jjyoung has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to get used to Moose and I'm having an issue mixing roles with subclassing. I have a role of the form:
#!/pdd/100/bin/perl5.16/bin # Filename: ChainOfResponsibilityIf package ChainOfResponsibilityIf; use Moose::Role; requires 'handleRequest'; requires 'addHandler;
A class that uses it:
#!/pdd/100/bin/perl5.16/bin # Filename: CoRHandler.pm package CoRHandler; use Moose; use Carp qw(confess croak); with 'ChainOfResponsibilityIf'; # implementation of roles not shown
and then a class that extends CoRHandler but doesn't override the roles:
#!/pdd/100/bin/perl5.16/bin # Filename: GenericCommandHandler.pm package GenericCommandHandler; use Moose; extends 'CoRHandler'; override '_processCommand' => sub { }
When I create an instance of GenericCommandHandler and try to assign it to an attribute defined as:
has 'successor' => ( is => 'rw', isa => 'ChainOfResposibilityIf', );
I get the following error at runtime:
Attribute (successor) does not pass the type constraint because: Valid +ation failed for 'ChainOfResposibilityIf' with value GenericCommandHa +ndler=HASH(0x31bb698) at (eval 333)[/pdd/100/bin/perl5.16/lib/Eval/Cl +osure.pm:125] line 8.
Any clues to what I'm doing wrong? I've tried including the role 'with' declaration in the subclass, but then I get errors about missing the 'role' required methods.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose roles with extends
by tobyink (Canon) on Apr 11, 2014 at 08:52 UTC | |
|
Re: Moose roles with extends
by kcott (Archbishop) on Apr 11, 2014 at 07:12 UTC |