From 3447ae72797ea189b6613d2c4abf9be7afe5537a Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Sun, 26 Sep 2004 22:00:08 +0000 Subject: [PATCH] Added Maypole::Model::Base::is_public() git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@207 48953598-375a-da11-a14b-00016c27c3ee --- Changes | 2 ++ lib/Maypole.pm | 34 ++++++++++++---------------------- lib/Maypole/Model/Base.pm | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Changes b/Changes index f017a09..b108b73 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,8 @@ Revision history for Perl extension Maypole - win32 support - new documentation for Maypole.pm (Simon Flack) - moved doc/*.pod to lib/Maypole/Manual + - added Maypole::Model::Base::is_public() to make it simple to overload + :Exported behavior 1.7 Sat Jul 17 20:15:26 BST 2004 - Emergency release - we lost the "use Maypole::Constants" from diff --git a/lib/Maypole.pm b/lib/Maypole.pm index 6ab5bc0..b4e1d62 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -5,7 +5,10 @@ use UNIVERSAL::require; use strict; use warnings; use Maypole::Config; +use Maypole::Constants; + our $VERSION = '2.0'; + __PACKAGE__->mk_classdata($_) for qw( config init_done view_object ); __PACKAGE__->mk_accessors( qw( ar params query objects model_class template_args output path @@ -13,7 +16,6 @@ __PACKAGE__->mk_accessors( ); __PACKAGE__->config( Maypole::Config->new() ); __PACKAGE__->init_done(0); -use Maypole::Constants; sub debug { 0 } @@ -133,18 +135,8 @@ sub is_applicable { and not $config->ok_tables->{ $self->{table} }; return DECLINED() unless exists $config->ok_tables->{ $self->{table} }; - # Does the action method exist? - my $cv = $self->model_class->can( $self->{action} ); - warn "We don't have that action ($self->{action})" - if $self->debug and not $cv; - return DECLINED() unless $cv; - - # Is it exported? - $self->{method_attribs} = join " ", attributes::get($cv); - do { - warn "$self->{action} not exported" if $self->debug; - return DECLINED(); - } unless $self->{method_attribs} =~ /\bExported\b/i; + # Is it public? + return DECLINED unless $r->model_class->is_public( $r->{action} ); return OK(); } @@ -211,7 +203,7 @@ See L. =head1 DESCRIPTION This documents the Maypole request object. For user documentation, see -L. +L. =head2 CLASS METHODS @@ -221,11 +213,10 @@ Returns the L object =head3 setup - My::App->setup(); + My::App->setup($data_source, $user, $password, \%attr); - Initialise the maypole application and model classes. Your - application should - call this after setting configuration via L<"config"> +Initialise the maypole application and model classes. Your application should +call this after setting configuration via L<"config"> =head3 init @@ -241,9 +232,8 @@ Get/set the Maypole::View object sub My::App::debug {1} - Returns the debugging flag. Override this in your application class - to - enable/disable debugging. +Returns the debugging flag. Override this in your application class to +enable/disable debugging. =head2 INSTANCE METHODS @@ -355,7 +345,7 @@ C list. See L for more information. $r->template_args->{foo} = 'bar'; - Get/set a hash of template variables. +Get/set a hash of template variables. =head3 template diff --git a/lib/Maypole/Model/Base.pm b/lib/Maypole/Model/Base.pm index 804f235..b592eaa 100644 --- a/lib/Maypole/Model/Base.pm +++ b/lib/Maypole/Model/Base.pm @@ -1,5 +1,10 @@ package Maypole::Model::Base; + +use Maypole::Constants; +use attributes (); + our %remember; + sub MODIFY_CODE_ATTRIBUTES { $remember{ $_[1] } = $_[2]; () } sub FETCH_CODE_ATTRIBUTES { $remember{ $_[1] } } @@ -147,5 +152,16 @@ A description of the class to be passed to the template. sub description { "A poorly defined class" } -1; +sub is_public { + my ( $self, $action ) = @_; + my $cv = $self->can($action); + return DECLINED() unless $cv; + my $attrs = join " ", attributes::get($cv); + do { + warn "$action not exported" if Maypole->debug; + return DECLINED(); + } unless $attrs =~ /\bExported\b/i; + return OK; +} +1; -- 2.39.2