don't use $_ as loop variable when calling arbitrary code
[gitmo/Role-Tiny.git] / lib / Role / Tiny.pm
index 9ebe242..9a3ce29 100644 (file)
@@ -6,7 +6,7 @@ sub _getstash { \%{"$_[0]::"} }
 use strict;
 use warnings FATAL => 'all';
 
-our $VERSION = '1.002000'; # 1.2.0
+our $VERSION = '1.002004'; # 1.2.4
 $VERSION = eval $VERSION;
 
 our %INFO;
@@ -45,7 +45,7 @@ sub import {
   warnings->import(FATAL => 'all');
   return if $INFO{$target}; # already exported into this package
   # get symbol table reference
-  my $stash = do { no strict 'refs'; \%{"${target}::"} };
+  my $stash = _getstash($target);
   # install before/after/around subs
   foreach my $type (qw(before after around)) {
     *{_getglob "${target}::${type}"} = sub {
@@ -190,14 +190,18 @@ sub apply_roles_to_package {
     delete $INFO{$to}{methods}; # reset since we're about to add methods
   }
 
-  $me->apply_role_to_package($to, $_) for @roles;
+  foreach my $role (@roles) {
+    $me->apply_single_role_to_package($to, $role);
+  }
   $APPLIED_TO{$to}{join('|',@roles)} = 1;
 }
 
 sub _composite_info_for {
   my ($me, @roles) = @_;
   $COMPOSITE_INFO{join('|', sort @roles)} ||= do {
-    _load_module($_) for @roles;
+    foreach my $role (@roles) {
+      _load_module($role);
+    }
     my %methods;
     foreach my $role (@roles) {
       my $this_methods = $me->_concrete_methods_of($role);
@@ -214,7 +218,11 @@ sub _composable_package_for {
   return $composed_name if $COMPOSED{role}{$composed_name};
   $me->_install_methods($composed_name, $role);
   my $base_name = $composed_name.'::_BASE';
-  *{_getglob("${composed_name}::ISA")} = [ $base_name ];
+  # Not using _getglob, since setting @ISA via the typeglob breaks
+  # inheritance on 5.10.0 if the stash has previously been accessed an
+  # then a method called on the class (in that order!), which
+  # ->_install_methods (with the help of ->_install_does) ends up doing.
+  { no strict 'refs'; @{"${composed_name}::ISA"} = ( $base_name ); }
   my $modifiers = $INFO{$role}{modifiers}||[];
   my @mod_base;
   foreach my $modified (
@@ -250,7 +258,7 @@ sub _concrete_methods_of {
   my ($me, $role) = @_;
   my $info = $INFO{$role};
   # grab role symbol table
-  my $stash = do { no strict 'refs'; \%{"${role}::"}};
+  my $stash = _getstash($role);
   # reverse so our keys become the values (captured coderefs) in case
   # they got copied or re-used since
   my $not_methods = { reverse %{$info->{not_methods}||{}} };
@@ -278,7 +286,7 @@ sub _install_methods {
   my $methods = $me->_concrete_methods_of($role);
 
   # grab target symbol table
-  my $stash = do { no strict 'refs'; \%{"${to}::"}};
+  my $stash = _getstash($to);
 
   # determine already extant methods of target
   my %has_methods;
@@ -321,7 +329,7 @@ sub _install_does {
   # add does() only if they don't have one
   *{_getglob "${to}::does"} = \&does_role unless $to->can('does');
   
-  return if ($to->can('DOES') and $to->can('DOES') != UNIVERSAL->can('DOES'));
+  return if ($to->can('DOES') and $to->can('DOES') != (UNIVERSAL->can('DOES') || 0));
   
   my $existing = $to->can('DOES') || $to->can('isa') || $FALLBACK;
   my $new_sub = sub {