1 package Data::Dumper::Concise::Sugar;
6 use Data::Dumper::Concise ();
8 BEGIN { @ISA = qw(Exporter) }
10 @EXPORT = qw($Dwarn $DwarnN Dwarn DwarnS DwarnL DwarnN);
12 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
15 our $DwarnN = \&DwarnN;
17 sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ }
19 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
22 require Devel::ArgNames;
23 my $x = Devel::ArgNames::arg_names();
24 warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0]
29 Data::Dumper::Concise::Sugar - return Dwarn @return_value
33 use Data::Dumper::Concise::Sugar;
35 return Dwarn some_call(...)
39 use Data::Dumper::Concise;
42 my @return = some_call(...);
46 my $return = some_call(...);
51 but shorter. If you need to force scalar context on the value,
53 use Data::Dumper::Concise::Sugar;
55 return DwarnS some_call(...)
59 use Data::Dumper::Concise;
61 my $return = some_call(...);
65 If you need to force list context on the value,
67 use Data::Dumper::Concise::Sugar;
69 return DwarnL some_call(...)
73 use Data::Dumper::Concise;
75 my @return = some_call(...);
79 If you want to label your output, try DwarnN
81 use Data::Dumper::Concise::Sugar;
87 use Data::Dumper::Concise;
89 my @return = some_call(...);
90 warn '$foo => ' . Dumper(@return);
93 If you want to output a reference returned by a method easily, try $Dwarn
95 $foo->bar->{baz}->$Dwarn
99 my $return = $foo->bar->{baz};
100 warn Dumper($return);
105 use Data::Dumper::Concise::Sugar;
107 will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using
108 L<Exporter>, so see its docs for ways to make it do something else.
112 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
124 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
128 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
132 sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
134 B<Note>: this requires L<Devel::ArgNames> to be installed.
136 =head1 TIPS AND TRICKS
140 Instead of always just doing:
142 use Data::Dumper::Concise::Sugar;
148 perl -MData::Dumper::Concise::Sugar foo.pl
150 (and then in the perl code:)
154 That way, if you leave them in and run without the
155 C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
156 you are less likely to check it in by accident. Furthmore it allows that
157 much less friction to add debug messages.
159 =head2 method chaining
161 One trick which is useful when doing method chaining is the following:
164 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
166 which is the same as:
169 (DwarnS $foo->bar->baz)->biff;
173 You probably want L<Devel::Dwarn>, it's the shorter name for this module.