1Maypole::Model::Base(3)User Contributed Perl DocumentatioMnaypole::Model::Base(3)
2
3
4
6 Maypole::Model::Base - Base class for model classes
7
9 This is the base class for Maypole data models. This is an abstract
10 class that defines the interface, and can't be used directly.
11
12 process
13
14 This is the engine of this module. Given the request object, it popu‐
15 lates all the relevant variables and calls the requested action.
16
17 Anyone subclassing this for a different database abstraction mechanism
18 needs to provide the following methods:
19
20 setup_database
21
22 $model->setup_database($config, $namespace, @data)
23
24 Uses the user-defined data in @data to specify a database- for example,
25 by passing in a DSN. The model class should open the database, and cre‐
26 ate a class for each table in the database. These classes will then be
27 "adopt"ed. It should also populate "$config->tables" and "$con‐
28 fig->classes" with the names of the classes and tables respectively.
29 The classes should be placed under the specified namespace. For
30 instance, "beer" should be mapped to the class "BeerDB::Beer".
31
32 class_of
33
34 $model->class_of($r, $table)
35
36 This maps between a table name and its associated class.
37
38 fetch_objects
39
40 This class method is passed a request object and is expected to return
41 an object of the appropriate table class from information stored in the
42 request object.
43
44 adopt
45
46 This class method is passed the name of a model class that represensts
47 a table and allows the master model class to do any set-up required.
48
49 columns
50
51 This is a list of all the columns in a table. You may also override see
52 also "display_columns"
53
54 table
55
56 This is the name of the table.
57
58 Actions
59
60 do_edit
61 If there is an object in "$r->objects", then it should be edited
62 with the parameters in "$r->params"; otherwise, a new object should
63 be created with those parameters, and put back into "$r->objects".
64 The template should be changed to "view", or "edit" if there were
65 any errors. A hash of errors will be passed to the template.
66
67 list
68 The "list" method should fill "$r->objects" with all of the objects
69 in the class. You may want to page this using "Data::Page" or simi‐
70 lar.
71
72 edit
73 Empty Action.
74
75 view
76 Empty Action.
77
78 index
79 Empty Action, calls list if provided with a table.
80
81 Also, see the exported commands in "Maypole::Model::CDBI".
82
84 Additionally, individual derived model classes may want to override the
85 following methods:
86
87 display_columns
88
89 Returns a list of columns to display in the model. By default returns
90 all columns in alphabetical order. Override this in base classes to
91 change ordering, or elect not to show columns.
92
93 list_columns
94
95 Same as display_columns, only for listings. Defaults to display_columns
96
97 column_names
98
99 Return a hash mapping column names with human-readable equivalents.
100
101 is_public
102
103 should return true if a certain action is supported, or false other‐
104 wise. Defaults to checking if the sub has the ":Exported" attribute.
105
106 method_attrs
107
108 Returns the list of attributes defined for a method. Maypole itself
109 only defines the "Exported" attribute.
110
111 related
112
113 This can go either in the master model class or in the individual
114 classes, and returns a list of has-many accessors. A brewery has many
115 beers, so "BeerDB::Brewery" needs to return "beers".
116
117
118
119perl v5.8.8 2005-11-23 Maypole::Model::Base(3)