sub new
{
my ($class) = @_;
-
my $self = bless {
- template_args => {},
config => $class->config,
}, $class;
+
+ $self->stash({});
+ $self->params({});
+ $self->query({});
+ $self->template_args({});
+ $self->args([]);
+ $self->objects([]);
return $self;
}
$self->status(Maypole::Constants::OK()); # set the default
$self->__call_hook('start_request_hook');
return $self->status unless $self->status == Maypole::Constants::OK();
-
die "status undefined after start_request_hook()" unless defined
$self->status;
-
$self->get_session;
$self->get_user;
-
my $status = $self->handler_guts;
-
return $status unless $status == OK;
-
# TODO: require send_output to return a status code
$self->send_output;
-
return $status;
}
which return fragments of HTML rather than entire pages, but once you've
done that, you can use the C<component> method of the Maypole request object
to call those actions. You may pass a query string in the usual URL style.
+
You should not fully qualify the Maypole URLs.
+Note: any HTTP POST or URL parameters passed to the parent are not passed to the
+component sub-request, only what is included in the url passed as an argyument
+to the method
+
=cut
sub component {
my ( $r, $path ) = @_;
- my $self = bless { parent => $r }, ref $r;
+ my $self = bless { parent => $r, config => $r->{config}, } , ref $r;
+ $self->stash({});
+ $self->params({});
+ $self->query({});
+ $self->template_args({});
+ $self->args([]);
+ $self->objects([]);
+
+ $self->get_user;
my $url = URI->new($path);
+ warn "path : $path\n";
$self->{path} = $url->path;
$self->parse_path;
$self->params( $url->query_form_hash );
- $self->query( $r->params );
$self->handler_guts;
return $self->output;
}
if ( my $error = $@ )
{
$status = $self->call_exception($error, "model");
- if ( $status != OK )
+ if ( $status != OK )
{
warn "caught model error: $error";
return $self->debug ?
sub exception {
my ($self, $error, $when) = @_;
- if ($self->view_object->can("report_error") and $self->debug) {
+ if (ref $self->view_object && $self->view_object->can("report_error") and $self->debug) {
$self->view_object->report_error($self, $error, $when);
return OK;
}
class, it will be removed from C<args> and the retrieved object will be added to
the C<objects> list. See L<Maypole::Model> for more information.
+
+=item object
+
+Alias to get/set the first/only model object. The object will be accessible
+in the view templates.
+
+When used to set the object, will overwrite the request objects
+with a single object.
+
+=cut
+
+sub object {
+ my ($r,$object) = @_;
+ $r->objects([$object]) if ($object);
+ return undef unless $r->objects();
+ return $r->objects->[0];
+}
+
=item template_args
$self->template_args->{foo} = 'bar';
=item stash
-A place to put custom application data. Not used by Maypole itself.
+A place to put custom application data. Not used by Maypole itself.
=item template