X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI%2FPlain.pm;h=fd34a75c91d312bcb6437cca6c4dc6883d67e52d;hb=2c41363d0f5abf35c8d642db4b837f52f5954b2c;hp=2c2d869a51679f24188cdddfb2ecafd8e59ba8f3;hpb=1ac110f4ecb782e381db456a3326ff71cb96a73e;p=maypole.git diff --git a/lib/Maypole/Model/CDBI/Plain.pm b/lib/Maypole/Model/CDBI/Plain.pm index 2c2d869..fd34a75 100644 --- a/lib/Maypole/Model/CDBI/Plain.pm +++ b/lib/Maypole/Model/CDBI/Plain.pm @@ -1,40 +1,88 @@ package Maypole::Model::CDBI::Plain; +use Maypole::Config; use base 'Maypole::Model::CDBI'; +use strict; + +Maypole::Config->mk_accessors(qw(table_to_class)); + +=head1 NAME + +Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader + +=head1 SYNOPSIS + + package Foo; + use 'Maypole::Application'; + + Foo->config->model("Maypole::Model::CDBI::Plain"); + Foo->setup([qw/ Foo::SomeTable Foo::Other::Table /]); + +=head1 DESCRIPTION + +This module allows you to use Maypole with previously set-up +L classes; simply call C with a list reference +of the classes you're going to use, and Maypole will work out the +tables and set up the inheritance relationships as normal. + +=head1 METHODS + +=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 + + 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}; } -1; - -=head1 NAME +=head2 adopt -Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader +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. -=head1 SYNOPSIS +=cut - package Foo; - use base 'Maypole::Application'; - use Foo::SomeTable; - use Foo::Other::Table; +sub adopt { + my ( $self, $child ) = @_; + if ( my $col = $child->stringify_column ) { + $child->columns( Stringify => $col ); + } +} - Foo->config->{model_class} = "Maypole::Model::CDBI::Plain"; - Foo->setup([qw/ Foo::SomeTable Foo::Other::Table /]); +=head1 SEE ALSO -=head1 DESCRIPTION +L -This module allows you to use Maypole with previously set-up -C classes; simply call C with a list reference -of the classes you're going to use, and Maypole will work out the -tables and set up the inheritance relationships as normal. +L =cut + +1; + +