]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
merged in TEEJAY Changes with current head
[maypole.git] / lib / Maypole.pm
index 908662f844431fdfa6ca4dc2664abb672f9a8b86..664df4b22ee8eb89732af415f9ed19015f6642bb 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
@@ -247,6 +247,25 @@ sub is_applicable
                         
     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
@@ -591,6 +639,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 +666,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