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 DwarnF);
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]
27 sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
31 Data::Dumper::Concise::Sugar - return Dwarn @return_value
35 use Data::Dumper::Concise::Sugar;
37 return Dwarn some_call(...)
41 use Data::Dumper::Concise;
44 my @return = some_call(...);
48 my $return = some_call(...);
53 but shorter. If you need to force scalar context on the value,
55 use Data::Dumper::Concise::Sugar;
57 return DwarnS some_call(...)
61 use Data::Dumper::Concise;
63 my $return = some_call(...);
67 If you need to force list context on the value,
69 use Data::Dumper::Concise::Sugar;
71 return DwarnL some_call(...)
75 use Data::Dumper::Concise;
77 my @return = some_call(...);
81 If you want to label your output, try DwarnN
83 use Data::Dumper::Concise::Sugar;
89 use Data::Dumper::Concise;
91 my @return = some_call(...);
92 warn '$foo => ' . Dumper(@return);
95 If you want to output a reference returned by a method easily, try $Dwarn
97 $foo->bar->{baz}->$Dwarn
101 my $return = $foo->bar->{baz};
102 warn Dumper($return);
105 If you want to format the output of your data structures, try DwarnF
107 my ($a, $c) = DwarnF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
111 my @return = ($awesome, $cheesy);
112 warn DumperF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
117 use Data::Dumper::Concise::Sugar;
119 will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using
120 L<Exporter>, so see its docs for ways to make it do something else.
124 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
136 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
140 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
144 sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
146 B<Note>: this requires L<Devel::ArgNames> to be installed.
150 sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
152 =head1 TIPS AND TRICKS
156 Instead of always just doing:
158 use Data::Dumper::Concise::Sugar;
164 perl -MData::Dumper::Concise::Sugar foo.pl
166 (and then in the perl code:)
170 That way, if you leave them in and run without the
171 C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
172 you are less likely to check it in by accident. Furthmore it allows that
173 much less friction to add debug messages.
175 =head2 method chaining
177 One trick which is useful when doing method chaining is the following:
180 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
182 which is the same as:
185 (DwarnS $foo->bar->baz)->biff;
189 You probably want L<Devel::Dwarn>, it's the shorter name for this module.