]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
fix applied for http://rt.cpan.org/Ticket/Display.html?id=14661
[maypole.git] / lib / Maypole.pm
index 908662f844431fdfa6ca4dc2664abb672f9a8b86..4f52493ef567b15b9226581160ce6658c4d7169a 100644 (file)
@@ -7,7 +7,7 @@ use Maypole::Config;
 use Maypole::Constants;
 use Maypole::Headers;
 
-our $VERSION = '2.10';
+our $VERSION = '2.11';
 
 # proposed privacy conventions:
 # - no leading underscore     - public to custom application code and plugins
@@ -19,7 +19,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 )
+        headers_in headers_out stash )
 );
 __PACKAGE__->config( Maypole::Config->new() );
 __PACKAGE__->init_done(0);
@@ -240,13 +240,32 @@ sub is_applicable
     
     warn "We don't have that table ($table).\n"
         . "Available tables are: "
-        . join( ",", @{ $config->display_tables } )
+        . join( ",", @{ $config->ok_tables } )
             if $self->debug
                 and not $config->ok_tables->{$table}
                         and $self->action; # this is probably always true
                         
     return DECLINED unless exists $config->ok_tables->{$table};
 
+    my $path_is_ok = 0;
+    if (exists $config->ok_tables->{ $self->{table} }) {
+      $path_is_ok = 1;
+    } else {
+      if ( $self->_have_default_table_view ) {
+       my $path_is_ok = $self->default_table_view($self->{path},$self->{args});
+      }
+      unless ($path_is_ok) {
+       warn "We don't have that table ($self->{table}).\n"
+         . "Available tables are: "
+           . join( ",", @{ $config->{display_tables} } )
+             if $self->debug
+               and not $config->ok_tables->{ $self->{table} }
+                 and $self->{action};
+      }
+    }
+
+    return DECLINED() unless $path_is_ok;
+
     # Is it public?
     return DECLINED unless $self->model_class->is_public($self->action);
     
@@ -285,6 +304,27 @@ sub call_exception
     return $self->exception($error);
 }
 
+sub default_table_view {
+  my ($self,$path,$args) = @_;
+  my $path_is_ok = 0;
+  my $default_table_view = __PACKAGE__->_default_table_view;
+  # (path class action field)
+  my @path = $self->{path} =~ m{([^/]+)/?}g;
+  my $search_value = shift(@path);
+  if ($default_table_view->{path}) {
+    if ($default_table_view->{path} eq $search_value) {
+      $search_value = shift(@path);
+    } else {
+      return 0;
+    }
+  }
+
+  $self->{table} = $default_table_view->{class};
+  $self->{action} = $default_table_view->{action};
+  $self->{args} = [ $search_value,@path ];
+  return $path_is_ok;
+}
+
 sub additional_data { }
 
 sub authenticate { return OK }
@@ -325,12 +365,20 @@ sub param
 sub get_template_root {'.'}
 sub get_request       { }
 
+sub get_protocol {
+  die "get_protocol is a virtual method. Do not use Maypole directly; use Apache::MVC or similar";
+}
+
 sub parse_location {
-    die "Do not use Maypole directly; use Apache::MVC or similar";
+    die "parse_location is a virtual method. Do not use Maypole directly; use Apache::MVC or similar";
+}
+
+sub redirect_request {
+  die "parse_location is a virtual method. Do not use Maypole directly; use Apache::MVC or similar";
 }
 
 sub send_output {
-    die "Do not use Maypole directly; use Apache::MVC or similar";
+    die "send_output is a virtual method. Do not use Maypole directly; use Apache::MVC or similar";
 }
 
 # Session and Repeat Submission Handling
@@ -484,6 +532,7 @@ You should only need to define this method if you are writing a new
 Maypole backend. It should return something that looks like an Apache
 or CGI request object, it defaults to blank.
 
+=head3 default_table_view
 
 =head3 is_applicable
 
@@ -531,6 +580,10 @@ C<objects> list. See L<Maypole::Model> for more information.
 
 Get/set a hash of template variables.
 
+=head3 stash
+
+A place to put custom application data. Not used by Maypole itself. 
+
 =head3 template
 
 Get/set the template to be used by the view. By default, it returns
@@ -591,6 +644,26 @@ exception method of your Maypole application.
 returns a unique id for this request can be used to prevent or detect repeat
 submissions.
 
+=head3 get_protocol
+
+Returns the protocol the request was made with, i.e. https
+
+=head3 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.
+
 =head3 handler
 
 This method sets up the class if it's not done yet, sets some
@@ -598,7 +671,10 @@ defaults and leaves the dirty work to handler_guts.
 
 =head3 handler_guts
 
-This is the core of maypole. You don't want to know.
+This is the main request handling method and calls various methods to handle the request/response
+and defines the workflow within Maypole.
+
+Currently undocumented and liable to be refactored without warning.
 
 =head1 SEE ALSO