1 package Data::Dumper::Concise::Sugar;
6 use Data::Dumper::Concise ();
9 BEGIN { @ISA = qw(Exporter) }
11 @EXPORT = qw($Dwarn Dwarn DwarnS DwarnL DwarnN);
13 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
17 sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ }
19 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
23 warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0]
28 Data::Dumper::Concise::Sugar - return Dwarn @return_value
32 use Data::Dumper::Concise::Sugar;
34 return Dwarn some_call(...)
38 use Data::Dumper::Concise;
41 my @return = some_call(...);
45 my $return = some_call(...);
50 but shorter. If you need to force scalar context on the value,
52 use Data::Dumper::Concise::Sugar;
54 return DwarnS some_call(...)
58 use Data::Dumper::Concise;
60 my $return = some_call(...);
64 If you need to force list context on the value,
66 use Data::Dumper::Concise::Sugar;
68 return DwarnL some_call(...)
72 use Data::Dumper::Concise;
74 my @return = some_call(...);
78 If you want to label your output, try DwarnN
80 use Data::Dumper::Concise::Sugar;
86 use Data::Dumper::Concise;
88 my @return = some_call(...);
89 warn '$foo => ' . Dumper(@return);
92 If you want to output a reference returned by a method easily, try $Dwarn
94 $foo->bar->{baz}->$Dwarn
98 my $return = $foo->bar->{baz};
104 use Data::Dumper::Concise::Sugar;
106 will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using
107 L<Exporter>, so see its docs for ways to make it do something else.
111 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
119 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
123 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
127 sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
129 =head1 TIPS AND TRICKS
133 Instead of always just doing:
135 use Data::Dumper::Concise::Sugar;
141 perl -MData::Dumper::Concise::Sugar foo.pl
143 (and then in the perl code:)
147 That way, if you leave them in and run without the
148 C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
149 you are less likely to check it in by accident. Furthmore it allows that
150 much less friction to add debug messages.
152 =head2 method chaining
154 One trick which is useful when doing method chaining is the following:
157 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
159 which is the same as:
162 (DwarnS $foo->bar->baz)->biff;
166 You probably want L<Devel::Dwarn>, it's the shorter name for this module.