1 package Apache::MVC::Model::Base;
3 sub MODIFY_CODE_ATTRIBUTES { $remember{$_[1]} = $_[2]; () }
5 sub FETCH_CODE_ATTRIBUTES { $remember{$_[1]} }
11 $r->template( my $method = $r->action );
12 $r->objects([ $class->retrieve(shift @{$r->{args}}) ]);
18 Apache::MVC::Model::Base - Base class for model classes
22 Anyone subclassing this for a different database abstraction mechanism
23 needs to provide the following methods:
27 If there is an object in C<$r-E<gt>objects>, then it should be edited
28 with the parameters in C<$r-E<gt>params>; otherwise, a new object should
29 be created with those parameters, and put back into C<$r-E<gt>objects>.
30 The template should be changed to C<view>, or C<edit> if there were any
31 errors. A hash of errors will be passed to the template.
35 sub do_edit { die "This is an abstract method" }
39 This turns an ID into an object of the appropriate class.
43 This is called on an model class representing a table and allows the
44 master model class to do any set-up required.
48 This can go either in the master model class or in the individual
49 classes, and returns a list of has-many accessors. A brewery has many
50 beers, so C<BeerDB::Brewery> needs to return C<beers>.
54 This is a list of the columns in a table.
58 This is the name of the table.
66 The C<list> method should fill C<< $r-> objects >> with all of the
67 objects in the class. You may want to page this using C<Data::Page> or
74 sub list :Exported { die "This is an abstract method" };
78 Also, see the exported commands in C<Apache::MVC::Model::CDBI>.
80 =head1 Other overrides
82 Additionally, individual derived model classes may want to override the
87 Return a hash mapping column names with human-readable equivalents.
91 sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
95 A description of the class to be passed to the template.
99 sub description { "A poorly defined class" }