From: Matt S Trout Date: Sat, 13 Feb 2010 19:47:14 +0000 (+0000) Subject: add Dwarn_only and DwarnS_only X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d776e43427e88900efc149026583cc4b64d8c130;p=p5sagit%2FData-Dumper-Concise.git add Dwarn_only and DwarnS_only These routines take a block as their first argument and only warn+Dumper the results of the block. Dwarn_only is list context and simply provides @_, DwarnS_only also does local $_ for the argument in order to simplify usage. --- diff --git a/lib/Data/Dumper/Concise/Sugar.pm b/lib/Data/Dumper/Concise/Sugar.pm index addd8e2..9a514b2 100644 --- a/lib/Data/Dumper/Concise/Sugar.pm +++ b/lib/Data/Dumper/Concise/Sugar.pm @@ -9,10 +9,24 @@ BEGIN { @ISA = qw(Exporter) } @EXPORT = qw(Dwarn DwarnS); +@EXPORT_OK = qw(Dwarn_only DwarnS_only); + sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ } sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } +sub Dwarn_only (&@) { + my $only = shift; + warn Data::Dumper::Concise::Dumper $only->(@_); + @_ +} + +sub DwarnS_only (&$) { + my $only = shift; + warn Data::Dumper::Concise::Dumper do { local $_ = $_[0]; $only->($_[0]) }; + $_[0] +} + =head1 NAME Data::Dumper::Concise::Sugar - return Dwarn @return_value diff --git a/t/dwarn_only.t b/t/dwarn_only.t new file mode 100644 index 0000000..0036042 --- /dev/null +++ b/t/dwarn_only.t @@ -0,0 +1,9 @@ +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) ];