X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FData%2FDumper%2FConcise%2FSugar.pm;h=4b33717b0749b3fd6437d46870fdf380aae8c114;hb=bef8cf5e5e01eadafefbd95cb99059a96faf73c7;hp=9394935e75e1692f30edaa09fe065ecbe20c6763;hpb=13b908a8bb2c12f572dffcf9e096fabf8a7b2b3b;p=p5sagit%2FData-Dumper-Concise.git diff --git a/lib/Data/Dumper/Concise/Sugar.pm b/lib/Data/Dumper/Concise/Sugar.pm index 9394935..4b33717 100644 --- a/lib/Data/Dumper/Concise/Sugar.pm +++ b/lib/Data/Dumper/Concise/Sugar.pm @@ -7,14 +7,23 @@ use Data::Dumper::Concise (); BEGIN { @ISA = qw(Exporter) } -@EXPORT = qw(Dwarn DwarnS DwarnL); +@EXPORT = qw($Dwarn $DwarnN Dwarn DwarnS DwarnL DwarnN); sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } +our $Dwarn = \&Dwarn; +our $DwarnN = \&DwarnN; + sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ } sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } +sub DwarnN ($) { + require Devel::ArgNames; + my $x = Devel::ArgNames::arg_names(); + warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0] +} + =head1 NAME Data::Dumper::Concise::Sugar - return Dwarn @return_value @@ -67,17 +76,49 @@ is equivalent to: warn Dumper(@return); return @return; +If you want to label your output, try DwarnN + + use Data::Dumper::Concise::Sugar; + + return DwarnN $foo + +is equivalent to: + + use Data::Dumper::Concise; + + my @return = some_call(...); + 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, and DwarnS into your namespace. Using L, so see -its docs for ways to make it do something else. +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 $DwarnN + + $DwarnN = \&DwarnN + =head2 DwarnL sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ } @@ -86,6 +127,12 @@ its docs for ways to make it do something else. sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } +=head2 DwarnN + + sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] } + +B: this requires L to be installed. + =head1 TIPS AND TRICKS =head2 global usage