Commit | Line | Data |
ce1f3e8e |
1 | package Data::Dumper::Concise::Sugar; |
2 | |
3 | use 5.006; |
4 | |
5 | use Exporter (); |
6 | use Data::Dumper::Concise (); |
0deeb75f |
7 | use Devel::ArgNames; |
ce1f3e8e |
8 | |
9 | BEGIN { @ISA = qw(Exporter) } |
10 | |
0deeb75f |
11 | @EXPORT = qw(Dwarn DwarnS DwarnL DwarnN); |
ce1f3e8e |
12 | |
e6746e64 |
13 | sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } |
14 | |
15 | sub DwarnL { warn Data::Dumper::Concise::Dumper @_; @_ } |
ce1f3e8e |
16 | |
17 | sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } |
18 | |
0deeb75f |
19 | sub DwarnN ($) { |
20 | my $x = arg_names(); |
21 | warn(($x?$x:'(anon)') . ' => ' . Data::Dumper::Concise::Dumper $_[0]); $_[0] |
22 | } |
23 | |
ce1f3e8e |
24 | =head1 NAME |
25 | |
26 | Data::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 | |
34 | is 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 | |
48 | but 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 | |
54 | is equivalent to: |
55 | |
56 | use Data::Dumper::Concise; |
57 | |
58 | my $return = some_call(...); |
59 | warn Dumper($return); |
60 | return $return; |
61 | |
13b908a8 |
62 | If 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 |
68 | is equivalent to: |
69 | |
70 | use Data::Dumper::Concise; |
71 | |
72 | my @return = some_call(...); |
73 | warn Dumper(@return); |
74 | return @return; |
01223632 |
75 | |
ce1f3e8e |
76 | =head1 DESCRIPTION |
77 | |
78 | use Data::Dumper::Concise::Sugar; |
79 | |
13b908a8 |
80 | will import Dwarn, DwarnL, and DwarnS into your namespace. Using L<Exporter>, so see |
ce1f3e8e |
81 | its docs for ways to make it do something else. |
82 | |
83 | =head2 Dwarn |
84 | |
13b908a8 |
85 | sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) } |
86 | |
87 | =head2 DwarnL |
88 | |
ce1f3e8e |
89 | sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ } |
90 | |
13b908a8 |
91 | =head2 DwarnS |
ce1f3e8e |
92 | |
93 | sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] } |
94 | |
13b908a8 |
95 | =head1 TIPS AND TRICKS |
96 | |
97 | =head2 global usage |
98 | |
99 | Instead of always just doing: |
100 | |
101 | use Data::Dumper::Concise::Sugar; |
102 | |
103 | Dwarn ... |
104 | |
105 | We tend to do: |
106 | |
107 | perl -MData::Dumper::Concise::Sugar foo.pl |
108 | |
109 | (and then in the perl code:) |
110 | |
111 | ::Dwarn ... |
112 | |
113 | That way, if you leave them in and run without the |
114 | C<< use Data::Dumper::Concise::Sugar >> the program will fail to compile and |
115 | you are less likely to check it in by accident. Furthmore it allows that |
116 | much less friction to add debug messages. |
117 | |
118 | =head2 method chaining |
119 | |
120 | One trick which is useful when doing method chaining is the following: |
121 | |
122 | my $foo = Bar->new; |
123 | $foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff; |
124 | |
125 | which is the same as: |
126 | |
127 | my $foo = Bar->new; |
128 | (DwarnS $foo->bar->baz)->biff; |
129 | |
dc06d25b |
130 | =head1 SEE ALSO |
131 | |
132 | You probably want L<Devel::Dwarn>, it's the shorter name for this module. |
133 | |
134 | =cut |
ce1f3e8e |
135 | |
136 | 1; |