Permalink
Browse files

Remove local $_ from Exporter

This was added in commit 732bb7c.

The changes in that commit did not necessitate the addition of
local $_.  So the localisation is wasting CPU cycles.  Worse, it
causes bugs in 5.12 and earlier.  (local $_ is always wrong if you
don’t control what is in $_ already, because it could be a read-only
tied variable.)  Actually, it causes bugs in 5.14-15 still, because
it seems that the changes to ‘local $_’ still weren’t sufficient (it
still calls FETCH, but not STORE).  That itself needs fixing, but that
should not obviate the need for this change, as Exporter has been liv-
ing a double life.
  • Loading branch information...
1 parent 36f9e82 commit da9127c72a244ecc246c9d82f152a4cbd318c4d6 Father Chrysostomos committed Dec 11, 2011
Showing with 18 additions and 2 deletions.
  1. +0 −1 lib/Exporter.pm
  2. +18 −1 lib/Exporter.t
View
@@ -44,7 +44,6 @@ sub import {
my $export_cache = ($Cache{$pkg} ||= {});
my $args = @_ or @_ = @$exports;
- local $_;
if ($args and not %$export_cache) {
s/^&//, $export_cache->{$_} = 1
foreach (@$exports, @{"$pkg\::EXPORT_OK"});
View
@@ -25,7 +25,7 @@ sub ok ($;$) {
BEGIN {
$test = 1;
- print "1..30\n";
+ print "1..31\n";
require Exporter;
ok( 1, 'Exporter compiled' );
}
@@ -233,3 +233,20 @@ eval { Carp::croak() };
::ok($Carp::Internal{Exporter}, "Carp recognizes Exporter");
::ok($Carp::Internal{'Exporter::Heavy'}, "Carp recognizes Exporter::Heavy");
+package Exporter::for::Tied::_;
+
+@ISA = 'Exporter';
+@EXPORT = 'foo';
+
+package Tied::_;
+
+sub TIESCALAR{bless[]}
+# no tie methods!
+
+{
+ tie my $t, __PACKAGE__;
+ for($t) { # $_ is now tied
+ import Exporter::for::Tied::_;
+ }
+}
+::ok(1, 'import with tied $_');

0 comments on commit da9127c

Please sign in to comment.