Subject: | Role::Tiny::_load_module is easily misled about modules being loaded |
All tests w/ Perl 5.10.0, Moo 0.00905
Role::Tiny::_load_module uses $class->can('can') to see if $class is
loaded. Unfortunately, this can be (easily) misled.
The first instance of this I came across involved the class which was
requesting a role also using Class::Autouse
==> Foo.pm <==
package Foo;
use Moo;
use Class::Autouse qw[ :nostat Bar ];
with 'Roll';
1;
==> Roll.pm <==
package Roll;
use Moo::Role;
1;
% perl Foo.pm
Roll is not a Role::Tiny at
/proj/axaf/ots/pkgs/perl/x86_64-linux_debian-5.0/lib/perl5/Role/Tiny.pm
line 57.
Class::Autouse plugs in a can() method which foils the can('can') check
by returning a valid coderef.
The next example is a little strange. If you use a class which has a
component in its name which is the same as your role class Perl will
happily return a coderef from can('can'). For example:
==> Gak.pm <==
package Roll::Mine;
1;
package Gak;
use Moo;
with 'Roll';
% perl Gak.pm
Roll is not a Role::Tiny at
/proj/axaf/ots/pkgs/perl/x86_64-linux_debian-5.0/lib/perl5/Role/Tiny.pm
line 57.
Removing the Roll::Mine package causes it to work properly.
Thanks,
Diab