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=75870a512fb20fb156afe75ebd2f8f068a52c87b;hpb=0deeb75fab1e92bc66dd345ed084fe29338ba013;p=p5sagit%2FData-Dumper-Concise.git diff --git a/lib/Data/Dumper/Concise/Sugar.pm b/lib/Data/Dumper/Concise/Sugar.pm index 75870a5..4b33717 100644 --- a/lib/Data/Dumper/Concise/Sugar.pm +++ b/lib/Data/Dumper/Concise/Sugar.pm @@ -4,20 +4,23 @@ use 5.006; use Exporter (); use Data::Dumper::Concise (); -use Devel::ArgNames; BEGIN { @ISA = qw(Exporter) } -@EXPORT = qw(Dwarn DwarnS DwarnL DwarnN); +@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 ($) { - my $x = arg_names(); + require Devel::ArgNames; + my $x = Devel::ArgNames::arg_names(); warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0] } @@ -73,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 @_; @_ } @@ -92,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