+ - transfer fix to _load_module to Role::Tiny and make a note it's an inline
- Bring back 5.8.1 compat
0.009007 - 2011-02-25
our %MAYBE_LOADED;
+# _load_module is inlined in Role::Tiny - make sure to copy if you update it.
+
sub _load_module {
(my $proto = $_[0]) =~ s/::/\//g;
return 1 if $INC{"${proto}.pm"};
package Role::Tiny;
sub _getglob { \*{$_[0]} }
+sub _getstash { \%{"$_[0]::"} }
use strict;
use warnings FATAL => 'all';
our %APPLIED_TO;
our %COMPOSED;
+# inlined from Moo::_Utils - update that first.
+
sub _load_module {
- return 1 if $_[0]->can('can');
(my $proto = $_[0]) =~ s/::/\//g;
+ return 1 if $INC{"${proto}.pm"};
+ # can't just ->can('can') because a sub-package Foo::Bar::Baz
+ # creates a 'Baz::' key in Foo::Bar's symbol table
+ return 1 if grep !/::$/, keys %{_getstash($_[0])||{}};
require "${proto}.pm";
return 1;
}
+# this test is replicated to t/load_module_role_tiny.t for Role::Tiny
+
# work around RT#67692
use Moo::_Utils;
use strictures 1;
--- /dev/null
+# this test is replicated to t/load_module.t for Moo::_Utils
+
+use Role::Tiny ();
+use strictures 1;
+use Test::More;
+
+local @INC = (sub {
+ return unless $_[1] eq 'Foo/Bar.pm';
+ my $source = "package Foo::Bar; sub baz { 1 } 1";
+ open my $fh, '<', \$source;
+ $fh;
+}, @INC);
+
+{ package Foo::Bar::Baz; sub quux { } }
+
+Role::Tiny::_load_module("Foo::Bar");
+
+ok(eval { Foo::Bar->baz }, 'Loaded module ok');
+
+done_testing;