From: Arthur Axel 'fREW' Schmidt Date: Fri, 30 Jul 2010 03:26:04 +0000 (-0500) Subject: add $Dwarn X-Git-Tag: v2.010~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7194c025550913190a5c82a91f80a64118949232;p=p5sagit%2FData-Dumper-Concise.git add $Dwarn --- diff --git a/lib/Data/Dumper/Concise/Sugar.pm b/lib/Data/Dumper/Concise/Sugar.pm index ef9d939..bbfdb6e 100644 --- a/lib/Data/Dumper/Concise/Sugar.pm +++ b/lib/Data/Dumper/Concise/Sugar.pm @@ -8,10 +8,12 @@ use Devel::ArgNames; BEGIN { @ISA = qw(Exporter) } -@EXPORT = qw(Dwarn DwarnS DwarnL DwarnN); +@EXPORT = qw($Dwarn Dwarn DwarnS DwarnL DwarnN); sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } +our $Dwarn = \&Dwarn; + sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ } sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } @@ -87,17 +89,31 @@ is equivalent to: warn '$foo => ' . Dumper(@return); return @return; +If you want to output a reference returned by a method easily, try $Dwarn + + $foo->bar->{baz}->$Dwarn + +is equivalent to: + + my $return = $foo->bar->{baz}; + warn Dumper($return); + return $return; + =head1 DESCRIPTION use Data::Dumper::Concise::Sugar; -will import Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using +will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using L, so see its docs for ways to make it do something else. =head2 Dwarn sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } +=head2 $Dwarn + + $Dwarn = \&Dwarn + =head2 DwarnL sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ } diff --git a/lib/Devel/Dwarn.pm b/lib/Devel/Dwarn.pm index 8211cf1..01da500 100644 --- a/lib/Devel/Dwarn.pm +++ b/lib/Devel/Dwarn.pm @@ -72,6 +72,16 @@ is equivalent to: warn '$foo => ' . Dumper(@return); return @return; +If you want to output a reference returned by a method easily, try $Dwarn + + $foo->bar->{baz}->$Dwarn + +is equivalent to: + + my $return = $foo->bar->{baz}; + warn Dumper($return); + return $return; + =head1 TIPS AND TRICKS =head2 global usage diff --git a/t/dwarn.t b/t/dwarn.t index 8f9c607..5579c47 100644 --- a/t/dwarn.t +++ b/t/dwarn.t @@ -8,3 +8,4 @@ use Test::More qw(no_plan); can_ok __PACKAGE__, qw{Dwarn DwarnS DwarnL DwarnN}; can_ok 'Devel::Dwarn', qw{Dwarn DwarnS DwarnL DwarnN}; +ok($Dwarn, 'Coderef gets exported too'); diff --git a/t/sugar.t b/t/sugar.t index e72955f..d62ed27 100644 --- a/t/sugar.t +++ b/t/sugar.t @@ -38,6 +38,13 @@ DWARN: { is $bar, 'robot', 'Dwarn passes scalars through correctly'; } +DWARN_CODEREF: { + my $foo = ['warn', 'friend']->$Dwarn; + is $warned_string,qq{[\n "warn",\n "friend"\n]\n}, 'Dwarn warns lists'; + + ok eq_array($foo, ['warn','friend']), 'Dwarn passes lists through correctly'; +} + DWARNN: { my $x = [1]; my $foo = DwarnN $x;