[Dbix-class] using load_classes selectively
Matt S Trout
dbix-class at trout.me.uk
Fri Feb 8 07:59:18 GMT 2008
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 => 'My::DB::Bar');
> __PACKAGE__->has_many(baz => '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/
More information about the DBIx-Class
mailing list