]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/Base.pm
Documentation updates
[maypole.git] / lib / Maypole / Model / Base.pm
index c4c959f7c7c42a4c2b0b0ec933bc56242120b83b..804f23519d0a808b1000d621660fe2b010d4f0fc 100644 (file)
@@ -1,16 +1,32 @@
 package Maypole::Model::Base;
 our %remember;
-sub MODIFY_CODE_ATTRIBUTES { $remember{$_[1]} = $_[2]; () }
+sub MODIFY_CODE_ATTRIBUTES { $remember{ $_[1] } = $_[2]; () }
 
-sub FETCH_CODE_ATTRIBUTES { $remember{$_[1]} } 
-sub view :Exported { }
-sub edit :Exported { }
+sub FETCH_CODE_ATTRIBUTES { $remember{ $_[1] } }
+
+sub view : Exported {
+}
+
+sub edit : Exported {
+}
 
 sub process {
-    my ($class, $r) = @_;
-    $r->template( my $method = $r->action );
-    $r->objects([ $class->retrieve(shift @{$r->{args}}) ]);
-    $class->$method($r);
+    my ( $class, $r ) = @_;
+    my $method = $r->action;
+    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} };
+    }
+    $class->$method( $r, $obj, @{ $r->{args} } );
+}
+
+sub display_columns {
+    sort shift->columns;
 }
 
 =head1 NAME
@@ -70,7 +86,9 @@ beers, so C<BeerDB::Brewery> needs to return C<beers>.
 
 =head2 columns
 
-This is a list of the columns in a table.
+This is a list of all the columns in a table. You may also override
+C<display_columns>, which is the list of columns you want to view, in
+the right order.
 
 =head2 table
 
@@ -92,7 +110,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
 
@@ -109,7 +130,14 @@ Return a hash mapping column names with human-readable equivalents.
 
 =cut
 
-sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
+sub column_names {
+    my $class = shift;
+    map {
+        my $col = $_;
+        $col =~ s/_+(\w)?/ \U$1/g;
+        $_ => ucfirst $col
+    } $class->columns;
+}
 
 =head2 description