Subject: | Data::Dump cannot handle vstrings |
Date: | Sat, 14 Aug 2010 11:31:49 -0500 |
To: | bug-Data-Dump [...] rt.cpan.org |
From: | Alex Ford <alex [...] pearanalytics.com> |
Data::Dump in its current incarnation gives up on vstring data:
$ perl -MData::Dump -E 'say $Data::Dump::VERSION; say $^V; dd v5.10.1'
1.17
v5.10.1
Can't handle VSTRING data at /usr/local/share/perl/5.10.1/Data/Dump.pm line
368.
'#VSTRING#'
I've included a preliminary patch:
---
lib/Data/Dump.pm | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/lib/Data/Dump.pm b/lib/Data/Dump.pm
index 3557d77..9ff39fc 100644
--- a/lib/Data/Dump.pm
+++ b/lib/Data/Dump.pm
@@ -364,6 +364,9 @@ sub _dump
elsif ($type eq "CODE") {
$out = 'sub { ... }';
}
+ elsif ($type eq "VSTRING") {
+ $out = sprintf +($ref ? '\v%vd' : 'v%vd'), $$rval;
+ }
else {
warn "Can't handle $type data";
$out = "'#$type#'";
--
I've included a small set of test cases to make sure it works in basic
cases; I'm sure that improvements could be made.
---
t/vstring.t | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
create mode 100644 t/vstring.t
diff --git a/t/vstring.t b/t/vstring.t
new file mode 100644
index 0000000..45e3e9f
--- /dev/null
+++ b/t/vstring.t
@@ -0,0 +1,18 @@
+#!perl -w
+
+use strict;
+use Test;
+plan tests => 9;
+
+use Data::Dump 'dump';
+
+ok(dump(v10), q{v10});
+ok(dump(v5.10.1), q{v5.10.1});
+ok(dump(5.10.1), q{v5.10.1});
+ok(dump(500.400.300.200.100), q{v500.400.300.200.100});
+
+ok(dump(\5.10.1), q{\v5.10.1});
+ok(dump(\v10), q{\v10});
+ok(dump(\\v10), q{\\\\v10});
+ok(dump([v10, v20, v30]), q{[v10, v20, v30]});
+ok(dump({ version => v6.0.0 }), q({ version => v6.0.0 }));
--
Alex Ford