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(...);
78 use Data::Dumper::Concise::Sugar;
80 will import Dwarn, DwarnL, and DwarnS into your namespace. Using L<Exporter>, so see
81 its docs for ways to make it do something else.
85 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
89 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
93 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
95 =head1 TIPS AND TRICKS
99 Instead of always just doing:
101 use Data::Dumper::Concise::Sugar;
107 perl -MData::Dumper::Concise::Sugar foo.pl
109 (and then in the perl code:)
113 That way, if you leave them in and run without the
114 C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
115 you are less likely to check it in by accident. Furthmore it allows that
116 much less friction to add debug messages.
118 =head2 method chaining
120 One trick which is useful when doing method chaining is the following:
123 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
125 which is the same as:
128 (DwarnS $foo->bar->baz)->biff;
132 You probably want L<Devel::Dwarn>, it's the shorter name for this module.