Subject: | Requirements in roles should not be checked until all roles are consumed |
I was doing some refactoring in some code when I couldn't figure out why
Moo was saying I was missing some requirements, despite a consumed role
clearly providing said requirements.
I can replicate the bug in Moo 1.000007 with the following sample code:
{
package Role1;
use Moo::Role;
sub i_am_required { return 'this is required' }
}
{
package Role2;
use Moo::Role;
requires 'i_am_required';
sub another_method { 'this is provided' }
}
{
package Consumer;
use Moo;
with qw(Role2 Role1);
}
When you run this you get:
Can't apply Role2 to Consumer - missing i_am_required at ...
However, in the Consumer class, if you reverse Role2 and Role1 in the
with() statement, the code runs just fine.
Suggested fix (sans code): delay checking whether or not a class
provides all methods required until all roles are consumed and provided
methods are flattened into the class.
Cheers,
Ovid