|XP is just a number|
Moose role with requirement consuming another roleby Boldra (Deacon)
|on Jul 20, 2011 at 09:45 UTC||Need Help??|
Boldra has asked for the wisdom of the Perl Monks concerning the following question:
I want a role to consume another role, and provide an attribute that the consumed role requires, but Moose won't see the attribute provided by the first role.
This code returns the error 'Role::App' requires the method 'smeg' to be implemented by 'App::FixIt'. But Role::App doesn't have any requirements, it's Role::Logger which requires smeg, and smeg is provided by Role::App.
The Moose documentation to required attributes warns that a requirement met by an attribute in a consuming class must be met before the role is consumed, so:
breaks because the requirement is met after the role is consumed. Here, swapping the order of with and has solves the problem. OTOH, requirement met by a subroutine would also be ok, because the subroutine is defined before with imposes the required constraints at runtime.
In summary: If a role requires a method and the requirement is met by:
Thanks for your thoughts!