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?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |