+ - create DwarnF for formatting Dumper'd output
+
2.012 Aug 31 2010
- Make DwarnN test still work if Devel::ArgNames isn't installed
BEGIN { @ISA = qw(Exporter) }
-@EXPORT = qw(Dumper);
+@EXPORT = qw(Dumper DumperF);
sub Dumper {
my $dd = Data::Dumper->new([]);
return $dd->Values([ @_ ])->Dump;
}
+sub DumperF (&@) {
+ my $code = shift;
+ return $code->(map Dumper($_), @_);
+}
+
=head1 NAME
Data::Dumper::Concise - Less indentation and newlines plus sub deparsing
(note the tab indentation, oh joy ...)
+Also try out C<DumperF> which takes a C<CodeRef> as the first argument to
+format the output. For example:
+
+ use Data::Dumper::Concise;
+
+ warn DumperF { "result: $_[0] result2: $_[1]" } $foo, $bar;
+
+Which is the same as:
+
+ warn 'result: ' . Dumper($foo) . ' result2: ' . Dumper($bar);
+
=head1 DESCRIPTION
This module always exports a single function, Dumper, which can be called
BEGIN { @ISA = qw(Exporter) }
-@EXPORT = qw($Dwarn $DwarnN Dwarn DwarnS DwarnL DwarnN);
+@EXPORT = qw($Dwarn $DwarnN Dwarn DwarnS DwarnL DwarnN DwarnF);
sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0]
}
+sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
+
=head1 NAME
Data::Dumper::Concise::Sugar - return Dwarn @return_value
warn Dumper($return);
return $return;
+If you want to format the output of your data structures, try DwarnF
+
+ my ($a, $c) = DwarnF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
+
+is equivalent to:
+
+ my @return = ($awesome, $cheesy);
+ warn DumperF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
+ return @return;
+
=head1 DESCRIPTION
use Data::Dumper::Concise::Sugar;
B<Note>: this requires L<Devel::ArgNames> to be installed.
+=head2 DwarnF
+
+ sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
+
=head1 TIPS AND TRICKS
=head2 global usage
is($example, Dumper(@$to_dump), 'Subroutine call usage equivalent');
}
+
+my $out = DumperF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl";
+
+is($out, qq{arr: [\n "wut",\n "HALP"\n]\n str: "gnarl"\n}, 'DumperF works!');
ok eq_array($foo, ['warn','friend']), 'Dwarn passes lists through correctly';
}
+DWARNF: {
+ my @foo = DwarnF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl";
+
+ is($warned_string, qq{arr: [\n "wut",\n "HALP"\n]\n str: "gnarl"\n}, 'DumperF works!');
+ ok eq_array($foo[0], ['wut','HALP']) && $foo[1] eq 'gnarl', 'DwarnF passes lists through correctly';
+}
+
DWARNN: {
my $loaded = eval { require Devel::ArgNames; 1 };
if ($loaded) {