maxhq has asked for the wisdom of the Perl Monks concerning the following question:
Dear wisest PerlMonks!
I have a problem concerning Moose traits: When defining a class role and requiring some method with requires, the method has to be implemented in the class.
But where/how to implement a method that is required by an attribute trait?
UPDATE: Alternatively, is it possible to use MooseX::Role::Parameterized together with attribute traits?
Example:
This gives:use MooseX::Declare; role My::DirOption { requires '_build_rootdir'; has rootdir => ( isa => 'Str', is => 'rw', lazy => 1, builder => '_build_rootdir', ); } # Make meta attribute trait known to Moose under a short name class Moose::Meta::Attribute::Custom::Trait::DirOption { sub register_implementation {'My::DirOption'} } class My::Config { use strict; use warnings; has testdir => ( traits => ['DirOption'], isa => 'Str', is => 'rw', ); ## This is the wrong place for the builder! method _build_rootdir() { return '/home/paulatreides'; } } 1;
'My::DirOption' requires the method '_build_rootdir' to be implemented + by 'Class::MOP::Class::__ANON__::SERIAL::9'
Is there anybody who can light my darkness?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose: Where to define a method required by an attribute trait?
by stvn (Monsignor) on Apr 28, 2010 at 21:01 UTC | |
by maxhq (Novice) on Apr 29, 2010 at 09:10 UTC | |
by stvn (Monsignor) on Apr 29, 2010 at 11:45 UTC | |
by maxhq (Novice) on Apr 29, 2010 at 17:56 UTC | |
by stvn (Monsignor) on Apr 30, 2010 at 19:31 UTC | |
|