File Coverage

blib/lib/Maypole/Model/CDBI/Plain.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Maypole::Model::CDBI::Plain;
2 1     1   1284 use strict;
  1         2  
  1         37  
3              
4             =head1 NAME
5              
6             Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader
7              
8             =head1 SYNOPSIS
9              
10             package Foo;
11             use 'Maypole::Application';
12              
13             Foo->config->model("Maypole::Model::CDBI::Plain");
14             Foo->setup([qw/ Foo::SomeTable Foo::Other::Table /]);
15              
16             # untaint columns and provide custom actions for each class
17              
18             Foo::SomeTable->untaint_columns(email => ['email'], printable => [qw/name description/]);
19              
20             Foo::Other::Table->untaint_columns ( ... );
21              
22             sub Foo::SomeTable::SomeAction : Exported {
23              
24             . . .
25              
26             }
27              
28             =head1 DESCRIPTION
29              
30             This module allows you to use Maypole with previously set-up
31             L classes; simply call C with a list reference
32             of the classes you're going to use, and Maypole will work out the
33             tables and set up the inheritance relationships as normal.
34              
35             =cut
36              
37 1     1   42 use Maypole::Config;
  0            
  0            
38             use base 'Maypole::Model::CDBI::Base';
39              
40             use Maypole::Model::CDBI::AsForm;
41             use Maypole::Model::CDBI::FromCGI;
42             use CGI::Untaint::Maypole;
43              
44             =head1 METHODS
45              
46             =head1 Action Methods
47              
48             Action methods are methods that are accessed through web (or other public) interface.
49              
50             Inherited from L
51              
52             =head2 do_edit
53              
54             If there is an object in C<$r-Eobjects>, then it should be edited
55             with the parameters in C<$r-Eparams>; otherwise, a new object should
56             be created with those parameters, and put back into C<$r-Eobjects>.
57             The template should be changed to C, or C if there were any
58             errors. A hash of errors will be passed to the template.
59              
60             =head2 do_delete
61              
62             Inherited from Maypole::Model::CDBI::Base.
63              
64             This action deletes records
65              
66             =head2 do_search
67              
68             Inherited from Maypole::Model::CDBI::Base.
69              
70             This action method searches for database records.
71              
72             =head2 list
73              
74             Inherited from Maypole::Model::CDBI::Base.
75              
76             The C method fills C<$r-Eobjects> with all of the
77             objects in the class. The results are paged using a pager.
78              
79             =head1 Helper Methods
80              
81             =head2 Untainter
82              
83             Set the class you use to untaint and validate form data
84             Note it must be of type CGI::Untaint::Maypole (takes $r arg) or CGI::Untaint
85              
86             =cut
87              
88             sub Untainter { 'CGI::Untaint::Maypole' };
89              
90             =head2 setup
91              
92             This method is inherited from Maypole::Model::Base and calls setup_database,
93             which uses Class::DBI::Loader to create and load Class::DBI classes from
94             the given database schema.
95              
96             =head2 setup_database
97              
98             This method loads the model classes for the application
99              
100             =cut
101              
102             sub setup_database {
103             my ( $self, $config, $namespace, $classes ) = @_;
104             $config->{classes} = $classes;
105             foreach my $class (@$classes) { $namespace->load_model_subclass($class); }
106             $namespace->model_classes_loaded(1);
107             $config->{table_to_class} = { map { $_->table => $_ } @$classes };
108             $config->{tables} = [ keys %{ $config->{table_to_class} } ];
109             }
110              
111             =head2 class_of
112              
113             returns class for given table
114              
115             =cut
116              
117             sub class_of {
118             my ( $self, $r, $table ) = @_;
119             return $r->config->{table_to_class}->{$table};
120             }
121              
122             =head2 adopt
123              
124             This class method is passed the name of a model class that represensts a table
125             and allows the master model class to do any set-up required.
126              
127             =cut
128              
129             sub adopt {
130             my ( $self, $child ) = @_;
131             if ( my $col = $child->stringify_column ) {
132             $child->columns( Stringify => $col );
133             }
134             }
135              
136             =head1 SEE ALSO
137              
138             L
139              
140             L
141              
142             =cut
143              
144              
145             1;
146              
147