[Dbix-class] Schema and Loader

Matt S Trout dbix-class at trout.me.uk
Thu Jan 5 22:46:28 CET 2006


On Thu, Jan 05, 2006 at 03:05:52PM -0500, Jason Kohles wrote:
> On 1/5/06, Alan Humphrey <alan.humphrey at comcast.net> wrote:
> >
> > Background: I'm updating a Catalyst app that now uses Catalyst::Model::CDBI.
> >  My DB has approx 40 tables, but using the auto loading in Catalyst I can
> > get away with creating modules for only a handful of the tables.  I'd like
> > the same ease of use using DBIx.
> >
> 
> This is how I do it....
> 
> 
> use DBIx::Class::Loader;
> use UNIVERSAL::require;
> 
> # loader creates the basic classes for everything in the database
> my $loader = DBIx::Class::Loader->new(
>     dsn => 'dbi:pg:dbname=whatever',
>     namespace => 'MyApp',
>     relationships => 1,
>     ....
> );
> 
> # then we attempt to load additional code for any of those classes, if any
> foreach my $class ( $loader->classes ) {
>     $class->require;
> }
> 
> # and restart the C3 MRO calculations, just in case any of the code we
> # just loaded messed with inheritance
> Class::C3::reinitialize();

Probably not a bad idea, but provided you stick to the ->load_components
idiom for adding stuff it's unlikely to cause a problem; Componentised.pm
automatically reinitialize()s when necessary most of the time (this may be
deleterious to your startup times but using an ORM is anyway so I'm not
worrying about that until somebody shows me a bench :)

-- 
     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