X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole.pm;h=cae420fea4bcf68d88ce41abdeafbfb15b167dbb;hb=8b45000d65db9833d72ce55c559d509019cc367f;hp=14260bd4320eb2ecfbf57591cbc5493b0fd5c50a;hpb=55f97a4ef2080f9fa90d5a85b703f23df76aa815;p=maypole.git diff --git a/lib/Maypole.pm b/lib/Maypole.pm index 14260bd..cae420f 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -20,7 +20,7 @@ __PACKAGE__->mk_classdata($_) for qw( config init_done view_object ); __PACKAGE__->mk_accessors( qw( params query objects model_class template_args output path args action template error document_encoding content_type table - headers_in headers_out stash) + headers_in headers_out stash session) ); __PACKAGE__->config( Maypole::Config->new() ); __PACKAGE__->init_done(0); @@ -119,10 +119,11 @@ sub handler_guts my $applicable = $self->is_model_applicable; $self->__setup_plain_template unless $applicable; + + $self->session($self->call_get_session); - # We authenticate every request, needed for proper session management my $status; - + eval { $status = $self->call_authenticate }; if ( my $error = $@ ) @@ -300,6 +301,11 @@ sub call_authenticate return $self->authenticate($self); } +sub call_get_session { + my ($self) = @_; + return $self->get_session($self); +} + sub call_exception { my ($self, $error) = @_; @@ -339,45 +345,29 @@ sub additional_data { } sub authenticate { return OK } +sub get_session { } + sub exception { return ERROR } +sub preprocess_path { }; + sub parse_path { my ($self) = @_; + $self->preprocess_path; + $self->path || $self->path('frontpage'); my @pi = grep {length} split '/', $self->path; - $self->table(shift @pi); + $self->table || $self->table(shift @pi); - $self->action( shift @pi or 'index' ); + $self->action || $self->action( shift @pi or 'index' ); - $self->args(\@pi); + $self->args || $self->args(\@pi); } -=head3 make_path( %args or \%args or @args ) - -This is the counterpart to C. It generates a path to use -in links, form actions etc. To implement your own path scheme, just override -this method and C. - - %args = ( table => $table, - action => $action, - additional => $additional, # optional - generally an object ID - ); - - \%args = as above, but a ref - - @args = ( $table, $action, $additional ); # $additional is optional - -C can be used as an alternative key to C. - -C<$additional> can be a string, an arrayref, or a hashref. An arrayref is -expanded into extra path elements, whereas a hashref is translated into a query -string. - -=cut sub make_path { @@ -417,16 +407,6 @@ sub make_path return $uri->as_string; } -=head3 make_uri( @segments ) - -Make a L object given table, action etc. Automatically adds -the C. - -If the final element in C<@segments> is a hash ref, C will render it -as a query string. - -=cut - sub make_uri { my ($r, @segments) = @_; @@ -572,8 +552,49 @@ Returns the request path =head3 parse_path -Parses the request path and sets the C, C and C -properties +Parses the request path and sets the C, C and C
+properties. Calls preprocess_path before parsing path and setting properties. + +=head3 make_path( %args or \%args or @args ) + +This is the counterpart to C. It generates a path to use +in links, form actions etc. To implement your own path scheme, just override +this method and C. + + %args = ( table => $table, + action => $action, + additional => $additional, # optional - generally an object ID + ); + + \%args = as above, but a ref + + @args = ( $table, $action, $additional ); # $additional is optional + +C can be used as an alternative key to C. + +C<$additional> can be a string, an arrayref, or a hashref. An arrayref is +expanded into extra path elements, whereas a hashref is translated into a query +string. + +=head3 preprocess_path + +Sometimes when you don't want to rewrite or over-ride parse_path but +want to rewrite urls or extract data from them before it is parsed. + +This method is called after parse_location has populated the request +information and before parse_path has populated the model and action +information, and is passed the request object. + +You can set action, args or table in this method and parse_path will +then leave those values in place or populate them if not present + +=head3 make_uri( @segments ) + +Make a L object given table, action etc. Automatically adds +the C. + +If the final element in C<@segments> is a hash ref, C will render it +as a query string. =head3 table @@ -800,7 +821,7 @@ L, L, L. =head1 AUTHOR -Maypole is currently maintained by Simon Flack C +Maypole is currently maintained by Aaron Trevena =head1 AUTHOR EMERITUS