From: Arthur Axel 'fREW' Schmidt Date: Sat, 13 Feb 2010 20:50:17 +0000 (-0600) Subject: doc for _only methods X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5054642f6999a563ee8e12118eb89d9445f274a5;p=p5sagit%2FData-Dumper-Concise.git doc for _only methods --- diff --git a/lib/Data/Dumper/Concise/Sugar.pm b/lib/Data/Dumper/Concise/Sugar.pm index cae80af..29400a8 100644 --- a/lib/Data/Dumper/Concise/Sugar.pm +++ b/lib/Data/Dumper/Concise/Sugar.pm @@ -58,6 +58,17 @@ is equivalent to: warn Dumper($return); return $return; +Sometimes you'll want to C out part of a result, instead of the entire +thing; for that we have C: + + # Dwarn the TO_JSON of all the objects in the list + my @results = Dwarn_only { map $_->TO_JSON, @_ } some_call(...); + +and C: + + # only Dwarn the first item + my $data = Dwarn_only { $_->[0] } [ some_call(...) ]; + Another trick that is extremely useful when doing method chaining is the following: @@ -80,10 +91,26 @@ its docs for ways to make it do something else. sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ } -=head3 DwarnS +=head2 DwarnS sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } +=head2 Dwarn_only + + sub Dwarn_only (&@) { + my $only = shift; + warn Data::Dumper::Concise::Dumper $only->(@_); + @_ + } + +=head2 DwarnS_only + + sub DwarnS_only (&$) { + my $only = shift; + warn Data::Dumper::Concise::Dumper do { local $_ = $_[0]; $only->($_[0]) }; + $_[0] + } + =head1 SEE ALSO You probably want L, it's the shorter name for this module. diff --git a/lib/Devel/Dwarn.pm b/lib/Devel/Dwarn.pm index c522a11..abcd9cd 100644 --- a/lib/Devel/Dwarn.pm +++ b/lib/Devel/Dwarn.pm @@ -38,6 +38,17 @@ is equivalent to: warn Dumper($return); return $return; +Sometimes you'll want to C out part of a result, instead of the entire +thing; for that we have C: + + # Dwarn the TO_JSON of all the objects in the list + my @results = Dwarn_only { map $_->TO_JSON, @_ } some_call(...); + +and C: + + # only Dwarn the first item + my $data = Dwarn_only { $_->[0] } [ some_call(...) ]; + Another trick that is extremely useful when doing method chaining is the following: diff --git a/t/dwarn_only.t b/t/dwarn_only.t deleted file mode 100644 index 0036042..0000000 --- a/t/dwarn_only.t +++ /dev/null @@ -1,9 +0,0 @@ -use strict; -use warnings FATAL => 'all'; -use Test::More qw(no_plan); - -use Devel::Dwarn qw(Dwarn_only DwarnS_only); - -warn Dwarn_only { $_[0] } qw(one two three); - -warn DwarnS_only { $_->[0] } [ qw(one two three) ];