[Dbix-class] using load_classes selectively

Frazer Irving superfraz at clumsyjedi.com
Fri Feb 8 09:33:07 GMT 2008


The business req

On Feb 8, 2008 7:59 AM, Matt S Trout <dbix-class at trout.me.uk> wrote:

> On Thu, Feb 07, 2008 at 04:39:05PM +0000, Frazer Irving wrote:
> > Hi everybody,
> >
> > I'm a first time poster to this list. I hope I have the right place to
> ask
> > this question.
> >
> > I am currently in the process of setting up DBIx::Class as the ORM for
> my
> > employer. I have setup the basic structure as so...
> >
> > package My::DB;
> > use base qw/DBIx::Class::Schema/;
> > __Package__->load_classes();
> >
> > package My::AbstractClass;
> > use base qw(DBIx::Class);
> >
> > package My::DB::Foo;
> > use base qw(My::AbstractClass);
> > ...
> > __PACKAGE__->belongs_to(bar =3D> 'My::DB::Bar');
> > __PACKAGE__->has_many(baz =3D> 'My::DB::Baz');
> >
> > That all works great, but the load_classes method is called for every
> class
> > whenever I 'use My::DB'. I would like the classes to only load when I am
> > going to use them. I have experimented with moving the load_classes
> > definitions into My::DB::Foo etc, and only specifying the current
> > __PACKAGE__ and it's relationships but this results in all relationships
> for
> > My::DB::Foo being loaded when that class is loaded even if they are not
> > going to be used.
> >
> > Is there some way I can load the relation classes only when a call is
> made
> > to the accessor for that relation? I have looked for an answer in the
> docs
> > and in the googles but to no avail.
>
> Not really. The loading time is fairly low if you either (a) have
> Class::C3::XS installed or (b) are on 5.10 (C3 built in)
>
> What business requirement is leading you to want on-demand loading?
>
> --
>      Matt S Trout       Need help with your Catalyst or DBIx::Class
> project?
>   Technical Director
> http://www.shadowcat.co.uk/catalyst/
>  Shadowcat Systems Ltd.  Want a managed development or deployment
> platform?
> http://chainsawblues.vox.com/
> http://www.shadowcat.co.uk/servers/
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080208/7b7=
fdf01/attachment-0001.htm


More information about the DBIx-Class mailing list