From: Matt S Trout Date: Fri, 3 Jun 2011 16:35:12 +0000 (+0000) Subject: transfer changes to _load_module to Role::Tiny's inlined version and document that... X-Git-Tag: release_0.009008~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5e03b55c684139e8f776dceaeee8a6dc51380ff1;p=gitmo%2FRole-Tiny.git transfer changes to _load_module to Role::Tiny's inlined version and document that it's a copy --- diff --git a/Changes b/Changes index 8a0ca07..e96099c 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - 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 diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm index d332ec6..1e53b0e 100644 --- a/lib/Moo/_Utils.pm +++ b/lib/Moo/_Utils.pm @@ -28,6 +28,8 @@ sub _install_modifier { 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"}; diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index d1a2bbb..10ef3c3 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -1,6 +1,7 @@ package Role::Tiny; sub _getglob { \*{$_[0]} } +sub _getstash { \%{"$_[0]::"} } use strict; use warnings FATAL => 'all'; @@ -9,9 +10,14 @@ our %INFO; 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; } diff --git a/t/load_module.t b/t/load_module.t index 6841e93..8704137 100644 --- a/t/load_module.t +++ b/t/load_module.t @@ -1,3 +1,5 @@ +# this test is replicated to t/load_module_role_tiny.t for Role::Tiny + # work around RT#67692 use Moo::_Utils; use strictures 1; diff --git a/t/load_module_role_tiny.t b/t/load_module_role_tiny.t new file mode 100644 index 0000000..2c7c88f --- /dev/null +++ b/t/load_module_role_tiny.t @@ -0,0 +1,20 @@ +# 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;