]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/Base.pm
Added Maypole::Model::Base::is_public()
[maypole.git] / lib / Maypole / Model / Base.pm
index a9b3a32a7b9b57ccb6d13f652db6175a1b94fc48..b592eaab30f9439d257a2a04df8775c6a504d7e7 100644 (file)
@@ -1,27 +1,36 @@
 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([]);
+    $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;
 }
 
@@ -106,7 +115,10 @@ similar.
 
 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
 
@@ -123,10 +135,14 @@ Return a hash mapping column names with human-readable equivalents.
 
 =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
 
@@ -136,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;