[Dbix-class] Question about dynamic
class generation (DBIx::Class::Schema::Loader)
Matt S Trout
dbix-class at trout.me.uk
Wed Feb 15 16:07:48 CET 2006
On Wed, Feb 15, 2006 at 02:43:49PM +0000, Dave Howorth wrote:
> Matt S Trout wrote:
> >On Wed, Feb 15, 2006 at 11:02:55AM +0000, Dave Howorth wrote:
> >>castaway at desert-island.demon.co.uk wrote:
> >>>IMO (and I may be off base), it should be possible to use Loader, which
> >>>will have a standard set of predictable results (which should be
> >>>detailed in the docs), and then only write your own classes for the
> >>>parts you need to change / expand. Some flag should possibly set whether
> >>>the user-created classes replace or extend the Loader ones .. ?
> >>FWIW, that's what I do in my home-grown CDBI/Maypole loader. It works
> >>well for me. I haven't needed to replace any automatically-generated
> >>classes; I just override individual methods. For example, I define an
> >>alternate semantics for find_or_create in my base class and override the
> >>method in those classes where it's appropriate (some classes have
> >>special change-logging built in that alters how the find part of
> >>find_or_create needs to work).
> >>
> >>It would be nice when I get around to migrating to find that DBIC
> >>already has the mechanism :)
> >
> >left_base_classes and additional_base_classes should already do the trick
> >for this in all Loaders (including the CDBI one)
>
> I'm not sure I understand you. We're talking about a mechanism that
> dynamically generates appropriate packages for all tables and then goes
> and automatically loads any modules it finds for those packages too. At
> any rate that's what I'm talking about. I'm not sure how
> left_base_classes and additional_base_classes help?
Well the Loader handles the "dynamically generates" bits. As for the
automatically loads, just running
foreach my $moniker ($schema->sources) {
$schema->class($moniker)->require;
}
should do the trick (assuming UNIVERSAL::require is loaded)
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list