1 package Data::Dumper::Concise::Sugar;
6 use Data::Dumper::Concise ();
9 BEGIN { @ISA = qw(Exporter) }
11 @EXPORT = qw(Dwarn DwarnS DwarnL DwarnN);
13 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
15 sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ }
17 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
21 warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0]
26 Data::Dumper::Concise::Sugar - return Dwarn @return_value
30 use Data::Dumper::Concise::Sugar;
32 return Dwarn some_call(...)
36 use Data::Dumper::Concise;
39 my @return = some_call(...);
43 my $return = some_call(...);
48 but shorter. If you need to force scalar context on the value,
50 use Data::Dumper::Concise::Sugar;
52 return DwarnS some_call(...)
56 use Data::Dumper::Concise;
58 my $return = some_call(...);
62 If you need to force list context on the value,
64 use Data::Dumper::Concise::Sugar;
66 return DwarnL some_call(...)
70 use Data::Dumper::Concise;
72 my @return = some_call(...);
76 If you want to label your output, try DwarnN
78 use Data::Dumper::Concise::Sugar;
84 use Data::Dumper::Concise;
86 my @return = some_call(...);
87 warn '$foo => ' . Dumper(@return);
92 use Data::Dumper::Concise::Sugar;
94 will import Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using
95 L<Exporter>, so see its docs for ways to make it do something else.
99 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
103 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
107 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
111 sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
113 =head1 TIPS AND TRICKS
117 Instead of always just doing:
119 use Data::Dumper::Concise::Sugar;
125 perl -MData::Dumper::Concise::Sugar foo.pl
127 (and then in the perl code:)
131 That way, if you leave them in and run without the
132 C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
133 you are less likely to check it in by accident. Furthmore it allows that
134 much less friction to add debug messages.
136 =head2 method chaining
138 One trick which is useful when doing method chaining is the following:
141 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
143 which is the same as:
146 (DwarnS $foo->bar->baz)->biff;
150 You probably want L<Devel::Dwarn>, it's the shorter name for this module.