A likely target for over-riding, if you need to build a customised model.
+This method also ensures any code in custom model classes is loaded, so you
+don't need to load them in the driver.
+
=cut
sub setup_model
{
- my $calling_class = shift;
+ my $class = shift;
- $calling_class = ref $calling_class if ref $calling_class;
+ $class = ref $class if ref $class;
- my $config = $calling_class->config;
+ my $config = $class->config;
$config->model || $config->model('Maypole::Model::CDBI');
$config->model->require or die sprintf
"Couldn't load the model class %s: %s", $config->model, $@;
- $config->model->setup_database($config, $calling_class, @_);
+ # among other things, this populates $config->classes
+ $config->model->setup_database($config, $class, @_);
foreach my $subclass ( @{ $config->classes } )
{
unshift @{ $subclass . "::ISA" }, $config->model;
$config->model->adopt($subclass)
if $config->model->can("adopt");
-
- # TODO: I think we should also load these classes, in case there is any
- # custom code. It would save the developer from needing to put
- # lots of use MyApp::SomeTable statements in the driver, and should
- # help eliminate some of those annoying silent errors if there's a
- # syntax error.
+
+ # Load custom model code, if it exists - nb this must happen after the
+ # unshift, to allow code attributes to work
+ eval "use $subclass";
+ die "Error loading $subclass: $@"
+ if $@ and $@ !~ /Can\'t locate \S+ in \@INC/;
}
}
-=item redirect_request
-
-Sets output headers to redirect based on the arguments provided
-
-Accepts either a single argument of the full url to redirect to, or a hash of
-named parameters :
-
-$r->redirect_request('http://www.example.com/path');
-
-or
-
-$r->redirect_request(protocol=>'https', domain=>'www.example.com', path=>'/path/file?arguments', status=>'302', url=>'..');
-
-The named parameters are protocol, domain, path, status and url
-
-Only 1 named parameter is required but other than url, they can be combined as
-required and current values (from the request) will be used in place of any
-missing arguments. The url argument must be a full url including protocol and
-can only be combined with status.
-
-=cut
-
-sub redirect_request {
- die "redirect_request is a virtual method. Do not use Maypole directly; use Apache::MVC or similar";
-}
-
-=item redirect_internal_request
-
-=cut
-
-sub redirect_internal_request {
-
-}
=back
Alias for C<params>.
+=back
+
+=head3 Utility methods
+
+=over 4
+
+=item redirect_request
+
+Sets output headers to redirect based on the arguments provided
+
+Accepts either a single argument of the full url to redirect to, or a hash of
+named parameters :
+
+$r->redirect_request('http://www.example.com/path');
+
+or
+
+$r->redirect_request(protocol=>'https', domain=>'www.example.com', path=>'/path/file?arguments', status=>'302', url=>'..');
+
+The named parameters are protocol, domain, path, status and url
+
+Only 1 named parameter is required but other than url, they can be combined as
+required and current values (from the request) will be used in place of any
+missing arguments. The url argument must be a full url including protocol and
+can only be combined with status.
+
+=cut
+
+sub redirect_request {
+ die "redirect_request is a virtual method. Do not use Maypole directly; use Apache::MVC or similar";
+}
+
+=item redirect_internal_request
+
+=cut
+
+sub redirect_internal_request {
+
+}
+
+
=item make_random_id
returns a unique id for this request can be used to prevent or detect repeat