]> git.decadent.org.uk Git - maypole.git/blob - lib/Maypole/Model/CDBI/Plain.pm
upped Class::DBI::SQLite requirement, quiettened tests and build, cleaned up document...
[maypole.git] / lib / Maypole / Model / CDBI / Plain.pm
1 package Maypole::Model::CDBI::Plain;
2 use Maypole::Config;
3 use base 'Maypole::Model::CDBI';
4 use strict;
5
6 Maypole::Config->mk_accessors(qw(table_to_class));
7
8 =head1 NAME
9
10 Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader
11
12 =head1 SYNOPSIS
13
14     package Foo;
15     use 'Maypole::Application';
16
17     Foo->config->model("Maypole::Model::CDBI::Plain");
18     Foo->setup([qw/ Foo::SomeTable Foo::Other::Table /]);
19
20     # untaint columns and provide custom actions for each class
21
22     Foo::SomeTable->untaint_columns(email => ['email'], printable => [qw/name description/]);
23
24     Foo::Other::Table->untaint_columns ( ... );
25
26     sub Foo::SomeTable::SomeAction : Exported {
27
28         . . .
29
30     }
31
32 =head1 DESCRIPTION
33
34 This module allows you to use Maypole with previously set-up
35 L<Class::DBI> classes; simply call C<setup> with a list reference
36 of the classes you're going to use, and Maypole will work out the
37 tables and set up the inheritance relationships as normal.
38
39 =head1 METHODS
40
41 =head2 setup
42
43   This method is inherited from Maypole::Model::Base and calls setup_database,
44   which uses Class::DBI::Loader to create and load Class::DBI classes from
45   the given database schema.
46
47 =head2 setup_database
48
49   This method loads the model classes for the application
50
51 =cut
52
53
54
55 sub setup_database {
56     my ( $self, $config, $namespace, $classes ) = @_;
57     $config->{classes}        = $classes;
58     foreach my $class (@$classes) { $namespace->load_model_subclass($class); }
59     $namespace->model_classes_loaded(1);
60     $config->{table_to_class} = { map { $_->table => $_ } @$classes };
61     $config->{tables}         = [ keys %{ $config->{table_to_class} } ];
62 }
63
64 =head2 class_of
65
66   returns class for given table
67
68 =cut
69
70 sub class_of {
71     my ( $self, $r, $table ) = @_;
72     return $r->config->{table_to_class}->{$table};
73 }
74
75 =head2 adopt
76
77 This class method is passed the name of a model class that represensts a table
78 and allows the master model class to do any set-up required.
79
80 =cut
81
82 sub adopt {
83     my ( $self, $child ) = @_;
84     if ( my $col = $child->stringify_column ) {
85         $child->columns( Stringify => $col );
86     }
87 }
88
89 =head1 SEE ALSO
90
91 L<Maypole::Model::Base>
92
93 L<Maypole::Model::CDBI>
94
95 =cut
96
97
98 1;
99
100