]> git.decadent.org.uk Git - maypole.git/blob - lib/Apache/MVC/Model/Base.pm
Swathes of documentation.
[maypole.git] / lib / Apache / MVC / Model / Base.pm
1 package Apache::MVC::Model::Base;
2 our %remember;
3 sub MODIFY_CODE_ATTRIBUTES { $remember{$_[1]} = $_[2]; () }
4
5 sub FETCH_CODE_ATTRIBUTES { $remember{$_[1]} } 
6 sub view :Exported { }
7 sub edit :Exported { }
8
9 sub list :Exported {
10     my ($self, $r) = @_;
11     $r->objects([ $self->retrieve_all ]);
12 }
13
14 sub process {
15     my ($class, $r) = @_;
16     $r->template( my $method = $r->action );
17     $r->objects([ $class->retrieve(shift @{$r->{args}}) ]);
18     $class->$method($r);
19 }
20
21 =head1 NAME
22
23 Apache::MVC::Model::Base - Base class for model classes
24
25 =head1 DESCRIPTION
26
27 Anyone subclassing this for a different database abstraction mechanism
28 needs to provide the following methods:
29
30 =head2 do_edit
31
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.
37
38 =cut
39
40 sub do_edit { die "This is an abstract method" }
41
42 =head2 retrieve
43
44 This turns an ID into an object of the appropriate class.
45
46 =head2 adopt
47
48 This is called on an model class representing a table and allows the
49 master model class to do any set-up required. 
50
51 =head2 related
52
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>.
56
57 =head2 columns
58
59 This is a list of the columns in a table.
60
61 =head2 table
62
63 This is the name of the table.
64
65 =head2 Commands
66
67 See the exported commands in C<Apache::MVC::Model::CDBI>.
68
69 =head1 Other overrides
70
71 Additionally, individual derived model classes may want to override the
72 following methods:
73
74 =head2 column_names
75
76 Return a hash mapping column names with human-readable equivalents.
77
78 =cut
79
80 sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
81
82 =head2 description
83
84 A description of the class to be passed to the template.
85
86 =cut
87
88 sub description { "A poorly defined class" }
89
90 1;
91