r69057 - in /branches/upstream/libdata-peek-perl/current: ChangeLog MANIFEST META.yml Makefile.PL Peek.pm Peek.xs README t/11_DDumper.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Sat Feb 19 03:46:38 UTC 2011
Author: jawnsy-guest
Date: Sat Feb 19 03:46:25 2011
New Revision: 69057
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=69057
Log:
[svn-upgrade] new version libdata-peek-perl (0.33)
Added:
branches/upstream/libdata-peek-perl/current/t/11_DDumper.t
Modified:
branches/upstream/libdata-peek-perl/current/ChangeLog
branches/upstream/libdata-peek-perl/current/MANIFEST
branches/upstream/libdata-peek-perl/current/META.yml
branches/upstream/libdata-peek-perl/current/Makefile.PL
branches/upstream/libdata-peek-perl/current/Peek.pm
branches/upstream/libdata-peek-perl/current/Peek.xs
branches/upstream/libdata-peek-perl/current/README
Modified: branches/upstream/libdata-peek-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/ChangeLog?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/ChangeLog (original)
+++ branches/upstream/libdata-peek-perl/current/ChangeLog Sat Feb 19 03:46:25 2011
@@ -1,3 +1,8 @@
+2011-02-16 0.33 - H.Merijn Brand <h.m.brand at xs4all.nl>
+
+ * Added DTidy (): stream DDumper output through Perl::Tidy
+ * Upped copyright to 2011
+
2010-11-21 0.32 - H.Merijn Brand <h.m.brand at xs4all.nl>
* Require perl 5.8.0
Modified: branches/upstream/libdata-peek-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/MANIFEST?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/MANIFEST (original)
+++ branches/upstream/libdata-peek-perl/current/MANIFEST Sat Feb 19 03:46:25 2011
@@ -9,6 +9,7 @@
t/00_pod.t Check if pod is valid
t/01_pod.t Check if pod covers all
t/10_DDumper.t Tests for DDumper ()
+t/11_DDumper.t Tests for DDumper () using Perl::Tidy
t/20_DPeek.t Tests for DPeek ()
t/21_DDisplay.t Tests for DDisplay ()
t/22_DHexDump.t Tests for DHexDump ()
Modified: branches/upstream/libdata-peek-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/META.yml?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/META.yml (original)
+++ branches/upstream/libdata-peek-perl/current/META.yml Sat Feb 19 03:46:25 2011
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Data::Peek
-version: 0.32
+version: 0.33
abstract: Modified and extended debugging facilities
license: perl
author:
@@ -10,17 +10,19 @@
provides:
Data::Peek:
file: Peek.pm
- version: 0.32
+ version: 0.33
requires:
perl: 5.008
DynaLoader: 0
+ Data::Dumper: 0
recommends:
- perl: 5.012002
+ perl: 5.012003
+ Perl::Tidy: 0
configure_requires:
ExtUtils::MakeMaker: 0
build_requires:
perl: 5.008
- Data::Dumper: 0
+test_requires:
Test::Harness: 0
Test::More: 0
Test::NoWarnings: 0
Modified: branches/upstream/libdata-peek-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/Makefile.PL?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/Makefile.PL (original)
+++ branches/upstream/libdata-peek-perl/current/Makefile.PL Sat Feb 19 03:46:25 2011
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# Copyright PROCURA B.V. (c) 2008-2010 H.Merijn Brand
+# Copyright PROCURA B.V. (c) 2008-2011 H.Merijn Brand
require 5.008; # <- also see postamble at the bottom for META.yml
use strict;
@@ -92,7 +92,7 @@
q{ sandbox/leaktest $(FULLPERLRUN) "test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(TEST_FILES)},
'',
'spellcheck:',
- ' pod-spell-check --aspell',
+ ' pod-spell-check --aspell --ispell',
'',
'checkmeta: spellcheck',
' perl sandbox/genMETA.pl -c',
@@ -134,7 +134,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2008-2010 H.Merijn Brand
+Copyright (C) 2008-2011 H.Merijn Brand
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
Modified: branches/upstream/libdata-peek-perl/current/Peek.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/Peek.pm?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/Peek.pm (original)
+++ branches/upstream/libdata-peek-perl/current/Peek.pm Sat Feb 19 03:46:25 2011
@@ -6,13 +6,23 @@
use DynaLoader ();
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
-$VERSION = "0.32";
+$VERSION = "0.33";
@ISA = qw( DynaLoader Exporter );
- at EXPORT = qw( DDumper DDsort DPeek DDisplay DDump DHexDump DDual DGrow );
- at EXPORT_OK = qw( triplevar );
+ at EXPORT = qw( DDumper DTidy DDsort DPeek DDisplay DDump DHexDump
+ DDual DGrow );
+ at EXPORT_OK = qw( triplevar :tidy );
push @EXPORT, "DDump_IO";
bootstrap Data::Peek $VERSION;
+
+our $has_perlio;
+our $has_perltidy;
+
+BEGIN {
+ use Config;
+ $has_perlio = ($Config{useperlio} || "undef") eq "define";
+ $has_perltidy = eval q{use Perl::Tidy; $Perl::Tidy::VERSION};
+ }
### ############# DDumper () ##################################################
@@ -45,7 +55,8 @@
[ reverse sort keys %$r ];
},
);
-my $_sortkeys = 1;
+my $_sortkeys = 1;
+our $_perltidy = 0;
sub DDsort
{
@@ -61,6 +72,11 @@
foreach my $p (@exp) {
exists $sk{$p} and DDsort ($p), next;
+ if ($p eq ":tidy") {
+ $_perltidy = $has_perltidy;
+ next;
+ }
+
push @etl, $p;
}
__PACKAGE__->export_to_level (1, @etl);
@@ -68,6 +84,8 @@
sub DDumper
{
+ $_perltidy and goto \&DTidy;
+
local $Data::Dumper::Sortkeys = $_sortkeys;
local $Data::Dumper::Indent = 1;
local $Data::Dumper::Quotekeys = 0;
@@ -76,7 +94,7 @@
local $Data::Dumper::Useqq = 0; # I want unicode visible
my $s = Data::Dumper::Dumper @_;
- $s =~ s/^(\s*)(.*?)\s*=>/sprintf "%s%-16s =>", $1, $2/gme; # Align =>
+ $s =~ s/^(\s*)(.*?)\s*=>/sprintf "%s%-16s =>", $1, $2/gme; # Align =>
$s =~ s/\bbless\s*\(\s*/bless (/gm and $s =~ s/\s+\)([;,])$/)$1/gm;
$s =~ s/^(?= *[]}](?:[;,]|$))/ /gm;
$s =~ s/^(\s*[{[]) *\n *(?=\S)(?![{[])/$1 /gm;
@@ -86,14 +104,26 @@
return $s;
} # DDumper
+sub DTidy
+{
+ $has_perltidy or goto \&DDumper;
+
+ local $Data::Dumper::Sortkeys = $_sortkeys;
+ local $Data::Dumper::Indent = 1;
+ local $Data::Dumper::Quotekeys = 1;
+ local $Data::Dumper::Deparse = 1;
+ local $Data::Dumper::Terse = 1;
+ local $Data::Dumper::Useqq = 0;
+
+ my $s = Data::Dumper::Dumper @_;
+ Perl::Tidy::perltidy (source => \$s, destination => \my $t);
+ $s = $t;
+
+ defined wantarray or warn $s;
+ return $s;
+ } # DTidy
+
### ############# DDump () ####################################################
-
-our $has_perlio;
-
-BEGIN {
- use Config;
- $has_perlio = ($Config{useperlio} || "undef") eq "define";
- }
sub _DDump_ref
{
@@ -206,6 +236,7 @@
use Data::Peek;
print DDumper \%hash; # Same syntax as Data::Dumper
+ DTidy { ref => $ref };
print DPeek \$var;
my ($pv, $iv, $nv, $rv, $magic) = DDual ($var [, 1]);
@@ -225,9 +256,12 @@
close $fh;
print $dump;
- use Data::Peek qw( DGrow triplevar );
+ # Imports
+ use Data::Peek qw( :tidy VNR DGrow triplevar );
my $x = ""; DGrow ($x, 10000);
my $tv = triplevar ("\N{GREEK SMALL LETTER PI}", 3, "3.1415");
+ DDsort ("R");
+ DDumper [ $x ]; # use of :tidy make DDumper behave as DTidy
=head1 DESCRIPTION
@@ -246,7 +280,9 @@
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
-And the result is further beautified to meet my needs:
+If C<Data::Peek> is C<use>d with import argument C<:tidy>, the result is
+formatted according to L<Perl::Tidy>, see L<DTidy> below, otherwise the
+result is further beautified to meet my needs:
* quotation of hash keys has been removed (with the disadvantage
that the output might not be parseable again).
@@ -257,7 +293,8 @@
Example
- print DDumper { ape => 1, foo => "egg", bar => [ 2, "baz", undef ]};
+ $ perl -MDP \
+ -e'DDumper { ape => 1, foo => "egg", bar => [ 2, "baz", undef ]};'
{ ape => 1,
bar => [
@@ -268,6 +305,26 @@
foo => 'egg'
};
+=head2 DTidy ($var, ...)
+
+C<DTidy> is an alternative to C<DDumper>, where the output of C<DDumper>
+is formatted using C<Perl::Tidy> (if available) according to your
+C<.perltidyrc> instead of the default behavior, maybe somewhat like (YMMV):
+
+ $ perl -MDP=:tidy \
+ -we'DDumper { ape => 1, foo => "egg", bar => [ 2, "baz", undef ]};'
+ { 'ape' => 1,
+ 'bar' => [2, 'baz', undef],
+ 'foo' => 'egg'
+ }
+
+If C<Data::Peek> is C<use>d with import argument C<:tidy>, this is the
+default output method for C<DDumper>.
+
+If L<Perl::Tidy> is not available, C<DTidy> will fallback to C<DDumper>.
+
+This idea was shamelessly copied from John McNamara's L<Data::Dumper::Perltidy>.
+
=head2 DDsort ( 0 | 1 | R | V | VR | VN | VNR )
Set the hash sort algorithm for DDumper. The default is to sort by key value.
@@ -282,13 +339,15 @@
These can also be passed to import:
- $ perl -MDP=VNR -we'DDumper { foo => 1, bar => 2, zap => 3, gum => 13 }'
+ $ perl -MDP=VNR \
+ -we'DDumper { foo => 1, bar => 2, zap => 3, gum => 13 }'
{ gum => 13,
zap => 3,
bar => 2,
foo => 1
};
- $ perl -MDP=V -we'DDumper { foo => 1, bar => 2, zap => 3, gum => 13 }'
+ $ perl -MDP=V \
+ -we'DDumper { foo => 1, bar => 2, zap => 3, gum => 13 }'
{ foo => 1,
gum => 13,
bar => 2,
@@ -370,7 +429,7 @@
" RV: ", DPeek ($d[3]), "\n";
}
-=head2 my $LEN = DGrow ($pv, $size)
+=head2 my $len = DGrow ($pv, $size)
Fastest way to preallocate space for a PV scalar. Returns the allocated
length. If $size is smaller than the already allocated space, it will
@@ -388,7 +447,7 @@
grow 1622943/s 2512% 967% --
-=head2 triplevar ($pv, $iv, $nv)
+=head2 my $tp = triplevar ($pv, $iv, $nv)
When making C<DDual ()> I wondered if it were possible to create triple-val
scalar variables. L<Scalar::Util> already gives us C<dualvar ()>, that creates
@@ -607,7 +666,7 @@
=head1 SEE ALSO
L<Devel::Peek>, L<Data::Dumper>, L<Data::Dump>, L<Devel::Dumpvar>,
-L<Data::Dump::Streamer>
+L<Data::Dump::Streamer>, L<Data::Dumper::Perltidy>, L<Perl::Tidy>.
=head1 AUTHOR
@@ -615,7 +674,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2008-2010 H.Merijn Brand
+Copyright (C) 2008-2011 H.Merijn Brand
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Modified: branches/upstream/libdata-peek-perl/current/Peek.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/Peek.xs?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/Peek.xs (original)
+++ branches/upstream/libdata-peek-perl/current/Peek.xs Sat Feb 19 03:46:25 2011
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008-2010 H.Merijn Brand. All rights reserved.
+/* Copyright (c) 2008-2011 H.Merijn Brand. All rights reserved.
* This program is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
*/
Modified: branches/upstream/libdata-peek-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/README?rev=69057&op=diff
==============================================================================
--- branches/upstream/libdata-peek-perl/current/README (original)
+++ branches/upstream/libdata-peek-perl/current/README Sat Feb 19 03:46:25 2011
@@ -56,7 +56,7 @@
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2008-2010 H.Merijn Brand. All rights reserved.
+Copyright (c) 2008-2011 H.Merijn Brand. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Added: branches/upstream/libdata-peek-perl/current/t/11_DDumper.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdata-peek-perl/current/t/11_DDumper.t?rev=69057&op=file
==============================================================================
--- branches/upstream/libdata-peek-perl/current/t/11_DDumper.t (added)
+++ branches/upstream/libdata-peek-perl/current/t/11_DDumper.t Sat Feb 19 03:46:25 2011
@@ -1,0 +1,69 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $ntests;
+BEGIN { $ntests = 33 };
+
+use Test::More tests => $ntests;
+#se Test::NoWarnings;
+
+BEGIN {
+ eval q{use Perl::Tidy};
+ if ($@) {
+ diag "Perl::Tidy not available";
+ ok (1) for 1..$ntests;
+ exit 0;
+ }
+ use_ok ("Data::Peek", ":tidy");
+ die "Cannot load Data::Peek\n" if $@;
+ }
+
+my ($dump, $var) = ("", "");
+while (<DATA>) {
+ chomp;
+ my ($v, $exp, $re) = split m/\t+ */;
+
+ if ($v eq "--") {
+ ok (1, "** $exp");
+ next;
+ }
+
+ $v =~ s/^S:([^:]*):// and DDsort ($1), $v =~ m/^()/; # And reset $1 for below
+
+ unless ($v eq "") {
+ eval "\$var = $v";
+ ok ($dump = DDumper ($var), "DDumper ($v)");
+ $dump =~ s/\A\$VAR1 = //;
+ $dump =~ s/;?\n\Z//;
+ }
+ if ($re) {
+ like ($dump, qr{$exp}ms, ".. content $re");
+ $1 and diag "# '$1' (", length ($1), ")\n";
+ }
+ else {
+ is ($dump, $exp, ".. content");
+ }
+ }
+
+1;
+
+__END__
+-- Basic values
+undef undef
+1 1
+"" ''
+"\xa8" '¨'
+1.24 '1.24'
+\undef \undef
+\1 \1
+\"" \''
+\"\xa8" \'¨'
+(0, 1) 1
+\(0, 1) \1
+-- Structures
+[0] \A\[\s*0\s*]\s*\Z tidy array 1
+[0, 1] \A\[\s*0\s*,\s*1\s*]\s*\Z tidy array 2
+[0,1,2] \A\[\s*0\s*,\s*1\s*,\s*2\s*]\s*\Z tidy array 3
+[[0],{foo=>1}] \A\[\s*\[\s*0\s*]\s*,\s*\{\s*'foo'\s*=>\s*1\s*}\s*]\s*\Z structure
More information about the Pkg-perl-cvs-commits
mailing list