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

Moose Cookbook - Meta Recipe 5 Won't Run

by crashtest (Curate)
on Jan 12, 2012 at 03:47 UTC ( #947479=perlquestion: print w/ replies, xml ) Need Help??
crashtest has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, Monks!

I was just now trying to work something with Moose class traits that I thought I understood from the cookbook examples. I kept working my code, whittling it down to smaller and smaller attempts... until I finally just attempted the cookbook example:

package MyApp::Meta::Class::Trait::HasTable; use Moose::Role; has table => ( is => 'rw', isa => 'Str', ); package Moose::Meta::Class::Custom::Trait::HasTable; sub register_implementation { 'MyApp::Meta::Class::Trait::HasTable' } package MyApp::User; use Moose -traits => 'HasTable'; __PACKAGE__->meta->table('User');
which fails with the following:
Can't locate object method "table" via package "Moose::Meta::Class::__ +ANON__::SERIAL::1" at xxx_test_moose.pl line 15.

Can anyone help me with this - is there a mistake in the example, or am I missing some code/setup that is being assumed?

I would also appreciate it if someone can point me to a correct (Moose'ish) way of achieving the functionality of the recipe, if the recipe is indeed flawed. I am trying to build something that is quite similar to what is illustrated here.

Some of my system information: Windows XP, running Strawberry Perl 5.12.1 and Moose 2.0401.

Comment on Moose Cookbook - Meta Recipe 5 Won't Run
Select or Download Code
Re: Moose Cookbook - Meta Recipe 5 Won't Run
by Anonymous Monk on Jan 12, 2012 at 04:06 UTC

    I can't find it now, but IIRC, there is a tarball (or github repository) or the moose cookbook examples, so I would look for it, to see the file-layout

    This works

    BEGIN { package MyApp::Meta::Class::Trait::HasTable; use Moose::Role; has table => ( is => 'rw', isa => 'Str', ); package Moose::Meta::Class::Custom::Trait::HasTable; sub register_implementation { 'MyApp::Meta::Class::Trait::HasTable' } } package MyApp::User; use Moose -traits => 'HasTable'; __PACKAGE__->meta->table('User');

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://947479]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-10-24 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (137 votes), past polls