use UNIVERSAL::require;
use strict;
use warnings;
+use Data::Dumper;
use Maypole::Config;
use Maypole::Constants;
use Maypole::Headers;
-use Maypole::Components;
use URI();
use URI::QueryParam;
use NEXT;
=cut
-sub debug { 0 }
+sub debug { 1 }
=item config
Maypole::Model::CDBI is the base class.
My::App->setup($data_source, $user, $password,
- { opitons => { # These are DB connection options
+ { options => { # These are DB connection options
AutoCommit => 0,
RaiseError => 1,
...
# initialise the request
$self->headers_out(Maypole::Headers->new);
$self->get_request($req);
+
$self->parse_location;
-
+
# hook useful for declining static requests e.g. images, or perhaps for
# sanitizing request parameters
$self->status(Maypole::Constants::OK()); # set the default
$self->get_user;
my $status = $self->handler_guts;
+
return $status unless $status == OK;
# TODO: require send_output to return a status code
return $status;
}
-=back
-
-=head2 component
+=item component
- Run Maypole sub-requests as components using L<Maypole::Components>
+ Run Maypole sub-requests as a component of the request
[% request.component("/beer/view_as_component/20") %]
$self->__load_request_model;
my $applicable = $self->is_model_applicable == OK;
-
- $self->__setup_plain_template unless $applicable;
my $status;
+ # handle authentication
eval { $status = $self->call_authenticate };
-
if ( my $error = $@ )
{
$status = $self->call_exception($error, "authentication");
-
if ( $status != OK )
{
warn "caught authenticate error: $error";
$self->view_object->error($self, $error) : ERROR;
}
}
-
if ( $self->debug and $status != OK and $status != DECLINED )
{
$self->view_object->error( $self,
"Got unexpected status $status from calling authentication" );
}
-
+
return $status unless $status == OK;
# We run additional_data for every request
$self->additional_data;
-
- if ($applicable)
- {
- eval { $self->model_class->process($self) };
-
- if ( my $error = $@ )
+
+ if ($applicable) {
+ eval { $self->model_class->process($self) };
+ if ( my $error = $@ )
{
- $status = $self->call_exception($error, "model");
-
- if ( $status != OK )
+ $status = $self->call_exception($error, "model");
+ if ( $status != OK )
{
- warn "caught model error: $error";
- return $self->debug ?
- $self->view_object->error($self, $error) : ERROR;
+ warn "caught model error: $error";
+ return $self->debug ?
+ $self->view_object->error($self, $error) : ERROR;
}
}
+ } else {
+ $self->__setup_plain_template;
}
-
+
# less frequent path - perhaps output has been set to an error message
return OK if $self->output;
$self->{content_type} ||= $self->__get_mime_type();
$self->{document_encoding} ||= "utf-8";
+
return $processed_view_ok;
}
sub __get_mime_type {
my $self = shift;
- my $type;
+ my $type = 'text/html';
if ($self->path =~ m/.*\.(\w{3,4})$/) {
$type = $filetypes{$1};
} else {
- $type = $mmagic->checktype_contents($self->output);
+ my $output = $self->output;
+ if (defined $output) {
+ $type = $mmagic->checktype_contents($output);
+ }
}
return $type;
}
sub __setup_plain_template
{
my ($self) = @_;
-
+
# It's just a plain template
$self->model_class(undef);
# The model has been processed or skipped (if is_applicable returned false),
# any exceptions have been handled, and there's no content in $self->output
-sub __call_process_view
-{
- my ($self) = @_;
-
- my $status;
-
- eval { $status = $self->view_object->process($self) };
-
- if ( my $error = $@ )
- {
- $status = $self->call_exception($error, "view");
-
- if ( $status != OK )
- {
- warn "caught view error: $error" if $self->debug;
- return $self->debug ?
- $self->view_object->error($self, $error) : ERROR;
- }
+sub __call_process_view {
+ my ($self) = @_;
+
+ my $status = eval { $self->view_object->process($self) };
+
+ my $error = $@ || $self->{error};
+
+ if ( $error ) {
+ $status = $self->call_exception($error, "view");
+
+ if ( $status != OK ) {
+ warn "caught view error: $error" if $self->debug;
+ return $self->debug ?
+ $self->view_object->error($self, $error) : ERROR;
}
-
- return $status;
+ }
+
+ return $status;
}
=item get_request
=head1 AUTHOR
-Maypole is currently maintained by Aaron Trevena, David Baird, Dave Howorth and
-Peter Speltz.
+Maypole is currently maintained by Aaron Trevena.
=head1 AUTHOR EMERITUS