Re: [Maypole] Maypole model inheritance

From: Dave Howorth (Dave.Howorth at acm.org)
Date: Sun Dec 12 2004 - 01:34:39 GMT


Simon Flack wrote:
> Dave Howorth wrote:
>> Now it's morning, I see an obvious evil patch that's a variation of
>> my experiment last night. Simply start with the original M-M-CDBI
>> that *does* inherit from C-DBI so that all the C-DBI-* modules can
>> be used. Then at the end of setup_database(), once the
>> loader-determined C-DBI subclass is known, _remove_ C-DBI from
>> M-M-CDBI's @ISA and substitute the C-DBI subclass.
>
> Unfortunately, that'll break under mod_perl if you have one app using
> a Mysql datasource and another using some other datasource such as Pg
> or SQLite.

A variant would be to leave C-DBI in place in M-M_CDBI's @ISA but push
it rather than unshift it onto the table subclasses' @ISA. I still
haven't looked into why an unshift was used ... (See below why you
might want to do this).

> One solution is to remove Class::DBI entirely from M::M::CDBI's @ISA
> and make your table classes inherit from a new base class. Consider
> the following inheritance model:
>
> @MyApp::Model::Table::ISA = (MyApp::Model::_CDBI)
> @MyApp::Model::_CDBI::ISA = (M::M::CDBI, Class::DBI::$driver)
> @Maypole::Model::CDBI::ISA = (M::M::Base)
>
> M::M::CDBI can defer loading of Class::DBI::RetrieveAll, etc until
> the new base class is created. And $r->config->model remains near the
> front of your table classes' @ISA, where it belongs.

The difficulty here is that it's C-DBI-Loader that makes
MyApp::Model::Table inherit directly from Class::DBI::$driver. So to
make this work, you have to rewrite C-DBI-Loader, I think? Which seems
odd, since the scenario (using C-DBI-Loader to set up the table classes
but also wanting to use other C-DBI-* modules) is pure C-DBI, no
Maypole, so there ought to be an existing solution out there somewhere.

OTOH, if you're willing to discard C-DBI-Loader, my auto-generated
application class doesn't suffer from this problem (It's MySQL only at
the moment, but it doesn't have the problem in principle :)

Also, mightn't there be another problem with your suggested solution if
any of the C-DBI-* modules initialize differently when connected to
different databases? The only safe place for them to be loaded would be
MyApp::Model::_CDBI (or the individual table classes).

Cheers, Dave

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT