From: Arthur Axel 'fREW' Schmidt Date: Sun, 19 Feb 2012 23:58:09 +0000 (-0600) Subject: work in progress X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fweakdump;p=p5sagit%2FData-Dumper-Concise.git work in progress --- diff --git a/lib/Data/Dumper/Concise.pm b/lib/Data/Dumper/Concise.pm index 5e58826..e8ef95d 100644 --- a/lib/Data/Dumper/Concise.pm +++ b/lib/Data/Dumper/Concise.pm @@ -6,6 +6,7 @@ $VERSION = '2.020'; require Exporter; require Data::Dumper; +use Scalar::Util 'isweak'; BEGIN { @ISA = qw(Exporter) } @@ -16,7 +17,15 @@ sub DumperObject { $dd->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0)->Sortkeys(1); } -sub Dumper { DumperObject->Values([ @_ ])->Dump } +sub Dumper { + my $o = Data::Dumper->can('_dump'); + local *Data::Dumper::_dump = sub { + isweak($_[1]) + ? 'do { WEAK: ' . $o->(@_) . ' }' + : $o->(@_) + }; + DumperObject->Values([ @_ ])->Dump +} sub DumperF (&@) { my $code = shift; diff --git a/t/concise.t b/t/concise.t index 20e3512..32e422d 100644 --- a/t/concise.t +++ b/t/concise.t @@ -3,6 +3,7 @@ use warnings; use Data::Dumper (); use Data::Dumper::Concise; use Test::More qw(no_plan); +use Scalar::Util 'weaken'; my $dd = Data::Dumper->new([]) ->Terse(1) @@ -35,5 +36,9 @@ foreach my $to_dump ( } my $out = DumperF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl"; - +my $x = [1, 2]; +my $z = $x; +my $y = weaken($x); +warn Dumper($y); +warn Dumper($x); is($out, qq{arr: [\n "wut",\n "HALP"\n]\n str: "gnarl"\n}, 'DumperF works!');