Subject: | Excluded methods should be added to 'requires' |
Consider the following code and the error message:
#!/usr/bin/env perl
package My::Role::Foo;
use Moose::Role;
sub foo { 'foo' }
package My::Class;
use Moose;
with 'My::Role::Foo' => { excludes => ['foo'] };
print My::Class->foo;
The error message is:
Can't locate object method "foo" via package "My::Class" at role.pl
line 12.
The problem that since My::Class->meta->does('My::Role::Foo'), there's a
promise that it will provide the &foo method. However, the failure
happens at runtime, not at composition time. I'm expecting a
composition-time error message like this:
My::Role::Foo' requires the method 'foo' to be implemented by
'My::Class' at ...
I think the solution is to have Moose::Meta::Role::add_excluded_methods
also call ->add_required_methods with the same argument list, but I've
not tested this.
Cheers,
Ovid