package Maypole::Model::Base;
+
+use Maypole::Constants;
+use attributes ();
+
our %remember;
-sub MODIFY_CODE_ATTRIBUTES { $remember{$_[1]} = $_[2]; () }
-sub FETCH_CODE_ATTRIBUTES { $remember{$_[1]} }
-sub view :Exported { }
-sub edit :Exported { }
+sub MODIFY_CODE_ATTRIBUTES { $remember{ $_[1] } = $_[2]; () }
+
+sub FETCH_CODE_ATTRIBUTES { $remember{ $_[1] } }
+
+sub view : Exported {
+}
+
+sub edit : Exported {
+}
sub process {
- my ($class, $r) = @_;
+ my ( $class, $r ) = @_;
my $method = $r->action;
- return if $r->{template}; # Authentication has set this, we're done.
+ return if $r->{template}; # Authentication has set this, we're done.
$r->{template} = $method;
+ $r->objects( [] );
my $obj = $class->retrieve( $r->{args}->[0] );
if ($obj) {
- $r->objects([ $obj ]);
- shift @{$r->{args}};
+ $r->objects( [$obj] );
+ shift @{ $r->{args} };
}
- $class->$method($r);
+ $class->$method( $r, $obj, @{ $r->{args} } );
}
-sub display_columns {
+sub display_columns {
sort shift->columns;
}
sub class_of { die "This is an abstract method" }
sub setup_database { die "This is an abstract method" }
-sub list :Exported { die "This is an abstract method" };
+
+sub list : Exported {
+ die "This is an abstract method";
+}
=pod
=cut
-sub column_names { my $class = shift; map {
+sub column_names {
+ my $class = shift;
+ map {
my $col = $_;
- $col =~ s/_+(\w)?/ \U\1/g;
- $_ => ucfirst $col } $class->columns }
+ $col =~ s/_+(\w)?/ \U$1/g;
+ $_ => ucfirst $col
+ } $class->columns;
+}
=head2 description
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;