From: Dagfinn Ilmari Mannsåker Date: Fri, 9 Nov 2012 16:35:06 +0000 (+0000) Subject: Don't use $_ as loop variable when calling arbitrary code (RT#81072) X-Git-Tag: v1.000006~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=141b507ace5957c098c52ceb7afaf21d5928a02d;hp=ce08ea519f2105eed00cbef6661c1637cbded27d;p=gitmo%2FMoo.git Don't use $_ as loop variable when calling arbitrary code (RT#81072) --- diff --git a/Changes b/Changes index eb52edf..b8cae11 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ + - Don't use $_ as loop variable when calling arbitrary code (RT#81072) + 1.000005 - 2012-10-23 - fix POD typo (RT#80060) - include init_arg name in constructor errors (RT#79596) diff --git a/lib/Moo.pm b/lib/Moo.pm index c47c3e9..fdd46e2 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -75,11 +75,11 @@ sub unimport { sub _set_superclasses { my $class = shift; my $target = shift; - for (@_) { - _load_module($_); - if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$_}) { + foreach my $superclass (@_) { + _load_module($superclass); + if ($INC{"Role/Tiny.pm"} && $Role::Tiny::INFO{$superclass}) { require Carp; - Carp::croak("Can't extend role '$_'"); + Carp::croak("Can't extend role '$superclass'"); } } # Can't do *{...} = \@_ or 5.10.0's mro.pm stops seeing @ISA diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index c382dd1..61d66da 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -190,7 +190,9 @@ sub _make_accessors { sub apply_roles_to_package { my ($me, $to, @roles) = @_; - $me->_inhale_if_moose($_) for @roles; + foreach my $role (@roles) { + $me->_inhale_if_moose($role); + } $me->SUPER::apply_roles_to_package($to, @roles); } @@ -211,7 +213,9 @@ sub create_class_with_roles { return $new_name if $Role::Tiny::COMPOSED{class}{$new_name}; - $me->_inhale_if_moose($_) for @roles; + foreach my $role (@roles) { + $me->_inhale_if_moose($role); + } my $m; if ($INC{"Moo.pm"} diff --git a/t/global_underscore.t b/t/global_underscore.t new file mode 100644 index 0000000..da11492 --- /dev/null +++ b/t/global_underscore.t @@ -0,0 +1,23 @@ +use strict; +use warnings; +use Test::More; +use lib qw(t/lib); + +use_ok('UnderscoreClass'); + +is( + UnderscoreClass->c1, + 'c1', +); + +is( + UnderscoreClass->r1, + 'r1', +); + +is( + ClobberUnderscore::h1(), + 'h1', +); + +done_testing; diff --git a/t/lib/ClobberUnderscore.pm b/t/lib/ClobberUnderscore.pm new file mode 100644 index 0000000..2679278 --- /dev/null +++ b/t/lib/ClobberUnderscore.pm @@ -0,0 +1,4 @@ +package ClobberUnderscore; +sub h1 { 'h1' }; +undef $_; +1; diff --git a/t/lib/UnderscoreClass.pm b/t/lib/UnderscoreClass.pm new file mode 100644 index 0000000..980b862 --- /dev/null +++ b/t/lib/UnderscoreClass.pm @@ -0,0 +1,5 @@ +package UnderscoreClass; +use Moo; +with qw(UnderscoreRole); +sub c1 { 'c1' }; +1; diff --git a/t/lib/UnderscoreRole.pm b/t/lib/UnderscoreRole.pm new file mode 100644 index 0000000..3afe0c9 --- /dev/null +++ b/t/lib/UnderscoreRole.pm @@ -0,0 +1,5 @@ +package UnderscoreRole; +use Moo::Role; +use ClobberUnderscore; +sub r1 { 'r1' }; +1;