Remove use of local($_) from dumpvar.pl
authorFather Chrysostomos <sprout@cpan.org>
Sat, 17 Dec 2011 04:46:35 +0000 (20:46 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 17 Dec 2011 04:46:35 +0000 (20:46 -0800)
I know we should really be fixing local($_), but that code
in scope.c is rather twisted, and I want to see this fix
in 5.16.

lib/dumpvar.pl
lib/dumpvar.t

index 91ec407..7aadba1 100644 (file)
@@ -37,7 +37,7 @@ sub main::dumpValue {
 # This one is good for variable names:
 
 sub unctrl {
-       local($_) = @_;
+    for (my($dummy) = shift) {
        local($v) ; 
 
        return \$_ if ref \$_ eq "GLOB";
@@ -47,7 +47,8 @@ sub unctrl {
        } else {
            s/([\001-\037\177])/'^'.pack('c',ord($1)^64)/eg;
        }
-       $_;
+       return $_;
+    }
 }
 
 sub uniescape {
@@ -57,7 +58,8 @@ sub uniescape {
 }
 
 sub stringify {
-       local($_,$noticks) = @_;
+    (my $__, local $noticks) = @_;
+    for ($__) {
        local($v) ; 
        my $tick = $tick;
 
@@ -101,9 +103,10 @@ sub stringify {
        }
        $_ = uniescape($_);
        s/([\200-\377])/'\\'.sprintf('%3o',ord($1))/eg if $quoteHighBit;
-       ($noticks || /^\d+(\.\d*)?\Z/) 
+       return ($noticks || /^\d+(\.\d*)?\Z/) 
          ? $_ 
          : $tick . $_ . $tick;
+    }
 }
 
 # Ensure a resulting \ is escaped to be \\
index 69ec3b2..f4f55d9 100644 (file)
@@ -49,6 +49,11 @@ sub new { my $class = shift; bless [ @_ ], $class }
 
 use overload '""' => sub { "Bar<@{$_[0]}>" };
 
+package Tyre;
+
+sub TIESCALAR{bless[]}
+# other methods intentionally omitted
+
 package main;
 
 my $foo = Foo->new(1..5);
@@ -318,3 +323,11 @@ EXPECT
 dumpvalue(bless[1,2,3,4],"a=b=c");
 EXPECT
 /0  a=b=c=ARRAY\(0x[0-9a-f]+\)\n   0  1\n   1  2\n   2  3\n   3  4\n/i
+########
+local *_; tie $_, 'Tyre'; stringify('');
+EXPECT
+''
+########
+local *_; tie $_, 'Tyre'; unctrl('abc');
+EXPECT
+abc