]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole.pm
Implemented daveh's fixes for is_applicable() -
[maypole.git] / lib / Maypole.pm
index e8de04e077942839f500fb391fb5eb30a1476107..36f085880f02f11b1f523ebdf577510eb2d8870e 100644 (file)
@@ -115,7 +115,7 @@ sub handler_guts
     
     $self->__load_model;
 
-    my $applicable = __to_boolean( $self->is_applicable );
+    my $applicable = $self->is_model_applicable;
     
     $self->__setup_plain_template unless $applicable;
     
@@ -225,51 +225,63 @@ sub __load_model
 # instead of changing is_applicable() to return 0 or 1, the return value is
 # passed through __to_boolean. I think it helps handler_guts() if we don't
 # have multiple sets of return codes being checked for different things -drb.
-sub is_applicable 
+sub is_model_applicable 
 {
     my ($self) = @_;
     
+    # cater for applications that are using obsolete version
+    if ($self->can('is_applicable')) 
+    {
+        warn "DEPRECATION WARNING: rewrite is_applicable to the interface ".
+                "of Maypole::is_model_applicable\n";
+        return $self->is_applicable == OK;
+    }
+
+    # Establish which tables should be processed by the model
     my $config = $self->config;
     
     $config->ok_tables || $config->ok_tables( $config->display_tables );
     
     $config->ok_tables( { map { $_ => 1 } @{ $config->ok_tables } } )
         if ref $config->ok_tables eq "ARRAY";
+        
+    my $ok_tables = $config->ok_tables;
       
+    # Does this request concern a table to be processed by the model?
     my $table = $self->table;
     
-    warn "We don't have that table ($table).\n"
-        . "Available tables are: "
-        . 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};
-      }
+    my $ok = 0;
+    
+    if (exists $ok_tables->{$table}) 
+    {
+        $ok = 1;
+    } 
+# implements tj's default_table_view(), but there's no _default_table_view()
+# or _have_default_table_view() yet
+#    else 
+#    {
+#        $ok = $self->default_table_view($self->path, $self->args)
+#            if $self->_have_default_table_view;
+#    }
+
+    if (not $ok) 
+    {
+        warn "We don't have that table ($table).\n"
+            . "Available tables are: "
+            . join( ",", keys %$ok_tables )
+                if $self->debug and not $ok_tables->{$table};
+                
+        return 0;
     }
-
-    return DECLINED() unless $path_is_ok;
-
-    # Is it public?
-    return DECLINED unless $self->model_class->is_public($self->action);
     
-    return OK;
+    # Is the action public?
+    my $action = $self->action;
+    return 1 if $self->model_class->is_public($action);
+    
+    warn "The action '$action' is not applicable to the table $table"
+        if $self->debug;
+    
+    return 0;
 }
 
 # *only* intended for translating the return code from is_applicable()
@@ -542,9 +554,17 @@ or CGI request object, it defaults to blank.
 
 Returns a Maypole::Constant to indicate whether the request is valid.
 
-The default implementation checks that C<$self-E<gt>table> is publicly
-accessible
-and that the model class is configured to handle the C<$self-E<gt>action>
+B<This method is deprecated> as of version 2.11. If you have overridden it,
+please override C<is_model_applicable> instead, and change the return type
+from Maypole:Constants to true/false.
+
+=head3 is_model_applicable
+
+Returns true or false to indicate whether the request is valid.
+
+The default implementation checks that C<< $r->table >> is publicly
+accessible and that the model class is configured to handle the
+C<< $r->action >>.
 
 =head3 authenticate