From: Arthur Axel 'fREW' Schmidt Date: Thu, 22 Jul 2010 04:22:07 +0000 (-0500) Subject: Add DwarnN X-Git-Tag: v2.000~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0deeb75fab1e92bc66dd345ed084fe29338ba013;p=p5sagit%2FData-Dumper-Concise.git Add DwarnN --- diff --git a/Changes b/Changes index 2fd9b2c..6cfdeda 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,5 @@ - remove Dumper() returning object + - add DwarnN - add DwarnL - make Dwarn contextual - document ::Dwarn idiom diff --git a/lib/Data/Dumper/Concise/Sugar.pm b/lib/Data/Dumper/Concise/Sugar.pm index 9394935..75870a5 100644 --- a/lib/Data/Dumper/Concise/Sugar.pm +++ b/lib/Data/Dumper/Concise/Sugar.pm @@ -4,10 +4,11 @@ use 5.006; use Exporter (); use Data::Dumper::Concise (); +use Devel::ArgNames; BEGIN { @ISA = qw(Exporter) } -@EXPORT = qw(Dwarn DwarnS DwarnL); +@EXPORT = qw(Dwarn DwarnS DwarnL DwarnN); sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } @@ -15,6 +16,11 @@ sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ } sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } +sub DwarnN ($) { + my $x = arg_names(); + warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0] +} + =head1 NAME Data::Dumper::Concise::Sugar - return Dwarn @return_value diff --git a/t/dwarn.t b/t/dwarn.t index 240f9e4..8f9c607 100644 --- a/t/dwarn.t +++ b/t/dwarn.t @@ -5,6 +5,6 @@ use Devel::Dwarn; use Test::More qw(no_plan); -can_ok __PACKAGE__, qw{Dwarn DwarnS DwarnL}; +can_ok __PACKAGE__, qw{Dwarn DwarnS DwarnL DwarnN}; -can_ok 'Devel::Dwarn', qw{Dwarn DwarnS DwarnL}; +can_ok 'Devel::Dwarn', qw{Dwarn DwarnS DwarnL DwarnN}; diff --git a/t/sugar.t b/t/sugar.t index 7375415..e72955f 100644 --- a/t/sugar.t +++ b/t/sugar.t @@ -37,3 +37,15 @@ DWARN: { is $warned_string,qq{"robot"\n}, 'Dwarn warns scalars correctly'; is $bar, 'robot', 'Dwarn passes scalars through correctly'; } + +DWARNN: { + my $x = [1]; + my $foo = DwarnN $x; + is $warned_string, qq{\$x => [\n 1\n]\n}, 'DwarnN warns'; + + ok eq_array($foo, [1]), 'DwarnN passes through correctly'; + + DwarnN [1]; + is $warned_string, qq{(anon) => [\n 1\n]\n}, 'DwarnN warns'; +} +