r24454 - in /branches/upstream/libdata-dump-perl/current: Changes MANIFEST META.yml Makefile.PL README lib/Data/Dump.pm t/dd.t t/quote.t
ansgar-guest at users.alioth.debian.org
ansgar-guest at users.alioth.debian.org
Fri Aug 22 12:50:19 UTC 2008
Author: ansgar-guest
Date: Fri Aug 22 12:50:16 2008
New Revision: 24454
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=24454
Log:
[svn-upgrade] Integrating new upstream version, libdata-dump-perl (1.10)
Added:
branches/upstream/libdata-dump-perl/current/META.yml
branches/upstream/libdata-dump-perl/current/t/dd.t
Modified:
branches/upstream/libdata-dump-perl/current/Changes
branches/upstream/libdata-dump-perl/current/MANIFEST
branches/upstream/libdata-dump-perl/current/Makefile.PL
branches/upstream/libdata-dump-perl/current/README
branches/upstream/libdata-dump-perl/current/lib/Data/Dump.pm
branches/upstream/libdata-dump-perl/current/t/quote.t
Modified: branches/upstream/libdata-dump-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/Changes?rev=24454&op=diff
==============================================================================
--- branches/upstream/libdata-dump-perl/current/Changes (original)
+++ branches/upstream/libdata-dump-perl/current/Changes Fri Aug 22 12:50:16 2008
@@ -1,3 +1,18 @@
+2008-08-21 Gisle Aas <gisle at ActiveState.com>
+
+ Release 1.10
+
+ Add the functions quote(), dd() and ddx().
+
+ Fix segfault when duming large repeated strings [RT#33520]
+
+ Incorporated documentation improvements from Mark Stosberg
+
+ Apply Data-Dump-1.08-ANDK-01.patch from CPAN. Might do some
+ good on older Perl's I guess.
+
+
+
2006-11-29 Gisle Aas <gisle at ActiveState.com>
Release 1.08
Modified: branches/upstream/libdata-dump-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/MANIFEST?rev=24454&op=diff
==============================================================================
--- branches/upstream/libdata-dump-perl/current/MANIFEST (original)
+++ branches/upstream/libdata-dump-perl/current/MANIFEST Fri Aug 22 12:50:16 2008
@@ -1,15 +1,17 @@
Changes
lib/Data/Dump.pm
+Makefile.PL
MANIFEST
-Makefile.PL
README
+t/dd.t
t/dump.t
t/eval.t
t/glob.t
+t/quote-unicode.t
t/quote.t
-t/quote-unicode.t
t/ref.t
t/regexp.t
t/scalar-obj.t
t/scalar.t
t/tied.t
+META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libdata-dump-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/META.yml?rev=24454&op=file
==============================================================================
--- branches/upstream/libdata-dump-perl/current/META.yml (added)
+++ branches/upstream/libdata-dump-perl/current/META.yml Fri Aug 22 12:50:16 2008
@@ -1,0 +1,11 @@
+--- #YAML:1.0
+name: Data-Dump
+version: 1.10
+abstract: ~
+license: ~
+generated_by: ExtUtils::MakeMaker version 6.3201
+distribution_type: module
+requires:
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.2.html
+ version: 1.2
Modified: branches/upstream/libdata-dump-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/Makefile.PL?rev=24454&op=diff
==============================================================================
--- branches/upstream/libdata-dump-perl/current/Makefile.PL (original)
+++ branches/upstream/libdata-dump-perl/current/Makefile.PL Fri Aug 22 12:50:16 2008
@@ -4,5 +4,4 @@
WriteMakefile(
NAME => "Data::Dump",
VERSION_FROM => "lib/Data/Dump.pm",
- dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz'},
);
Modified: branches/upstream/libdata-dump-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/README?rev=24454&op=diff
==============================================================================
--- branches/upstream/libdata-dump-perl/current/README (original)
+++ branches/upstream/libdata-dump-perl/current/README Fri Aug 22 12:50:16 2008
@@ -1,24 +1,41 @@
-This package contain the Data::Dump module. It is a simplification of
-Sarathy's Data::Dumper. I made it to demonstrate for Sarathy how I
-would like Data::Dumper to work, and found it useful myself. Sarathy
-have plans to integrate this with his dumper, but while we wait, you
-can test this out.
+NAME
+ Data::Dump - Pretty printing of data structures
-The Data::Dump module provide a single function called dump() which
-you can import to your namespace if you wish:
+SYNOPSIS
+ use Data::Dump 'dump ddx';
- use Data::Dump qw(dump);
- $str = dump(@list);
+ $str = dump(@list)
@copy_of_list = eval $str;
-No OO interface is available and there are no configuration options to
-worry about. Other benefits is that the dump produced does not try to
-set any variables. It only returns what is needed to produce a copy of
-the arguments passed in. It means that `dump("foo")' simply returns
-`"foo"', and `dump(1..5)' simply returns `(1, 2, 3, 4, 5)'.
+ # or use it for easy debug printout
+ ddx localtime;
-Copyright 1998-1999,2003-2004 Gisle Aas.
-Copyright 1996-1998 Gurusamy Sarathy.
+DESCRIPTION
+ This module provide functions that takes a list of values as their
+ argument and produces a string as its result. The string contains Perl
+ code that, when "eval"ed, produces a deep copy of the original
+ arguments.
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+ The main feature of the module is that it strives to produce output that
+ is easy to read. Example:
+
+ @a = (1, [2, 3], {4 => 5});
+ dump(@a);
+
+ Produces:
+
+ (1, [2, 3], { 4 => 5 })
+
+ If you dump just a little data, it is output on a single line. If you
+ dump data that is more complex or there is a lot of it, line breaks are
+ automatically added to keep it easy to read.
+
+AUTHORS
+ The "Data::Dump" module is written by Gisle Aas <gisle at aas.no>, based on
+ "Data::Dumper" by Gurusamy Sarathy <gsar at umich.edu>.
+
+ Copyright 1998-2000,2003-2004,2008 Gisle Aas.
+ Copyright 1996-1998 Gurusamy Sarathy.
+
+ This library is free software; you can redistribute it and/or modify it
+ under the same terms as Perl itself.
Modified: branches/upstream/libdata-dump-perl/current/lib/Data/Dump.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/lib/Data/Dump.pm?rev=24454&op=diff
==============================================================================
--- branches/upstream/libdata-dump-perl/current/lib/Data/Dump.pm (original)
+++ branches/upstream/libdata-dump-perl/current/lib/Data/Dump.pm Fri Aug 22 12:50:16 2008
@@ -1,13 +1,15 @@
package Data::Dump;
use strict;
-use vars qw(@EXPORT_OK $VERSION $DEBUG);
+use vars qw(@EXPORT @EXPORT_OK $VERSION $DEBUG);
+use subs qq(dump);
require Exporter;
*import = \&Exporter::import;
- at EXPORT_OK=qw(dump pp);
-
-$VERSION = "1.08"; # $Date: 2006/11/29 10:47:17 $
+ at EXPORT = qw(dd ddx);
+ at EXPORT_OK = qw(dump pp quote);
+
+$VERSION = "1.10";
$DEBUG = 0;
use overload ();
@@ -103,6 +105,18 @@
*pp = \&dump;
+sub dd {
+ print dump(@_), "\n";
+}
+
+sub ddx {
+ my(undef, $file, $line) = caller;
+ $file =~ s,.*[\\/],,;
+ my $out = "$file:$line: " . dump(@_) . "\n";
+ $out =~ s/^/# /gm;
+ print $out;
+}
+
sub _dump
{
my $ref = ref $_[0];
@@ -141,7 +155,7 @@
}
my $out;
- if ($type eq "SCALAR" || $type eq "REF") {
+ if ($type eq "SCALAR" || $type eq "REF" || $type eq "REGEXP") {
if ($ref) {
if ($class && $class eq "Regexp") {
my $v = "$rval";
@@ -185,7 +199,7 @@
$out = $$rval;
}
else {
- $out = quote($$rval);
+ $out = str($$rval);
}
if ($class && !@$idx) {
# Top is an object, not a reference to one as perl needs
@@ -383,38 +397,29 @@
}
}
-my %esc = (
- "\a" => "\\a",
- "\b" => "\\b",
- "\t" => "\\t",
- "\n" => "\\n",
- "\f" => "\\f",
- "\r" => "\\r",
- "\e" => "\\e",
-);
-
-# put a string value in double quotes
-sub quote {
- local($_) = $_[0];
- if (length($_) > 20) {
+sub str {
+ if (length($_[0]) > 20) {
+ for ($_[0]) {
# Check for repeated string
- if (/^(.{1,5}?)(\1*)$/s) {
+ if (/^(.)\1\1\1/s) {
+ # seems to be a repating sequence, let's check if it really is
+ # without backtracking
+ unless (/[^\Q$1\E]/) {
+ my $base = quote($1);
+ my $repeat = length;
+ return "($base x $repeat)"
+ }
+ }
+ # Length protection because the RE engine will blow the stack [RT#33520]
+ if (length($_) < 16 * 1024 && /^(.{2,5}?)(\1*)\z/s) {
my $base = quote($1);
my $repeat = length($2)/length($1) + 1;
return "($base x $repeat)";
}
+ }
}
- # If there are many '"' we might want to use qq() instead
- s/([\\\"\@\$])/\\$1/g;
- return qq("$_") unless /[^\040-\176]/; # fast exit
-
- s/([\a\b\t\n\f\r\e])/$esc{$1}/g;
-
- # no need for 3 digits in escape for these
- s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
-
- s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
- s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
+
+ local $_ = "e;
if (length($_) > 40 && !/\\x\{/ && length($_) > (length($_[0]) * 2)) {
# too much binary data, better to represent as a hex/base64 string
@@ -433,6 +438,34 @@
return "pack(\"H*\",\"" . unpack("H*", $_[0]) . "\")";
}
+ return $_;
+}
+
+my %esc = (
+ "\a" => "\\a",
+ "\b" => "\\b",
+ "\t" => "\\t",
+ "\n" => "\\n",
+ "\f" => "\\f",
+ "\r" => "\\r",
+ "\e" => "\\e",
+);
+
+# put a string value in double quotes
+sub quote {
+ local($_) = $_[0];
+ # If there are many '"' we might want to use qq() instead
+ s/([\\\"\@\$])/\\$1/g;
+ return qq("$_") unless /[^\040-\176]/; # fast exit
+
+ s/([\a\b\t\n\f\r\e])/$esc{$1}/g;
+
+ # no need for 3 digits in escape for these
+ s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
+
+ s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
+ s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
+
return qq("$_");
}
@@ -446,30 +479,108 @@
=head1 SYNOPSIS
- use Data::Dump qw(dump);
+ use Data::Dump 'dump ddx';
$str = dump(@list)
@copy_of_list = eval $str;
+ # or use it for easy debug printout
+ ddx localtime;
+
=head1 DESCRIPTION
-This module provides a single function called dump() that takes a list
-of values as its argument and produces a string as its result. The string
-contains Perl code that, when C<eval>ed, produces a deep copy of the
-original arguments. The string is formatted for easy reading.
+This module provide functions that takes a list of values as their
+argument and produces a string as its result. The string contains
+Perl code that, when C<eval>ed, produces a deep copy of the original
+arguments.
+
+The main feature of the module is that it strives to produce output
+that is easy to read. Example:
+
+ @a = (1, [2, 3], {4 => 5});
+ dump(@a);
+
+Produces:
+
+ (1, [2, 3], { 4 => 5 })
+
+If you dump just a little data, it is output on a single line. If
+you dump data that is more complex or there is a lot of it, line breaks
+are automatically added to keep it easy to read.
+
+The following functions are provided (only the dd* functions are exported by default):
+
+=over
+
+=item dump( ... )
+
+=item pp( ... )
+
+This takes a list of arguments and produce a string containing a Perl
+expression as its result. If you pass this string to Perl's built-in
+eval() function it should return a copy of the arguments you passed
+to dump().
+
+If you call the function with multiple arguments then the output will
+be wrapped in parenthesis "( ..., ... )". If you call the function with a
+single argument it will not have these. If you call the function with
+a single scalar (non-reference) argument it will just return the
+scalar quoted if need, but never break it into multiple lines. If you
+pass multiple arguments or references to arrays of hashes then the
+return value might be contain line breaks to format it for easier
+reading. The returned string will never be "\n" terminated, even if
+contains multiple lines. This allows code like this to place the
+semicolon in the expected place:
+
+ print '$obj = ', dump($obj), ";\n";
If dump() is called in a void context, then the dump is printed on
-STDERR instead of being returned.
-
-If you don't like importing a function that overrides Perl's
-not-so-useful builtin, then you can also import the same function as
-pp(), mnemonic for "pretty-print".
+STDERR instead of being returned and then "\n" terminated. You might
+find this useful for quick debug printouts, but the dd*() functions
+might be a better alternative for this.
+
+There is no difference between dump() and pp(), except that dump()
+shares its name with a not-so-useful perl builtin. Because of this
+some might want to avoid using that name.
+
+=item quote( $string )
+
+Returns a quoted version of the provided string.
+
+It differs from dump($string) in that it will quote even numbers and
+not try to come up with clever expressions that might shorten the
+output.
+
+=item dd( ... )
+
+=item ddx( ... )
+
+These functions will call dump() on on their argument and print the
+result to STDOUT.
+
+The difference between them is only that ddx() will prefix the lines
+it prints with "# " and mark the first line with the file and line
+number where it was called. This is meant to be useful for debug
+printouts of state within programs.
+
+=back
+
+
+=head1 LIMITATIONS
+
+Code references will be displayed as simply 'sub { "???" }' when
+dumped. Thus, "eval'ing" them will not reproduce the original routine.
+
+If you forget to explicitly import the 'dump' function, your code will
+core dump. That's because you just called the builtin 'dump' function
+by accident, which intentionally dumps core. Because of this you can
+also import the same function as pp(), mnemonic for "pretty-print".
=head1 HISTORY
The C<Data::Dump> module grew out of frustration with Sarathy's
-in-most-cases-excellent C<Data::Dumper>. Basic ideas and some code are shared
-with Sarathy's module.
+in-most-cases-excellent C<Data::Dumper>. Basic ideas and some code
+are shared with Sarathy's module.
The C<Data::Dump> module provides a much simpler interface than
C<Data::Dumper>. No OO interface is available and there are no
@@ -488,7 +599,7 @@
The C<Data::Dump> module is written by Gisle Aas <gisle at aas.no>, based
on C<Data::Dumper> by Gurusamy Sarathy <gsar at umich.edu>.
- Copyright 1998-2000,2003-2004 Gisle Aas.
+ Copyright 1998-2000,2003-2004,2008 Gisle Aas.
Copyright 1996-1998 Gurusamy Sarathy.
This library is free software; you can redistribute it and/or
Added: branches/upstream/libdata-dump-perl/current/t/dd.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/t/dd.t?rev=24454&op=file
==============================================================================
--- branches/upstream/libdata-dump-perl/current/t/dd.t (added)
+++ branches/upstream/libdata-dump-perl/current/t/dd.t Fri Aug 22 12:50:16 2008
@@ -1,0 +1,14 @@
+#!perl -w
+
+use strict;
+use Test;
+plan tests => 1;
+
+use Data::Dump;
+
+print "# ";
+dd getlogin;
+ddx localtime;
+ddx \%Exporter::;
+
+ok(1);
Modified: branches/upstream/libdata-dump-perl/current/t/quote.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-dump-perl/current/t/quote.t?rev=24454&op=diff
==============================================================================
--- branches/upstream/libdata-dump-perl/current/t/quote.t (original)
+++ branches/upstream/libdata-dump-perl/current/t/quote.t Fri Aug 22 12:50:16 2008
@@ -3,9 +3,9 @@
use strict;
use Test qw(plan ok skip);
-plan tests => 9;
+plan tests => 17;
-use Data::Dump qw(dump);
+use Data::Dump qw(dump quote);
$Data::Dump::TRY_BASE64 = 0;
ok(dump(""), qq(""));
@@ -13,6 +13,9 @@
ok(dump("\0\1\x1F\0" . 3), qq("\\0\\1\\37\\x003"));
ok(dump("xx" x 30), qq(("x" x 60)));
ok(dump("xy" x 30), qq(("xy" x 30)));
+ok(dump("\0" x 1024), qq(("\\0" x 1024)));
+ok(dump("\$" x 1024), qq(("\\\$" x 1024)));
+ok(dump("\n" x (1024 * 1024)), qq(("\\n" x 1048576)));
ok(dump("\x7F\x80\xFF"), qq("\\x7F\\x80\\xFF"));
ok(dump(join("", map chr($_), 0..127)), qq("\\0\\1\\2\\3\\4\\5\\6\\a\\b\\t\\n\\13\\f\\r\\16\\17\\20\\21\\22\\23\\24\\25\\26\\27\\30\\31\\32\\e\\34\\35\\36\\37 !\\"#\\\$%&'()*+,-./0123456789:;<=>?\\\@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\x7F"));
ok(dump(join("", map chr($_), 0..255)), qq(pack("H*","000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")));
@@ -24,3 +27,10 @@
else {
skip("MIME::Base64 missing", 1);
}
+
+ok(quote(""), qq(""));
+ok(quote(42), qq("42"));
+ok(quote([]) =~ /^"ARRAY\(/);
+ok(quote('"'), qq("\\""));
+ok(quote("\0" x 1024), join("", '"', ("\\0") x 1024, '"'));
+
More information about the Pkg-perl-cvs-commits
mailing list