Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 73389
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: MARKLE [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 2.0202
  • 2.0203
  • 2.0204
  • 2.0205
  • 2.0300-TRIAL
  • 2.0301-TRIAL
  • 2.0302-TRIAL
  • 2.0400
  • 2.0401
Fixed in: 2.0600



Subject: example in Moose::Cookbook::Meta::Recipe5 generates error
I tried running the example in the Synopsis section of Moose::Cookbook::Meta::Recipe5. It generates this error: Can't locate object method "table" via package "Moose::Meta::Class::__ANON__::SERIAL::1" at ./work-scratch/moose-doodles.pl line 19. Here's my code (verbatim from the cookbook): ############### 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'); ############### Since this doesn't work, can you tell me if this is the right approach? Basically, I have a container object with roles. It has an attribute which is an arrayref of objects of another class. I want to create the container object with arbitrary roles as needed using MooseX::Traits. The container roles need a meta attribute to specify what other roles need to be applied to the objects in the arrayref to give them relevant methods. Thanks. Mark
On Tue Dec 20 15:24:59 2011, MARKLE wrote: Show quoted text
> I tried running the example in the Synopsis section of > Moose::Cookbook::Meta::Recipe5. It generates this error: > > Can't locate object method "table" via package > "Moose::Meta::Class::__ANON__::SERIAL::1" at > ./work-scratch/moose-doodles.pl line 19. > > Here's my code (verbatim from the cookbook): > > ############### > 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'); > > ############### > > Since this doesn't work, can you tell me if this is the right
approach? Show quoted text
> Basically, I have a container object with roles. It has an attribute > which is an arrayref of objects of another class. I want to create
the Show quoted text
> container object with arbitrary roles as needed using MooseX::Traits. > The container roles need a meta attribute to specify what other roles > need to be applied to the objects in the arrayref to give them
relevant Show quoted text
> methods.
The problem with the example is that when this is all in one file, the "use Moose -traits => 'HasTable';" line is executed before the "has table" line earlier. If the MyApp::Meta::Class::Trait::HasTable and the MyApp::User packages are in separate files, we don't have this problem. I'm not sure how to make the code work without introducing a confusing BEGIN {} block. I'll add a note to the recipe that tries to clarify that these should be separate files.