X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI%2FPlain.pm;h=3c3296a2fbe3a46c59b4d961d3d00b6a6d02ab1a;hb=8d3f7b6c5612270c10042d8e0a9e52ad4ad54a46;hp=9cce6886c03f50678d7701da074edab646a2aaa0;hpb=8b68aa68ac5e83bc439d16c1fda0fb3870ee246c;p=maypole.git diff --git a/lib/Maypole/Model/CDBI/Plain.pm b/lib/Maypole/Model/CDBI/Plain.pm index 9cce688..3c3296a 100644 --- a/lib/Maypole/Model/CDBI/Plain.pm +++ b/lib/Maypole/Model/CDBI/Plain.pm @@ -5,20 +5,6 @@ use strict; Maypole::Config->mk_accessors(qw(table_to_class)); -sub setup_database { - my ( $self, $config, $namespace, $classes ) = @_; - $config->{classes} = $classes; - $config->{table_to_class} = { map { $_->table => $_ } @$classes }; - $config->{tables} = [ keys %{ $config->{table_to_class} } ]; -} - -sub class_of { - my ( $self, $r, $table ) = @_; - return $r->config->{table_to_class}->{$table}; -} - -1; - =head1 NAME Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader @@ -26,13 +12,23 @@ Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader =head1 SYNOPSIS package Foo; - use base 'Maypole::Application'; - use Foo::SomeTable; - use Foo::Other::Table; + use 'Maypole::Application'; Foo->config->model("Maypole::Model::CDBI::Plain"); Foo->setup([qw/ Foo::SomeTable Foo::Other::Table /]); + # untaint columns and provide custom actions for each class + + Foo::SomeTable->untaint_columns(email => ['email'], printable => [qw/name description/]); + + Foo::Other::Table->untaint_columns ( ... ); + + sub Foo::SomeTable::SomeAction : Exported { + + . . . + + } + =head1 DESCRIPTION This module allows you to use Maypole with previously set-up @@ -42,15 +38,63 @@ tables and set up the inheritance relationships as normal. =head1 METHODS -=over 4 +=head2 setup + + This method is inherited from Maypole::Model::Base and calls setup_database, + which uses Class::DBI::Loader to create and load Class::DBI classes from + the given database schema. + +=head2 setup_database + + This method loads the model classes for the application + +=cut + -=item setup_database -=item class_of +sub setup_database { + my ( $self, $config, $namespace, $classes ) = @_; + $config->{classes} = $classes; + foreach my $class (@$classes) { $namespace->load_model_subclass($class); } + $namespace->model_classes_loaded(1); + $config->{table_to_class} = { map { $_->table => $_ } @$classes }; + $config->{tables} = [ keys %{ $config->{table_to_class} } ]; +} + +=head2 class_of + + returns class for given table + +=cut + +sub class_of { + my ( $self, $r, $table ) = @_; + return $r->config->{table_to_class}->{$table}; +} -=back +=head2 adopt -See L +This class method is passed the name of a model class that represensts a table +and allows the master model class to do any set-up required. =cut +sub adopt { + my ( $self, $child ) = @_; + if ( my $col = $child->stringify_column ) { + $child->columns( Stringify => $col ); + } +} + +=head1 SEE ALSO + +L + +L + +=cut + + +1; + +