From: Matt S Trout Date: Fri, 16 Mar 2012 09:48:39 +0000 (+0000) Subject: Module::Runtime-ify X-Git-Tag: v0.009014~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cf62c98938670cba251cdc299ce194d0cdf694a2;hp=1fb2de927a866d9467859a16b89d5360da2c46c4;p=gitmo%2FMoo.git Module::Runtime-ify --- diff --git a/Changes b/Changes index 4847183..90a6e76 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ + - Switch Moo::Utils to using Module::Runtime, and add the 5.8 %INC + leakage fix into Role::Tiny's _load_module to provide partial parity - Update incompatibilities with Moose documentation - Remove Sub::Quote's outstanding queue since it doesn't actually slow things down to do it this way and makes debugging easier. diff --git a/Makefile.PL b/Makefile.PL index b047631..7a550c4 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,6 +12,7 @@ my %BUILD_DEPS = ( my %RUN_DEPS = ( 'Class::Method::Modifiers' => 1.07, 'strictures' => 1.001001, + 'Module::Runtime' => 0.013, ); # have to do this since old EUMM dev releases miss the eval $VERSION line diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm index 6b585cf..6fa6e24 100644 --- a/lib/Moo/_Utils.pm +++ b/lib/Moo/_Utils.pm @@ -11,6 +11,7 @@ BEGIN { } use strictures 1; +use Module::Runtime qw(require_module); use base qw(Exporter); use Moo::_mro; @@ -32,15 +33,13 @@ 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"}; # 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"; } + require_module($_[0]); return 1; } diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index 623b338..db9151e 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -10,15 +10,27 @@ our %INFO; our %APPLIED_TO; our %COMPOSED; -# inlined from Moo::_Utils - update that first. +# Module state workaround totally stolen from Zefram's Module::Runtime. + +BEGIN { + *_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0}; +} + +sub Role::Tiny::__GUARD__::DESTROY { + delete $INC{$_[0]->[0]} if @{$_[0]}; +} sub _load_module { (my $proto = $_[0]) =~ s/::/\//g; - return 1 if $INC{"${proto}.pm"}; + $proto .= '.pm'; + return 1 if $INC{$proto}; # 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"; + my $guard = _WORK_AROUND_BROKEN_MODULE_STATE + && bless([ $proto ], 'Role::Tiny::__GUARD__'); + require $proto; + pop @$guard if _WORK_AROUND_BROKEN_MODULE_STATE; return 1; }