Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

DBIx::Class Result classes using Moose

by tospo (Hermit)
on May 02, 2012 at 09:21 UTC ( #968402=perlmeditation: print w/ replies, xml ) Need Help??

I'm just posting this here because I found it surprisingly difficult to get the information I needed but maybe my Google-Fu wasn't good today.

If you want to use Moose Roles in DBIC Result classes, all you need to do is make your Result class look like this:

package MyApp::Schema::Result::Foo; use strict; use warnings; use Moose; use MooseX::NonMoose; use MooseX::MarkAsMethods autoclean => 1; extends 'DBIx::Class::Core'; ### all the usual __PACKAGE__->table etc stuff goes in here ### # and as always with Moose classes __PACKAGE__->meta->make_immutable; 1;
Your Schema class should look like this:
package Test::Schema; use Moose; use MooseX::MarkAsMethods autoclean => 1; extends 'DBIx::Class::Schema'; __PACKAGE__->load_namespaces; __PACKAGE__->meta->make_immutable(inline_constructor => 0); 1;
You can use dbicdump to create files using Moose with the
-o use_moose=1
option or just modify your existing classes as outlined above.

For more information, check out the docs for DBIx-Class-Schema-Loader

Comment on DBIx::Class Result classes using Moose
Select or Download Code
Re: DBIx::Class Result classes using Moose
by sundialsvc4 (Monsignor) on May 02, 2012 at 11:36 UTC

    Thank you for saving a little bit of every one else’s “Google-Fu!”   :-D

Re: DBIx::Class Result classes using Moose
by tospo (Hermit) on May 02, 2012 at 15:54 UTC
    oh, just realised I had forgottoen to mention how to make use of the actual Moose Role in the end but of course that's trivial once your result class (MyApp::Schema::Result::Foo) is a proper Moose class:
    ... extends 'DBIx::Class::Core'; with "FoomakerRole"; ...
Re: DBIx::Class Result classes using Moose
by tospo (Hermit) on May 09, 2012 at 12:39 UTC

    Using Moose Roles in ResultSet Classes

    turns out that this is a bit more tricky and needs some more magic. Thanks to the folks over on irc I found out that you need to fiddle with the BUILDARGS to make it work. So, the above code works for Result classes, while the following will enable Moose in your ResultSet classes:
    package MyApp::Schema::ResultSet::Foo; use strict; use warnings; use Moose; use MooseX::NonMoose; use MooseX::MarkAsMethods autoclean => 1; extends 'DBIx::Class::ResultSet'; with 'SomeOldRole'; # insert your Role here... # This is the crucial bit - don't ask.... sub BUILDARGS { $_[2] } ### your ResultSet methods here ### __PACKAGE__->meta->make_immutable; 1;

      When using MooseX::NonMoose in my ResultSet class as described here I find that calling new() on it fails when it tries to proxy over to new_result().

      Is this a known bug (or limitation) of MooseX::NonMoose? Or am I doing something wrong?

      Error I get (on DBIx-Class-0.08196):

      Can't call method "isa" on unblessed reference at DBIx::Class::ResultSet::new(/usr/local/share/perl/5.10.1/DB +Ix/Class/ResultSet.pm:197)
        sorry for the delay - haven't been in here for a while... Can't even help you much I'm afraid. It worked fine for me. Can you post some code?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://968402]
Approved by GrandFather
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-08-02 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (54 votes), past polls