X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2FMaypole%2FModel%2FBase.pm;h=804f23519d0a808b1000d621660fe2b010d4f0fc;hb=5f530b5f17106319faa2f437a567332c86bf6a2c;hp=d092e502dd33ae61866d3d43c80d7d32528cdcb1;hpb=e82766d6aab88a10e75b4669f44d2dbe7ff9d766;p=maypole.git diff --git a/lib/Maypole/Model/Base.pm b/lib/Maypole/Model/Base.pm index d092e50..804f235 100644 --- a/lib/Maypole/Model/Base.pm +++ b/lib/Maypole/Model/Base.pm @@ -1,23 +1,31 @@ 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) = @_; + my ( $class, $r ) = @_; my $method = $r->action; - $r->{template} ||= $method; # Authentication may have done this for us - $r->objects([ $class->retrieve(shift @{$r->{args}}) ]); - - # This allows the authentication mechanism to set the template - # without needing to define an action. - $class->$method($r) if $class->can($method); + 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 { +sub display_columns { sort shift->columns; } @@ -102,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 @@ -119,10 +130,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