X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole.pm;h=36f085880f02f11b1f523ebdf577510eb2d8870e;hb=699c932710930328fa6942c375e097fbced03e5a;hp=e8de04e077942839f500fb391fb5eb30a1476107;hpb=349ed61cc56d78c7ce47eb08984c65d694d3aee0;p=maypole.git diff --git a/lib/Maypole.pm b/lib/Maypole.pm index e8de04e..36f0858 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -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-Etable> is publicly -accessible -and that the model class is configured to handle the C<$self-Eaction> +B as of version 2.11. If you have overridden it, +please override C 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