in reply to Moose roles with extends
When Moose sees this:
has 'successor' => ( is => 'rw', isa => 'ChainOfResposibilityIf', );
If the ChainOfResposibilityIf role has not yet been loaded (use/require), Moose needs to make a snap decision about what kind of thing ChainOfResposibilityIf is. It needs to set up everything for the attribute straight away - it doesn't wait until you actully make use of the attribute.
Anyway, Moose guesses that it's a class. So later, when you assign to the attribute, it checks $value->isa('ChainOfResposibilityIf') (which fails) instead of $value->DOES('ChainOfResposibilityIf') (which would pass).
Three possible solutions. Any of them will do:
Load ChainOfResposibilityIf earlier. Before using it in an attribute definition. (This seems the most fragile solution to me, and is my least preferred, but it should work.)
Instead of isa use does:
has 'successor' => ( is => 'rw', does => 'ChainOfResposibilityIf', # !!! );
Create an explicit type constraint object, and pass that to isa instead of passing the string "ChainOfResposibilityIf":
use Moose::Util::TypeConstraints qw(role_type); has 'successor' => ( is => 'rw', isa => role_type('ChainOfResposibilityIf'), );
|
|---|