Commit | Line | Data |
60e18490 |
1 | package Devel::Dwarn; |
2 | |
2570b7be |
3 | use Data::Dumper::Concise::Sugar; |
60e18490 |
4 | |
d71b0a31 |
5 | sub import { |
6 | Data::Dumper::Concise::Sugar->export_to_level(1, @_); |
7 | } |
60e18490 |
8 | |
dc06d25b |
9 | =head1 NAME |
10 | |
11 | Devel::Dwarn - return Dwarn @return_value |
12 | |
13 | =head1 SYNOPSIS |
9469b5b0 |
14 | |
15 | use Devel::Dwarn; |
dc06d25b |
16 | |
17 | return Dwarn some_call(...) |
18 | |
19 | is equivalent to: |
20 | |
21 | use Data::Dumper::Concise; |
22 | |
13b908a8 |
23 | if (wantarray) { |
24 | my @return = some_call(...); |
25 | warn Dumper(@return); |
26 | return @return; |
27 | } else { |
28 | my $return = some_call(...); |
29 | warn Dumper($return); |
30 | return $return; |
31 | } |
dc06d25b |
32 | |
33 | but shorter. If you need to force scalar context on the value, |
34 | |
9469b5b0 |
35 | use Devel::Dwarn; |
dc06d25b |
36 | |
37 | return DwarnS some_call(...) |
38 | |
39 | is equivalent to: |
40 | |
41 | use Data::Dumper::Concise; |
42 | |
43 | my $return = some_call(...); |
44 | warn Dumper($return); |
45 | return $return; |
46 | |
13b908a8 |
47 | If you need to force list context on the value, |
48 | |
9469b5b0 |
49 | use Devel::Dwarn; |
13b908a8 |
50 | |
51 | return DwarnL some_call(...) |
52 | |
53 | is equivalent to: |
54 | |
55 | use Data::Dumper::Concise; |
56 | |
57 | my @return = some_call(...); |
58 | warn Dumper(@return); |
59 | return @return; |
60 | |
9469b5b0 |
61 | If you want to label your output, try DwarnN |
62 | |
63 | use Devel::Dwarn; |
64 | |
65 | return DwarnN $foo |
66 | |
67 | is equivalent to: |
68 | |
69 | use Data::Dumper::Concise; |
70 | |
71 | my @return = some_call(...); |
72 | warn '$foo => ' . Dumper(@return); |
73 | return @return; |
74 | |
13b908a8 |
75 | =head1 TIPS AND TRICKS |
76 | |
77 | =head2 global usage |
78 | |
79 | Instead of always just doing: |
80 | |
81 | use Devel::Dwarn; |
82 | |
83 | Dwarn ... |
84 | |
85 | We tend to do: |
86 | |
87 | perl -MDevel::Dwarn foo.pl |
88 | |
89 | (and then in the perl code:) |
90 | |
91 | ::Dwarn ... |
92 | |
93 | That way, if you leave them in and run without the C<< use Devel::Dwarn >> |
94 | the program will fail to compile and you are less likely to check it in by |
95 | accident. Furthmore it allows that much less friction to add debug messages. |
96 | |
97 | =head2 method chaining |
98 | |
99 | One trick which is useful when doing method chaining is the following: |
01223632 |
100 | |
101 | my $foo = Bar->new; |
102 | $foo->bar->baz->Devel::Dwarn::DwarnS->biff; |
103 | |
104 | which is the same as: |
105 | |
106 | my $foo = Bar->new; |
107 | (DwarnS $foo->bar->baz)->biff; |
108 | |
dc06d25b |
109 | =head1 SEE ALSO |
110 | |
111 | This module is really just a shortcut for L<Data::Dumper::Concise::Sugar>, check |
112 | it out for more complete documentation. |
113 | |
114 | =cut |
115 | |
60e18490 |
116 | 1; |