1 package Data::Dumper::Concise::Sugar;
5 our $VERSION = '2.023';
8 use Data::Dumper::Concise ();
10 BEGIN { @ISA = qw(Exporter) }
13 $Dwarn $DwarnN Dwarn DwarnS DwarnL DwarnN DwarnF
14 $Ddie $DdieN Ddie DdieS DdieL DdieN DdieD
17 sub Dwarn { DwarnL(@_); return wantarray ? @_ : $_[0] }
20 our $DwarnN = \&DwarnN;
22 sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ }
24 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
27 require Devel::ArgNames;
28 my $x = Devel::ArgNames::arg_names();
29 warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0]
32 sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
34 sub Ddie { DdieL(@_); return wantarray ? @_ : $_[0] }
39 sub DdieL { die Data::Dumper::Concise::Dumper @_ }
41 sub DdieS ($) { die Data::Dumper::Concise::Dumper $_[0] }
44 require Devel::ArgNames;
45 my $x = Devel::ArgNames::arg_names();
46 die(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]);
51 Data::Dumper::Concise::Sugar - return Dwarn @return_value
55 use Data::Dumper::Concise::Sugar;
57 return Dwarn some_call(...)
61 use Data::Dumper::Concise;
64 my @return = some_call(...);
68 my $return = some_call(...);
73 but shorter. If you need to force scalar context on the value,
75 use Data::Dumper::Concise::Sugar;
77 return DwarnS some_call(...)
81 use Data::Dumper::Concise;
83 my $return = some_call(...);
87 If you need to force list context on the value,
89 use Data::Dumper::Concise::Sugar;
91 return DwarnL some_call(...)
95 use Data::Dumper::Concise;
97 my @return = some_call(...);
101 If you want to label your output, try DwarnN
103 use Data::Dumper::Concise::Sugar;
109 use Data::Dumper::Concise;
111 my @return = some_call(...);
112 warn '$foo => ' . Dumper(@return);
115 If you want to output a reference returned by a method easily, try $Dwarn
117 $foo->bar->{baz}->$Dwarn
121 my $return = $foo->bar->{baz};
122 warn Dumper($return);
125 If you want to format the output of your data structures, try DwarnF
127 my ($a, $c) = DwarnF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
131 my @return = ($awesome, $cheesy);
132 warn DumperF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
135 If you want to immediately die after outputting the data structure, every
136 Dwarn subroutine has a paired Ddie version, so just replace the warn with die.
139 DdieL 'foo', { bar => 'baz' };
143 use Data::Dumper::Concise::Sugar;
145 will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using
146 L<Exporter>, so see its docs for ways to make it do something else.
150 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
162 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
166 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
170 sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
172 B<Note>: this requires L<Devel::ArgNames> to be installed.
176 sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
178 =head1 TIPS AND TRICKS
182 Instead of always just doing:
184 use Data::Dumper::Concise::Sugar;
190 perl -MData::Dumper::Concise::Sugar foo.pl
192 (and then in the perl code:)
196 That way, if you leave them in and run without the
197 C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
198 you are less likely to check it in by accident. Furthmore it allows that
199 much less friction to add debug messages.
201 =head2 method chaining
203 One trick which is useful when doing method chaining is the following:
206 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
208 which is the same as:
211 (DwarnS $foo->bar->baz)->biff;
215 You probably want L<Devel::Dwarn>, it's the shorter name for this module.