$self->__load_model;
- my $applicable = __to_boolean( $self->is_applicable );
+ my $applicable = $self->is_model_applicable;
$self->__setup_plain_template unless $applicable;
# 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()
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
#!/usr/bin/perl
use strict;
use warnings;
-use Test::More tests => 73;
+use Test::More tests => 74;
use Test::MockModule;
# module compilation
my @API = qw/ config init_done view_object params query objects model_class
template_args output path args action template error document_encoding
content_type table headers_in headers_out
- is_applicable setup init handler handler_guts
+ is_model_applicable setup init handler handler_guts
call_authenticate call_exception additional_data
authenticate exception parse_path get_template_root get_request
parse_location send_output
can_ok(Maypole => @API);
+ok( ! UNIVERSAL::can(Maypole => 'is_applicable'), 'no is_applicable() method' );
+
ok(Maypole->config->isa('Maypole::Config'), 'config is a Maypole::Config object');
ok(! Maypole->init_done, '... which is false by default');
is(Maypole->view_object, undef, '... which is undefined');
my $mock_table = new Test::MockModule($table_class, no_auto => 1);
$mock_driver->mock(
- is_applicable => sub {push @{$called{applicable}},\@_; $applicable},
+ #is_applicable => sub {push @{$called{applicable}},\@_; $applicable},
+ is_model_applicable =>
+ sub {push @{$called{applicable}},\@_; $applicable},
get_request => sub {($r, $req) = @_},
additional_data => sub {$called{additional_data}++},
);
);
# allow request
- $applicable = $OK;
+ $applicable = 1;
$r->{path} = '/table/action';
$r->parse_path;
# decline request
%called = ();
- $applicable = $DECLINED;
+ $applicable = 0;
$r->{path} = '/table/action';
$r->parse_path;
# ... TODO view processing error handling
}
-# is_applicable()
+# is_model_applicable()
{
$r->config->display_tables([qw(one two)]);
$r->config->ok_tables(undef);
$r->action('unittest');
my $is_public;
$mock_model->mock('is_public', sub {0});
- my $status = $r->is_applicable;
- is($status, $DECLINED,
- '... return DECLINED unless model_class->is_public(action)');
+ my $true_false = $r->is_model_applicable;
+ is($true_false, 0,
+ '... returns 0 unless model_class->is_public(action)');
$mock_model->mock('is_public', sub {$is_public = \@_; 1});
- $status = $r->is_applicable;
- is($status, $OK, '... returns OK if table is in ok_tables');
+ $true_false = $r->is_model_applicable;
+ is($true_false, 1, '... returns 1 if table is in ok_tables');
is_deeply($is_public, [$r->model_class, 'unittest'],
'... calls model_class->is_public with request action');
is_deeply($r->config->ok_tables, {one => 1, two => 1},
'... config->ok_tables defaults to config->display_tables');
delete $r->config->ok_tables->{one};
- $status = $r->is_applicable;
- is($status, $DECLINED, '... return DECLINED unless $r->table is in ok_tables');
+ $true_false = $r->is_model_applicable;
+ is($true_false, 0, '... returns 0 unless $r->table is in ok_tables');
}
my $mock_driver = new Test::MockModule($driver_class, no_auto => 1);