1 package Apache::MVC::Model::Base;
3 sub MODIFY_CODE_ATTRIBUTES { $remember{$_[1]} = $_[2]; () }
5 sub FETCH_CODE_ATTRIBUTES { $remember{$_[1]} }
11 $r->objects([ $self->retrieve_all ]);
16 $r->template( my $method = $r->action );
17 $r->objects([ $class->retrieve(shift @{$r->{args}}) ]);
23 Apache::MVC::Model::Base - Base class for model classes
27 Anyone subclassing this for a different database abstraction mechanism
28 needs to provide the following methods:
32 If there is an object in C<$r-E<gt>objects>, then it should be edited
33 with the parameters in C<$r-E<gt>params>; otherwise, a new object should
34 be created with those parameters, and put back into C<$r-E<gt>objects>.
35 The template should be changed to C<view>, or C<edit> if there were any
36 errors. A hash of errors will be passed to the template.
40 sub do_edit { die "This is an abstract method" }
44 This turns an ID into an object of the appropriate class.
48 This is called on an model class representing a table and allows the
49 master model class to do any set-up required.
53 This can go either in the master model class or in the individual
54 classes, and returns a list of has-many accessors. A brewery has many
55 beers, so C<BeerDB::Brewery> needs to return C<beers>.
59 This is a list of the columns in a table.
63 This is the name of the table.
67 See the exported commands in C<Apache::MVC::Model::CDBI>.
69 =head1 Other overrides
71 Additionally, individual derived model classes may want to override the
76 Return a hash mapping column names with human-readable equivalents.
80 sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
84 A description of the class to be passed to the template.
88 sub description { "A poorly defined class" }