Commit | Line | Data |
ce1f3e8e |
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 | |
e6746e64 |
10 | @EXPORT = qw(Dwarn DwarnS DwarnL); |
ce1f3e8e |
11 | |
e6746e64 |
12 | sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } |
13 | |
14 | sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ } |
ce1f3e8e |
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 | |
13b908a8 |
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 | } |
ce1f3e8e |
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 | |
13b908a8 |
56 | If you need to force list context on the value, |
01223632 |
57 | |
13b908a8 |
58 | use Data::Dumper::Concise::Sugar; |
01223632 |
59 | |
13b908a8 |
60 | return DwarnL some_call(...) |
01223632 |
61 | |
13b908a8 |
62 | is equivalent to: |
63 | |
64 | use Data::Dumper::Concise; |
65 | |
66 | my @return = some_call(...); |
67 | warn Dumper(@return); |
68 | return @return; |
01223632 |
69 | |
ce1f3e8e |
70 | =head1 DESCRIPTION |
71 | |
72 | use Data::Dumper::Concise::Sugar; |
73 | |
13b908a8 |
74 | will import Dwarn, DwarnL, and DwarnS into your namespace. Using L<Exporter>, so see |
ce1f3e8e |
75 | its docs for ways to make it do something else. |
76 | |
77 | =head2 Dwarn |
78 | |
13b908a8 |
79 | sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } |
80 | |
81 | =head2 DwarnL |
82 | |
ce1f3e8e |
83 | sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ } |
84 | |
13b908a8 |
85 | =head2 DwarnS |
ce1f3e8e |
86 | |
87 | sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } |
88 | |
13b908a8 |
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 | |
dc06d25b |
124 | =head1 SEE ALSO |
125 | |
126 | You probably want L<Devel::Dwarn>, it's the shorter name for this module. |
127 | |
128 | =cut |
ce1f3e8e |
129 | |
130 | 1; |