1 package Maypole::Model::CDBI;
6 Maypole::Model::CDBI - Model class based on Class::DBI
10 This is a master model class which uses L<Class::DBI> to do all the hard
11 work of fetching rows and representing them as objects. It is a good
12 model to copy if you're replacing it with other database abstraction
15 It implements a base set of methods required for a Maypole Data Model.
17 It inherits accessor and helper methods from L<Maypole::Model::Base>.
19 When specified as the application model, it will use Class::DBI::Loader
20 to generate the model classes from the provided database. If you do not
21 wish to use this functionality, use L<Maypole::Model::CDBI::Plain> which
22 will instead use Class::DBI classes provided.
26 use base qw(Maypole::Model::CDBI::Base);
29 use Class::DBI::Loader;
32 use Maypole::Model::CDBI::AsForm;
33 use Maypole::Model::CDBI::FromCGI;
34 use CGI::Untaint::Maypole;
38 Set the class you use to untaint and validate form data
39 Note it must be of type CGI::Untaint::Maypole (takes $r arg) or CGI::Untaint
43 sub Untainter { 'CGI::Untaint::Maypole' };
45 =head2 add_model_superclass
47 Adds model as superclass to model classes (if necessary)
49 Inherited from Maypole::Model::CDBI::Base
53 Action methods are methods that are accessed through web (or other public) interface.
55 Inherited from L<Maypole::Model::CDBI::Base>
59 If there is an object in C<$r-E<gt>objects>, then it should be edited
60 with the parameters in C<$r-E<gt>params>; otherwise, a new object should
61 be created with those parameters, and put back into C<$r-E<gt>objects>.
62 The template should be changed to C<view>, or C<edit> if there were any
63 errors. A hash of errors will be passed to the template.
67 Inherited from Maypole::Model::CDBI::Base.
69 This action deletes records
73 Inherited from Maypole::Model::CDBI::Base.
75 This action method searches for database records.
79 Inherited from Maypole::Model::CDBI::Base.
81 The C<list> method fills C<$r-E<gt>objects> with all of the
82 objects in the class. The results are paged using a pager.
88 This method is inherited from Maypole::Model::Base and calls setup_database,
89 which uses Class::DBI::Loader to create and load Class::DBI classes from
90 the given database schema.
96 The $opts argument is a hashref of options. The "options" key is a hashref of
97 Database connection options . Other keys may be various Loader arguments or
98 flags. It has this form:
100 # DB connection options
101 options { AutoCommit => 1 , ... },
110 my ( $class, $config, $namespace, $dsn, $u, $p, $opts ) = @_;
111 $dsn ||= $config->dsn;
112 $u ||= $config->user;
113 $p ||= $config->pass;
114 $opts ||= $config->opts;
116 warn "No DSN set in config" unless $dsn;
117 $config->loader || $config->loader(
118 Class::DBI::Loader->new(
119 namespace => $namespace,
126 $config->{classes} = [ $config->{loader}->classes ];
127 $config->{tables} = [ $config->{loader}->tables ];
129 my @table_class = map { $_ . " => " . $config->{loader}->_table2class($_) } @{ $config->{tables} };
130 warn( 'Loaded tables to classes: ' . join ', ', @table_class )
131 if $namespace->debug;
136 returns class for given table
141 my ( $self, $r, $table ) = @_;
142 return $r->config->loader->_table2class($table); # why not find_class ?
148 L<Maypole>, L<Maypole::Model::CDBI::Base>.
152 Maypole is currently maintained by Aaron Trevena.
154 =head1 AUTHOR EMERITUS
156 Simon Cozens, C<simon#cpan.org>
158 Simon Flack maintained Maypole from 2.05 to 2.09
160 Sebastian Riedel, C<sri#oook.de> maintained Maypole from 1.99_01 to 2.04
164 You may distribute this code under the same terms as Perl itself.