From: Simon Cozens Date: Wed, 11 Feb 2004 15:09:51 +0000 (+0000) Subject: This makes it all work as Maypole. X-Git-Tag: 2.10~303 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=48b7f94a68422ee2d1ee9ca6bf9cd5c2ee34e189;p=maypole.git This makes it all work as Maypole. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@59 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/MANIFEST b/MANIFEST index 6f98971..c087fd1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,9 +1,10 @@ MANIFEST Changes -lib/Apache/MVC/Model/Base.pm -lib/Apache/MVC/Model/CDBI.pm -lib/Apache/MVC/Workflow.pod -lib/Apache/MVC/View/TT.pm +lib/Maypole/Model/Base.pm +lib/Maypole/Model/CDBI.pm +lib/Maypole/View/TT.pm +lib/Maypole/Workflow.pod +lib/Maypole.pm lib/Apache/MVC.pm lib/BeerDB.pm t/1.t diff --git a/lib/BeerDB.pm b/lib/BeerDB.pm index d77d83d..fd2c704 100644 --- a/lib/BeerDB.pm +++ b/lib/BeerDB.pm @@ -3,7 +3,7 @@ use base 'Apache::MVC'; use Class::DBI::Loader::Relationship; # This line is required if you don't have Apache calling Perl handlers # as methods. -sub handler { Apache::MVC::handler(__PACKAGE__, @_) } +sub handler { Maypole::handler(__PACKAGE__, @_) } # This is the sample application. Change this to the path to your # database. (or use mysql or something) diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index 83c118a..43b8c7b 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -3,6 +3,7 @@ use base qw(Maypole::Model::Base Class::DBI); use Lingua::EN::Inflect::Number qw(to_PL); use Class::DBI::AsForm; use Class::DBI::FromCGI; +use Class::DBI::Loader; use Class::DBI::AbstractSearch; use Class::DBI::Plugin::RetrieveAll; use Class::DBI::Pager; @@ -98,5 +99,22 @@ sub list :Exported { $r->objects([ $self->retrieve_all ]); } } + +sub setup_database { + my ($self, $config, $namespace, $dsn) = @_; + $config->{dsn} = $dsn; + $config->{loader} = Class::DBI::Loader->new( + namespace => $namespace, + dsn => $dsn + ); + $config->{classes} = [ $config->{loader}->classes ]; + $config->{tables} = [ $config->{loader}->tables ]; +} + +sub class_of { + my ($self, $r, $table) = @_; + return $r->config->{loader}->_table2class($table); +} + 1;