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