Subject: | handles => 'Role' only works if class explicitly use's Role |
Perl 5.12.2
test.pm:
#############################
package test;
use Moo;
has a => (
is => 'ro',
handles => 'testrole',
);
1;
#############################
testrole.pm:
#############################
package testrole;
use Moo::Role;
requires 'bar';
1;
#############################
As far as I can figure, this should work. But...
---------------------------
% perl -Mtest -e 1
Can't locate object method "methods_provided_by" via package "Role::Tiny"
at [...]/lib/site_perl/5.12.2/Method/Generate/Accessor.pm line 135.
Compilation failed in require.
BEGIN failed--compilation aborted.
---------------------------
And indeed, Method::Generate::Accessor does not 'use' Role::Tiny, even
though it invokes Role::Tiny->methods_provided_by.
If I add a 'use Moo::Role ()' to either test.pm or
Method::Generate::Accessor, I then get:
---------------------------
% perl -Mtest -e 1
testrole is not a Role::Tiny
at [...]/lib/site_perl/5.12.2/Role/Tiny.pm line 273.
Compilation failed in require.
BEGIN failed--compilation aborted.
---------------------------
The only way to get this to work is to add an explicit
use testrole;
to test.pm. That doesn't match with my expectations, which are that
handles => 'testrole'
is all that should be needed to get things to work.
Thanks!
Diab