tobyink / p5-sub-handlesvia

Perl 5 distribution Sub-HandlesVia; see homepage for downloads and documentation.

Home Page:https://metacpan.org/release/Sub-HandlesVia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrectly detects framework on roles when Moo is loaded

bbrtj opened this issue · comments

This example fails:

require Moo::Role;

package ThisFailsRole {
	use Mouse::Role;
	use Sub::HandlesVia;
}

use Test::More;
no feature 'indirect';

is Sub::HandlesVia->_detect_framework('ThisFailsRole'), 'Mouse', 'role ok';
done_testing;

The reason for this is that Moo::Role handles Moose / Mouse itself: https://metacpan.org/dist/Moo/source/lib/Moo/Role.pm#L163. So if only it is loaded, it will always think it handles Moo.

Additionally:

use Sub::Util qw(subname);
use Data::Dumper; 
die Dumper(subname(\&ThisFailsRole::has)); 
# Sub::HandlesVia::Toolkit::Moo::has

So it actually installed has wrapper from Moo, as suspected from _detect_framework result above.

Given the number of CPAN modules that may load Moo, this could be problematic.

Note: same problem with Moose::Role.

Changing the order which the checks happen would probably fix this.

Changing the order breaks Moo classes when Moose is loaded.

Tightening up the Moo::Role check seems to work better.