Skip to content

Commit

Permalink
Make dump($1) work [RT#63883]
Browse files Browse the repository at this point in the history
  • Loading branch information
gisle committed Oct 2, 2011
1 parent 7cd6b71 commit f4f4f48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/Data/Dump.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,17 @@ sub _dump
my($name, $idx, $dont_remember, $pclass, $pidx) = @_;

my($class, $type, $id);
if (overload::StrVal($rval) =~ /^(?:([^=]+)=)?([A-Z]+)\(0x([^\)]+)\)$/) {
$class = $1;
$type = $2;
$id = $3;
} else {
my $strval = overload::StrVal($rval);
# Parse $strval without using regexps, in order not to clobber $1, $2,...
if ((my $i = index($strval, "=")) >= 0) {
$class = substr($strval, 0, $i);
$strval = substr($strval, $i+1);
}
if ((my $i = index($strval, "(0x")) >= 0) {
$type = substr($strval, 0, $i);
$id = substr($strval, $i + 2, -1);
}
else {
die "Can't parse " . overload::StrVal($rval);
}
if ($] < 5.008 && $type eq "SCALAR") {
Expand Down
2 changes: 0 additions & 2 deletions t/dollar-one.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use Test::More tests => 3;
use Data::Dump qw/dump/;

if ("abc" =~ /(.+)/) {
TODO: { local $TODO = '$1 modified by dump itself';
is(dump($1), '"abc"');
is(dump(\$1), '\"abc"');
}
is(dump([$1]), '["abc"]');
}

0 comments on commit f4f4f48

Please sign in to comment.