Add doc for DwarnN and release
[p5sagit/Data-Dumper-Concise.git] / lib / Data / Dumper / Concise / Sugar.pm
CommitLineData
ce1f3e8e 1package Data::Dumper::Concise::Sugar;
2
3use 5.006;
4
5use Exporter ();
6use Data::Dumper::Concise ();
0deeb75f 7use Devel::ArgNames;
ce1f3e8e 8
9BEGIN { @ISA = qw(Exporter) }
10
0deeb75f 11@EXPORT = qw(Dwarn DwarnS DwarnL DwarnN);
ce1f3e8e 12
e6746e64 13sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
14
15sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ }
ce1f3e8e 16
17sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
18
0deeb75f 19sub DwarnN ($) {
20 my $x = arg_names();
21 warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0]
22}
23
ce1f3e8e 24=head1 NAME
25
26Data::Dumper::Concise::Sugar - return Dwarn @return_value
27
28=head1 SYNOPSIS
29
30 use Data::Dumper::Concise::Sugar;
31
32 return Dwarn some_call(...)
33
34is equivalent to:
35
36 use Data::Dumper::Concise;
37
13b908a8 38 if (wantarray) {
39 my @return = some_call(...);
40 warn Dumper(@return);
41 return @return;
42 } else {
43 my $return = some_call(...);
44 warn Dumper($return);
45 return $return;
46 }
ce1f3e8e 47
48but shorter. If you need to force scalar context on the value,
49
50 use Data::Dumper::Concise::Sugar;
51
52 return DwarnS some_call(...)
53
54is equivalent to:
55
56 use Data::Dumper::Concise;
57
58 my $return = some_call(...);
59 warn Dumper($return);
60 return $return;
61
13b908a8 62If you need to force list context on the value,
01223632 63
13b908a8 64 use Data::Dumper::Concise::Sugar;
01223632 65
13b908a8 66 return DwarnL some_call(...)
01223632 67
13b908a8 68is equivalent to:
69
70 use Data::Dumper::Concise;
71
72 my @return = some_call(...);
73 warn Dumper(@return);
74 return @return;
01223632 75
9469b5b0 76If you want to label your output, try DwarnN
77
78 use Data::Dumper::Concise::Sugar;
79
80 return DwarnN $foo
81
82is equivalent to:
83
84 use Data::Dumper::Concise;
85
86 my @return = some_call(...);
87 warn '$foo => ' . Dumper(@return);
88 return @return;
89
ce1f3e8e 90=head1 DESCRIPTION
91
92 use Data::Dumper::Concise::Sugar;
93
9469b5b0 94will import Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using
95L<Exporter>, so see its docs for ways to make it do something else.
ce1f3e8e 96
97=head2 Dwarn
98
13b908a8 99 sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
100
101=head2 DwarnL
102
ce1f3e8e 103 sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
104
13b908a8 105=head2 DwarnS
ce1f3e8e 106
107 sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
108
9469b5b0 109=head2 DwarnN
110
111 sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
112
13b908a8 113=head1 TIPS AND TRICKS
114
115=head2 global usage
116
117Instead of always just doing:
118
119 use Data::Dumper::Concise::Sugar;
120
121 Dwarn ...
122
123We tend to do:
124
125 perl -MData::Dumper::Concise::Sugar foo.pl
126
127(and then in the perl code:)
128
129 ::Dwarn ...
130
131That way, if you leave them in and run without the
132C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and
133you are less likely to check it in by accident. Furthmore it allows that
134much less friction to add debug messages.
135
136=head2 method chaining
137
138One trick which is useful when doing method chaining is the following:
139
140 my $foo = Bar->new;
141 $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
142
143which is the same as:
144
145 my $foo = Bar->new;
146 (DwarnS $foo->bar->baz)->biff;
147
dc06d25b 148=head1 SEE ALSO
149
150You probably want L<Devel::Dwarn>, it's the shorter name for this module.
151
152=cut
ce1f3e8e 153
1541;