]> git.decadent.org.uk Git - maypole.git/blob - lib/Apache/MVC/Model/Base.pm
And now we have paging support. (And some better docs)
[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 process {
10     my ($class, $r) = @_;
11     $r->template( my $method = $r->action );
12     $r->objects([ $class->retrieve(shift @{$r->{args}}) ]);
13     $class->$method($r);
14 }
15
16 =head1 NAME
17
18 Apache::MVC::Model::Base - Base class for model classes
19
20 =head1 DESCRIPTION
21
22 Anyone subclassing this for a different database abstraction mechanism
23 needs to provide the following methods:
24
25 =head2 do_edit
26
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.
32
33 =cut
34
35 sub do_edit { die "This is an abstract method" }
36
37 =head2 retrieve
38
39 This turns an ID into an object of the appropriate class.
40
41 =head2 adopt
42
43 This is called on an model class representing a table and allows the
44 master model class to do any set-up required. 
45
46 =head2 related
47
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>.
51
52 =head2 columns
53
54 This is a list of the columns in a table.
55
56 =head2 table
57
58 This is the name of the table.
59
60 =head2 Commands
61
62 =over
63
64 =item list
65
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
68 similar.
69
70 =back
71
72 =cut
73
74 sub list :Exported { die "This is an abstract method" };
75
76 =pod
77
78 Also, see the exported commands in C<Apache::MVC::Model::CDBI>.
79
80 =head1 Other overrides
81
82 Additionally, individual derived model classes may want to override the
83 following methods:
84
85 =head2 column_names
86
87 Return a hash mapping column names with human-readable equivalents.
88
89 =cut
90
91 sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
92
93 =head2 description
94
95 A description of the class to be passed to the template.
96
97 =cut
98
99 sub description { "A poorly defined class" }
100
101 1;
102