line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::Dwarn; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18832
|
use Data::Dumper::Concise::Sugar; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
292
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub import { |
6
|
1
|
|
|
1
|
|
166
|
Data::Dumper::Concise::Sugar->export_to_level(1, @_); |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Devel::Dwarn - return Dwarn @return_value |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Devel::Dwarn; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
return Dwarn some_call(...) |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
is equivalent to: |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Data::Dumper::Concise; |
22
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
but shorter. If you need to force scalar context on the value, |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Devel::Dwarn; |
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
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
If you need to force list context on the value, |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Devel::Dwarn; |
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
If you want to output a reference returned by a method easily, try $Dwarn |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$foo->bar->{baz}->$Dwarn |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
is equivalent to: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $return = $foo->bar->{baz}; |
82
|
|
|
|
|
|
|
warn Dumper($return); |
83
|
|
|
|
|
|
|
return $return; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
If you want to immediately die after outputting the data structure, every |
86
|
|
|
|
|
|
|
Dwarn subroutine has a paired Ddie version, so just replace the warn with die. |
87
|
|
|
|
|
|
|
For example: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
DdieL 'foo', { bar => 'baz' }; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 TIPS AND TRICKS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 global usage |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Instead of always just doing: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Devel::Dwarn; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Dwarn ... |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
We tend to do: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
perl -MDevel::Dwarn foo.pl |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
(and then in the perl code:) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
::Dwarn ... |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
That way, if you leave them in and run without the C<< use Devel::Dwarn >> |
110
|
|
|
|
|
|
|
the program will fail to compile and you are less likely to check it in by |
111
|
|
|
|
|
|
|
accident. Furthmore it allows that much less friction to add debug messages. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 method chaining |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
One trick which is useful when doing method chaining is the following: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $foo = Bar->new; |
118
|
|
|
|
|
|
|
$foo->bar->baz->Devel::Dwarn::DwarnS->biff; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
which is the same as: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $foo = Bar->new; |
123
|
|
|
|
|
|
|
(DwarnS $foo->bar->baz)->biff; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This module is really just a shortcut for L, check |
128
|
|
|
|
|
|
|
it out for more complete documentation. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |