Subject: | using plain CDBI classes in Maypole |
When you have a bunch of plain Class::DBI classes that you want to build your maypole application from, using Maypole::Model::CDBI::Plain won't work without inheriting it in your plain Class::DBI classes.
You can fix this by replaining Maypole/Model/CDBI/Plain.pm with the attached Plain.pm module attached, or upgrading to SVN, or upgrading to 2.11 when it is released.
package Maypole::Model::CDBI::Plain;
use Maypole::Config;
use base 'Maypole::Model::CDBI';
use strict;
Maypole::Config->mk_accessors(qw(table_to_class));
sub setup_database {
my ( $self, $config, $namespace, $classes ) = @_;
$config->{classes} = $classes;
foreach my $class (@$classes) {
if ( $class->require ) {
warn "Loaded external module for '$class'\n" if $namespace->debug > 1;
} else {
(my $filename = $class) =~ s!::!/!g;
die "Loading '$class' failed: $@\n"
unless $@ =~ /Can\'t locate \Q$filename\E\.pm/;
warn "No external module for '$class'"
if $namespace->debug > 1;
}
}
$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
=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<Class::DBI> classes; simply call C<setup> 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
=over 4
=item setup_database
=item class_of
=back
See L<Maypole::Model::Base>
=cut