Hi all,

Please note: this problem has also been posted on PerlMonks.org:
http://perlmonks.org/index.pl?node_id=837339

I am working with Moose for quite some weeks now and enjoy it very much,
though the principles keep my head aching ;-)

Now I have a problem concerning traits:
When defining a class role and requiring some method with "requires",
the required method can be implemented in the class.
But where/how to implement a method that is required by an attribute trait?
Alternatively, is it possible to use MooseX::Role::Parameterized
together with attribute traits?

Example:
    use MooseX::Declare;
    role My::DirOption {
        requires '_build_rootdir';
       
        has rootdir => (
            isa => 'Str',
            is => 'rw',
            lazy => 1,
            builder => '_build_rootdir',
        );
    }
    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;

This gives:
    'My::DirOption' requires the method '_build_rootdir' to be
implemented + by 'Class::MOP::Class::__ANON__::SERIAL::9'

Where to implement the method '_build_rootdir'?

Regards,
Jens

Reply via email to