From ecd15a9a595d45d044034fd2a7baf5a02d9d3279 Mon Sep 17 00:00:00 2001 From: karel-m Date: Sun, 30 Jun 2013 20:46:08 +0200 Subject: [PATCH] undesirable change of SV flags - fix for https://rt.cpan.org/Ticket/Display.html?id=86592 --- Makefile.PL | 1 + lib/Data/Dump.pm | 12 ++++++++---- t/dollar-one.t | 6 +++--- t/scalar.t | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 920dafc..ef9e079 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -10,6 +10,7 @@ WriteMakefile( MIN_PERL_VERSION => 5.006, PREREQ_PM => { Symbol => 0, + B => 0, }, META_MERGE => { resources => { diff --git a/lib/Data/Dump.pm b/lib/Data/Dump.pm index 5704db6..cdd1b77 100644 --- a/lib/Data/Dump.pm +++ b/lib/Data/Dump.pm @@ -12,6 +12,7 @@ require Exporter; $VERSION = "1.22"; $DEBUG = 0; +use B; use overload (); use vars qw(%seen %refcnt @dump @fixup %require $TRY_BASE64 @FILTERS $INDENT); @@ -229,11 +230,14 @@ sub _dump if (!defined $$rval) { $out = "undef"; } - elsif (do {no warnings 'numeric'; $$rval + 0 eq $$rval}) { - $out = $$rval; - } else { - $out = str($$rval); + my $f = B::svref_2object($rval)->FLAGS; + if ($f & (B::SVp_IOK | B::SVp_NOK) && $$rval + 0 eq $$rval) { + $out = $$rval; + } + else { + $out = str($$rval); + } } if ($class && !@$idx) { # Top is an object, not a reference to one as perl needs diff --git a/t/dollar-one.t b/t/dollar-one.t index d1d057d..809015a 100644 --- a/t/dollar-one.t +++ b/t/dollar-one.t @@ -11,7 +11,7 @@ if ("abc" =~ /(.+)/) { } if ("123" =~ /(.+)/) { - is(dump($1), "123"); - is(dump(\$1), '\123'); - is(dump([$1]), '[123]'); + is(dump($1), '"123"'); + is(dump(\$1), '\"123"'); + is(dump([$1]), '["123"]'); } diff --git a/t/scalar.t b/t/scalar.t index caea190..325e207 100644 --- a/t/scalar.t +++ b/t/scalar.t @@ -11,7 +11,7 @@ print "$d;\n"; print "not " unless $d eq q(do { my $a = 42; - ($a, $a, \\$a, \\\\$a, 42, 42, [\\$a]); + ($a, $a, \\$a, \\\\$a, "42", 42, [\\$a]); }); print "ok 1\n";