line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Trace; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
65445
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
116
|
|
4
|
5
|
|
|
5
|
|
14
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
93
|
|
5
|
5
|
|
|
5
|
|
2464
|
use PadWalker (); |
|
5
|
|
|
|
|
2477
|
|
|
5
|
|
|
|
|
91
|
|
6
|
5
|
|
|
5
|
|
1751
|
use Tie::Hash (); |
|
5
|
|
|
|
|
2695
|
|
|
5
|
|
|
|
|
71
|
|
7
|
5
|
|
|
5
|
|
2007
|
use Tie::Array (); |
|
5
|
|
|
|
|
3985
|
|
|
5
|
|
|
|
|
83
|
|
8
|
5
|
|
|
5
|
|
2023
|
use Tie::Scalar (); |
|
5
|
|
|
|
|
1855
|
|
|
5
|
|
|
|
|
71
|
|
9
|
5
|
|
|
5
|
|
18
|
use Carp (); |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
49
|
|
10
|
5
|
|
|
5
|
|
1489
|
use Data::Dumper (); |
|
5
|
|
|
|
|
16697
|
|
|
5
|
|
|
|
|
92
|
|
11
|
5
|
|
|
5
|
|
19
|
use base qw/Exporter/; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
351
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant { |
14
|
5
|
|
|
|
|
8259
|
SCALAR => 0, |
15
|
|
|
|
|
|
|
SCALARREF => 1, |
16
|
|
|
|
|
|
|
ARRAYREF => 2, |
17
|
|
|
|
|
|
|
HASHREF => 4, |
18
|
|
|
|
|
|
|
BLESSED => 8, |
19
|
|
|
|
|
|
|
TIED => 16, |
20
|
5
|
|
|
5
|
|
128
|
}; |
|
5
|
|
|
|
|
5
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ('watch'); |
23
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our %OPTIONS = (debug => 'dumper'); |
26
|
|
|
|
|
|
|
our $QUIET = 0; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $AUTOLOAD; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub AUTOLOAD{ |
31
|
|
|
|
|
|
|
# proxy to Tie::Std*** |
32
|
102
|
|
|
102
|
|
14576
|
my($self, @args) = @_; |
33
|
102
|
|
|
|
|
208
|
my($class, $method) = (split /::/, $AUTOLOAD)[2, 3]; |
34
|
102
|
|
|
|
|
81
|
my $sub = \&{'Tie::Std' . $class . '::' . $method}; |
|
102
|
|
|
|
|
231
|
|
35
|
102
|
100
|
|
|
|
242
|
defined &$sub ? $sub->($self->{storage}, @args) : return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
19
|
|
657
|
sub TIEHASH { Tie::Trace::_tieit({}, @_); } |
39
|
6
|
|
|
6
|
|
12
|
sub TIEARRAY { Tie::Trace::_tieit([], @_); } |
40
|
6
|
|
|
6
|
|
6
|
sub TIESCALAR{ my $tmp; Tie::Trace::_tieit(\$tmp, @_); } |
|
6
|
|
|
|
|
10
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub watch(\[$@%]@){ |
43
|
7
|
|
|
7
|
1
|
5113
|
my $s = shift; |
44
|
7
|
|
|
|
|
13
|
my $s_type = ref $s; |
45
|
7
|
|
|
|
|
12
|
my $s_ = $s; |
46
|
|
|
|
|
|
|
|
47
|
7
|
50
|
|
|
|
41
|
if($s_type eq 'SCALAR'){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$s_ = $$s; |
49
|
|
|
|
|
|
|
}elsif($s_type eq 'ARRAY'){ |
50
|
1
|
|
|
|
|
3
|
$s_ = [ @$s ]; |
51
|
|
|
|
|
|
|
}elsif($s_type eq 'HASH'){ |
52
|
6
|
|
|
|
|
15
|
$s_ = { %$s }; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
7
|
50
|
|
|
|
16
|
Carp::croak("must pass one argument.") unless $s; |
56
|
7
|
|
|
|
|
15
|
my @options = @_; |
57
|
7
|
|
|
|
|
7
|
my $var_name; |
58
|
7
|
|
|
|
|
10
|
eval{ |
59
|
7
|
|
|
|
|
38
|
$var_name = PadWalker::var_name(1, $s); |
60
|
|
|
|
|
|
|
}; |
61
|
7
|
50
|
|
|
|
25
|
my $pkg = defined $var_name ? (caller)[0] : undef; |
62
|
7
|
100
|
|
|
|
49
|
my $tied_value = tie $s_type eq 'SCALAR' ? $$s : $s_type eq 'ARRAY' ? @$s : %$s, "Tie::Trace", var => $var_name, pkg => $pkg, @options; |
|
|
50
|
|
|
|
|
|
63
|
7
|
|
|
|
|
10
|
local $QUIET = 1; |
64
|
|
|
|
|
|
|
|
65
|
7
|
50
|
|
|
|
30
|
if($s_type eq 'SCALAR'){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
$$s = $s_; |
67
|
|
|
|
|
|
|
}elsif($s_type eq 'ARRAY'){ |
68
|
1
|
50
|
|
|
|
4
|
@$s = @$s_ if @$s_; |
69
|
|
|
|
|
|
|
}elsif($s_type eq 'HASH'){ |
70
|
6
|
50
|
|
|
|
14
|
%$s = %$s_ if %$s_; |
71
|
|
|
|
|
|
|
} |
72
|
7
|
|
|
|
|
17
|
return $tied_value; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _dumper{ |
76
|
47
|
|
|
47
|
|
42
|
my($self, $value) = @_; |
77
|
47
|
|
|
|
|
45
|
local $Data::Dumper::Terse = 1; |
78
|
47
|
|
|
|
|
42
|
local $Data::Dumper::Indent = 0; |
79
|
47
|
|
|
|
|
45
|
local $Data::Dumper::Deparse = 1; |
80
|
47
|
|
|
|
|
105
|
$value = Data::Dumper::Dumper($value); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub storage{ |
84
|
0
|
|
|
0
|
1
|
0
|
my($self) = @_; |
85
|
0
|
|
|
|
|
0
|
return $self->{storage}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub parent{ |
89
|
95
|
|
|
95
|
1
|
75
|
my($self) = @_; |
90
|
95
|
|
|
|
|
151
|
return $self->{parent}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _match{ |
94
|
52
|
|
|
52
|
|
48
|
my($self, $test, $value) = @_; |
95
|
52
|
100
|
|
|
|
84
|
if(ref $test eq 'Regexp'){ |
|
|
50
|
|
|
|
|
|
96
|
7
|
|
|
|
|
35
|
return $value =~ $_; |
97
|
|
|
|
|
|
|
}elsif(ref $test eq 'CODE'){ |
98
|
0
|
|
|
|
|
0
|
return $test->($self, $value); |
99
|
|
|
|
|
|
|
}else{ |
100
|
45
|
|
|
|
|
115
|
return $test eq $value; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
0
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _matching{ |
106
|
107
|
|
|
107
|
|
157
|
my($self, $test, $tested) = @_; |
107
|
107
|
100
|
|
|
|
225
|
return 1 unless $test; |
108
|
29
|
100
|
|
|
|
47
|
if($tested){ |
109
|
28
|
100
|
|
|
|
52
|
return 1 if grep $self->_match($_, $tested), @$test; |
110
|
|
|
|
|
|
|
} |
111
|
10
|
|
|
|
|
18
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _carpit{ |
115
|
66
|
|
|
66
|
|
325
|
my($self, %args) = @_; |
116
|
66
|
50
|
|
|
|
97
|
return if $QUIET; |
117
|
|
|
|
|
|
|
|
118
|
66
|
|
|
|
|
150
|
my $class = (split /::/, ref $self)[2]; |
119
|
66
|
|
50
|
|
|
137
|
my $op = $self->{options} || {}; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# key/value checking |
122
|
66
|
100
|
66
|
|
|
187
|
if($op->{key} or $op->{value}){ |
123
|
20
|
|
|
|
|
78
|
my $key = $self->_matching($self->{options}->{key}, $args{key}); |
124
|
20
|
|
|
|
|
38
|
my $value = $self->_matching($self->{options}->{value}, $args{value}); |
125
|
20
|
50
|
33
|
|
|
114
|
if(($args{key} and $op->{key}) and $op->{value}){ |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
126
|
0
|
0
|
0
|
|
|
0
|
return unless $key or $value; |
127
|
|
|
|
|
|
|
}elsif($args{key} and $op->{key}){ |
128
|
6
|
100
|
|
|
|
11
|
return unless $key; |
129
|
|
|
|
|
|
|
}elsif($op->{value}){ |
130
|
14
|
100
|
|
|
|
27
|
return unless $value; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# debug type |
135
|
58
|
|
|
|
|
142
|
my $value = $self->_debug_message($args{value}, $op->{debug}, $args{filter}); |
136
|
|
|
|
|
|
|
# debug_value checking |
137
|
58
|
50
|
|
|
|
169
|
return unless $self->_matching($self->{options}->{debug_value}, $value); |
138
|
|
|
|
|
|
|
# use scalar/array/hash ? |
139
|
58
|
50
|
|
|
|
55
|
return unless grep lc($class) eq lc($_) , @{$op->{use}}; |
|
58
|
|
|
|
|
196
|
|
140
|
|
|
|
|
|
|
# create warning message |
141
|
58
|
|
|
|
|
51
|
my $watch_msg = ''; |
142
|
58
|
|
|
|
|
98
|
my $msg = $self->_output_message($class, $value, \%args); |
143
|
58
|
100
|
|
|
|
88
|
if(defined $self->{options}->{pkg}){ |
144
|
56
|
|
|
|
|
39
|
$watch_msg = sprintf("%s:: %s", @{$self->{options}}{qw/pkg var/}); |
|
56
|
|
|
|
|
161
|
|
145
|
|
|
|
|
|
|
}else{ |
146
|
2
|
|
|
|
|
3
|
$msg =~ s/^ => //; |
147
|
|
|
|
|
|
|
} |
148
|
58
|
|
|
|
|
248
|
warn $watch_msg . $msg . "\n"; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _output_message{ |
152
|
58
|
|
|
58
|
|
62
|
my($self, $class, $value, $args) = @_; |
153
|
58
|
|
|
|
|
65
|
my($msg, @msg) = (''); |
154
|
|
|
|
|
|
|
|
155
|
58
|
|
|
|
|
52
|
my $caller = $self->{options}->{caller}; |
156
|
58
|
|
|
|
|
42
|
my $_caller_n = 1; |
157
|
58
|
|
|
|
|
281
|
while (my $c = (caller $_caller_n)[0]) { |
158
|
124
|
50
|
|
|
|
312
|
if (not $c) { |
|
|
100
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
last; |
160
|
|
|
|
|
|
|
} elsif ($c !~ /^Tie::Trace/) { |
161
|
58
|
|
|
|
|
68
|
last; |
162
|
|
|
|
|
|
|
} |
163
|
66
|
|
|
|
|
211
|
$_caller_n++; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
58
|
50
|
|
|
|
153
|
my @caller = map $_ + $_caller_n, ref $caller ? @{$caller} : $caller; |
|
0
|
|
|
|
|
0
|
|
167
|
58
|
|
|
|
|
83
|
my(@filename, @line); |
168
|
58
|
|
|
|
|
68
|
foreach(@caller){ |
169
|
58
|
|
|
|
|
130
|
my($f, $l) = (caller($_))[1, 2]; |
170
|
58
|
50
|
33
|
|
|
215
|
next unless $f and $l; |
171
|
|
|
|
|
|
|
|
172
|
58
|
|
|
|
|
45
|
push @filename, $f; |
173
|
58
|
|
|
|
|
77
|
push @line, $l; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
58
|
50
|
|
|
|
137
|
my $location = @line == 1 ? " at $filename[0] line $line[0]." : |
178
|
|
|
|
|
|
|
join "\n", map " at $filename[$_] line $line[$_].", (0 .. $#filename); |
179
|
58
|
|
|
|
|
98
|
my($_p, $p) = ($self, $self->parent); |
180
|
58
|
|
|
|
|
98
|
while($p){ |
181
|
36
|
|
|
|
|
44
|
my $s_type = ref $p->{storage}; |
182
|
36
|
|
|
|
|
25
|
my $s = $p->{storage}; |
183
|
36
|
100
|
|
|
|
47
|
if($s_type eq 'HASH'){ |
|
|
50
|
|
|
|
|
|
184
|
35
|
|
|
|
|
54
|
push @msg, "{$_p->{__key}}"; |
185
|
|
|
|
|
|
|
}elsif($s_type eq 'ARRAY'){ |
186
|
1
|
|
|
|
|
2
|
push @msg, "[$_p->{__point}]"; |
187
|
|
|
|
|
|
|
} |
188
|
36
|
|
|
|
|
29
|
$_p = $p; |
189
|
36
|
100
|
33
|
|
|
77
|
last if ! ref $p or ! ($p = $p->parent); |
190
|
|
|
|
|
|
|
} |
191
|
58
|
100
|
|
|
|
105
|
$msg = @msg > 0 ? ' => ' . join "", reverse @msg : ""; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
58
|
50
|
|
|
|
80
|
$value = '' unless defined $value; |
195
|
58
|
100
|
|
|
|
154
|
if ($class eq 'Scalar') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
196
|
2
|
|
|
|
|
7
|
return("${msg} => $value$location"); |
197
|
|
|
|
|
|
|
} elsif ($class eq 'Array') { |
198
|
19
|
100
|
|
|
|
33
|
unless(defined $args->{point}){ |
199
|
4
|
|
|
|
|
28
|
$msg =~ s/^( => )(.+)$/$1\@\{$2\}/; |
200
|
4
|
|
|
|
|
17
|
return("$msg => $value$location"); |
201
|
|
|
|
|
|
|
}else{ |
202
|
15
|
|
|
|
|
84
|
return("${msg}[$args->{point}] => $value$location"); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} elsif ($class eq 'Hash') { |
205
|
37
|
100
|
100
|
|
|
226
|
return("${msg}" . (! $self->{options}->{pkg} || @msg ? "" : " => "). "{$args->{key}} => $value$location"); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _debug_message{ |
210
|
58
|
|
|
58
|
|
73
|
my($self, $value, $debug, $filter) = @_; |
211
|
|
|
|
|
|
|
|
212
|
58
|
50
|
|
|
|
250
|
if(ref $debug eq 'CODE'){ |
|
|
100
|
|
|
|
|
|
213
|
0
|
|
|
|
|
0
|
$value = $debug->($self, $value); |
214
|
|
|
|
|
|
|
}elsif(lc($debug) eq 'dumper'){ |
215
|
43
|
|
|
|
|
64
|
$value = $self->_dumper($value); |
216
|
43
|
100
|
|
|
|
4075
|
if(defined $filter){ |
217
|
8
|
|
|
|
|
14
|
$filter->($value); |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
58
|
|
|
|
|
91
|
return $value; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _tieit { |
224
|
31
|
|
|
31
|
|
63
|
my($self, $class, %arg) = @_; |
225
|
31
|
|
|
|
|
62
|
foreach (keys %OPTIONS){ |
226
|
31
|
100
|
|
|
|
89
|
$arg{$_} = $OPTIONS{$_} if not exists $arg{$_}; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
31
|
100
|
|
|
|
76
|
if($class =~/^Tie::Trace$/){ |
230
|
9
|
|
|
|
|
18
|
my $type = lc(ref $self); |
231
|
9
|
|
|
|
|
23
|
substr($type, 0, 1) = uc(substr($type, 0, 1)); |
232
|
9
|
|
|
|
|
20
|
$class .= '::' . $type; |
233
|
|
|
|
|
|
|
} |
234
|
31
|
|
|
|
|
29
|
my $parent = $arg{parent}; |
235
|
31
|
|
|
|
|
24
|
my $options; |
236
|
31
|
100
|
66
|
|
|
85
|
if(defined $parent and $parent){ |
237
|
22
|
|
|
|
|
27
|
$options = $parent->{options}; |
238
|
|
|
|
|
|
|
}else{ |
239
|
9
|
|
|
|
|
14
|
$options = \%arg; |
240
|
9
|
50
|
|
|
|
20
|
unless($options->{use}){ |
241
|
9
|
|
|
|
|
18
|
$options->{use} = [qw/scalar array hash/]; |
242
|
|
|
|
|
|
|
} |
243
|
9
|
100
|
|
|
|
18
|
unless(defined $options->{r}){ |
244
|
5
|
|
|
|
|
7
|
$options->{r} = 1; |
245
|
|
|
|
|
|
|
} |
246
|
9
|
|
50
|
|
|
44
|
$options->{caller} ||= 0; |
247
|
|
|
|
|
|
|
} |
248
|
31
|
|
|
|
|
59
|
my $_self = |
249
|
|
|
|
|
|
|
{ |
250
|
|
|
|
|
|
|
self => $self, |
251
|
|
|
|
|
|
|
parent => $parent, |
252
|
|
|
|
|
|
|
options => $options, |
253
|
|
|
|
|
|
|
}; |
254
|
31
|
100
|
|
|
|
69
|
$_self->{__key} = delete $arg{__key} if exists $arg{__key}; |
255
|
31
|
100
|
|
|
|
46
|
$_self->{__point} = delete $arg{__point} if exists $arg{__point}; |
256
|
31
|
|
|
|
|
37
|
bless $_self, $class; |
257
|
31
|
|
|
|
|
103
|
return $_self; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub _data_filter{ |
261
|
160
|
|
|
160
|
|
140
|
my($structure, $self, $parent_info) = @_; |
262
|
160
|
100
|
|
|
|
236
|
return $structure unless $self->{options}->{r}; |
263
|
153
|
|
100
|
|
|
200
|
$parent_info ||= {}; |
264
|
|
|
|
|
|
|
|
265
|
153
|
|
|
|
|
119
|
my $ref = ref $structure; |
266
|
153
|
|
|
|
|
248
|
my %test = (SCALARREF() => 'SCALAR', ARRAYREF() => 'ARRAY', HASHREF() => 'HASH'); |
267
|
153
|
|
|
|
|
105
|
my $type = 0; |
268
|
153
|
|
|
|
|
99
|
my($class, $tied); |
269
|
153
|
50
|
|
|
|
190
|
if(defined $ref){ |
270
|
153
|
|
|
|
|
226
|
foreach my $i (keys %test){ |
271
|
433
|
100
|
100
|
|
|
2968
|
if($ref eq $test{$i}){ |
|
|
100
|
|
|
|
|
|
272
|
22
|
|
|
|
|
19
|
$type = $i; |
273
|
22
|
|
|
|
|
39
|
last; |
274
|
|
|
|
|
|
|
}elsif(defined $structure and $structure =~/=$test{$i}/){ |
275
|
2
|
50
|
|
|
|
10
|
$tied = tied($i == SCALARREF ? $$structure : $i == ARRAYREF ? @$structure : $structure); |
|
|
50
|
|
|
|
|
|
276
|
2
|
50
|
|
|
|
7
|
$type = $i | BLESSED | ($tied ? TIED : 0); |
277
|
2
|
|
|
|
|
3
|
$class = $ref; |
278
|
2
|
|
|
|
|
2
|
last; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
} |
282
|
153
|
100
|
66
|
|
|
438
|
unless($class or $tied){ |
283
|
151
|
100
|
|
|
|
343
|
if(($type & 0b11001) == SCALARREF){ |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
284
|
6
|
|
|
|
|
27
|
my $tmp = $$structure; |
285
|
6
|
|
|
|
|
33
|
tie $$structure, "Tie::Trace::Scalar", parent => $self, %$parent_info; |
286
|
6
|
|
|
|
|
13
|
$$structure = Tie::Trace::_data_filter($tmp, $self); |
287
|
6
|
|
|
|
|
26
|
return $structure; |
288
|
|
|
|
|
|
|
}elsif(($type & 0b11010) == ARRAYREF){ |
289
|
5
|
|
|
|
|
15
|
my @tmp = @$structure; |
290
|
5
|
|
|
|
|
31
|
tie @$structure, "Tie::Trace::Array", parent => $self, %$parent_info; |
291
|
5
|
|
|
|
|
13
|
foreach my $i (0 .. $#tmp){ |
292
|
23
|
|
|
|
|
42
|
$structure->[$i] = Tie::Trace::_data_filter($tmp[$i], $self, {__point => $i}); |
293
|
|
|
|
|
|
|
} |
294
|
5
|
|
|
|
|
16
|
return $structure; |
295
|
|
|
|
|
|
|
}elsif(($type & 0b11100) == HASHREF){ |
296
|
11
|
|
|
|
|
25
|
my %tmp = %$structure; |
297
|
11
|
|
|
|
|
54
|
tie %$structure, "Tie::Trace::Hash", parent => $self, %$parent_info;; |
298
|
11
|
|
|
|
|
31
|
while(my($k, $v) = each %tmp){ |
299
|
8
|
|
|
|
|
26
|
$structure->{$k} = Tie::Trace::_data_filter($v, $self, {__key => $k}); |
300
|
|
|
|
|
|
|
} |
301
|
11
|
|
|
|
|
20
|
return $structure; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
# tied variable / blessed ref / just a scalar |
305
|
131
|
|
|
|
|
232
|
return $structure; |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# Hash ///////////////////////// |
309
|
|
|
|
|
|
|
package |
310
|
|
|
|
|
|
|
Tie::Trace::Hash; |
311
|
|
|
|
|
|
|
|
312
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
132
|
|
313
|
5
|
|
|
5
|
|
18
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
83
|
|
314
|
|
|
|
|
|
|
|
315
|
5
|
|
|
5
|
|
15
|
use base qw/Tie::Trace/; |
|
5
|
|
|
|
|
1
|
|
|
5
|
|
|
|
|
1051
|
|
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub STORE{ |
318
|
52
|
|
|
52
|
|
12770
|
my($self, $key, $value) = @_; |
319
|
52
|
100
|
|
|
|
136
|
$self->_carpit(key => $key, value => $value) unless $QUIET; |
320
|
52
|
|
|
|
|
66
|
local $QUIET = 1; |
321
|
52
|
|
|
|
|
112
|
Tie::Trace::_data_filter($value, $self, {__key => $key}); |
322
|
52
|
|
|
|
|
237
|
$self->{storage}->{$key} = $value; |
323
|
|
|
|
|
|
|
}; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub DELETE { |
326
|
2
|
|
|
2
|
|
367
|
my($self, $key) = @_; |
327
|
2
|
|
|
|
|
5
|
my $deleted = delete $self->{storage}->{$key}; |
328
|
|
|
|
|
|
|
$self->_carpit(key => $key, |
329
|
|
|
|
|
|
|
value => sprintf("DELETED(%s)", $self->_dumper(defined $deleted ? $deleted : 'undef')), |
330
|
0
|
|
|
0
|
|
0
|
filter => sub{$_[0] =~ s/^\'(.+)\'$/$1/; $_[0] =~s /\\'/'/g} |
|
0
|
|
|
|
|
0
|
|
331
|
2
|
100
|
|
|
|
17
|
) unless $QUIET; |
|
|
50
|
|
|
|
|
|
332
|
2
|
|
|
|
|
11
|
return $deleted; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub CLEAR{ |
336
|
0
|
|
|
0
|
|
0
|
my($self) = @_; |
337
|
0
|
|
|
|
|
0
|
return $self->Tie::Hash::CLEAR; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
# Array ///////////////////////// |
341
|
|
|
|
|
|
|
package |
342
|
|
|
|
|
|
|
Tie::Trace::Array; |
343
|
|
|
|
|
|
|
|
344
|
5
|
|
|
5
|
|
278
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
126
|
|
345
|
5
|
|
|
5
|
|
15
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
91
|
|
346
|
|
|
|
|
|
|
|
347
|
5
|
|
|
5
|
|
15
|
use base qw/Tie::Trace/; |
|
5
|
|
|
|
|
3
|
|
|
5
|
|
|
|
|
2731
|
|
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub STORE{ |
350
|
32
|
|
|
32
|
|
447
|
my($self, $p, $value) = @_; |
351
|
32
|
100
|
|
|
|
52
|
$self->_carpit(point => $p, value => $value) unless $QUIET; |
352
|
32
|
|
|
|
|
33
|
local $QUIET = 1; |
353
|
32
|
|
|
|
|
74
|
Tie::Trace::_data_filter($value, $self, {__point => $p}); |
354
|
32
|
|
|
|
|
119
|
$self->{storage}->[$p] = $value; |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub DELETE{ |
358
|
1
|
|
|
1
|
|
6
|
my($self, $p) = @_; |
359
|
1
|
|
|
|
|
2
|
my $deleted = delete ${$self->{storage}}[$p]; |
|
1
|
|
|
|
|
2
|
|
360
|
|
|
|
|
|
|
$self->_carpit(point => $p, |
361
|
|
|
|
|
|
|
value => sprintf("DELETED(%s)", $self->_dumper(defined $deleted ? $deleted : "undef")), |
362
|
1
|
|
|
1
|
|
7
|
filter => sub{$_[0] =~ s/^\'(.*)\'$/$1/; $_[0] =~s /\\'/'/g} |
|
1
|
|
|
|
|
3
|
|
363
|
1
|
50
|
|
|
|
6
|
) unless $QUIET; |
|
|
50
|
|
|
|
|
|
364
|
1
|
|
|
|
|
8
|
return $deleted; |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub SPLICE{ |
368
|
9
|
|
|
9
|
|
15
|
my $self = shift; |
369
|
9
|
|
|
|
|
7
|
my $sz = @{$self->{storage}}; |
|
9
|
|
|
|
|
12
|
|
370
|
9
|
50
|
|
|
|
17
|
my $off = @_ ? shift : 0; |
371
|
9
|
|
|
|
|
13
|
my $fetchsize = $self->FETCHSIZE; |
372
|
9
|
|
|
|
|
17
|
my $caller_pkg = (caller)[0]; |
373
|
9
|
|
|
|
|
10
|
my $func = ""; |
374
|
9
|
100
|
|
|
|
20
|
if($caller_pkg eq "Tie::Trace::Array"){ |
375
|
8
|
|
|
|
|
21
|
$func = (caller 1)[3]; |
376
|
8
|
|
|
|
|
30
|
$func =~s/^Tie::Trace::Array:://; |
377
|
|
|
|
|
|
|
} |
378
|
9
|
50
|
|
|
|
16
|
$off += $sz if $off < 0; |
379
|
9
|
50
|
|
|
|
16
|
my $len = @_ ? shift : $sz - $off; |
380
|
9
|
|
|
|
|
11
|
my $to = $off + $len -1; |
381
|
9
|
100
|
|
|
|
24
|
my $p = $off eq $to ? $off : $off < $to ? "$off .. $to" : $off; |
|
|
100
|
|
|
|
|
|
382
|
9
|
100
|
100
|
|
|
38
|
my @point = ($func and $func ne 'STORESIZE') ? () : (point => $p); |
383
|
9
|
50
|
|
7
|
|
79
|
$self->_carpit(@point, value => \@_, filter => sub {$_[0] =~ s/^\[(.*)\]$/$func\($1\)/} ) unless $QUIET; |
|
7
|
|
|
|
|
52
|
|
384
|
9
|
|
|
|
|
25
|
local $QUIET = 1; |
385
|
9
|
100
|
|
|
|
18
|
if(@_){ |
386
|
5
|
|
|
|
|
5
|
my $cnt = 0; |
387
|
5
|
|
|
|
|
8
|
foreach(@_){ |
388
|
5
|
|
|
|
|
17
|
Tie::Trace::_data_filter($_, $self, {__point => $off + $cnt++}); |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
} |
391
|
9
|
|
|
|
|
11
|
my $ret = splice(@{$self->{storage}}, $off, $len, @_); |
|
9
|
|
|
|
|
24
|
|
392
|
9
|
100
|
|
|
|
33
|
if(@_ != $len){ |
393
|
6
|
|
|
|
|
7
|
my $diff = scalar @_ - $len; |
394
|
6
|
|
|
|
|
7
|
local $QUIET = 1; |
395
|
6
|
|
|
|
|
7
|
for(my $i = 0;$i < @{$self->{storage}}; $i++){ |
|
32
|
|
|
|
|
57
|
|
396
|
26
|
|
|
|
|
22
|
my $value = $self->{storage}->[$i]; |
397
|
26
|
|
|
|
|
38
|
Tie::Trace::_data_filter($value, $self, {__point => $i}); |
398
|
26
|
|
|
|
|
39
|
$self->{storage}->[$i] = $value; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
} |
401
|
9
|
|
|
|
|
22
|
return $ret; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
sub FETCHSIZE{ |
405
|
28
|
|
|
28
|
|
269
|
my($self) = shift; |
406
|
28
|
|
100
|
|
|
23
|
return scalar @{$self->{storage} ||= []}; |
|
28
|
|
|
|
|
105
|
|
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
sub PUSH{ |
410
|
4
|
|
|
4
|
|
22
|
my($self, @value) = @_; |
411
|
4
|
|
|
|
|
10
|
return $self->SPLICE($self->FETCHSIZE, 0, @value); |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
sub UNSHIFT{ |
415
|
0
|
|
|
0
|
|
0
|
my($self, @value) = @_; |
416
|
0
|
|
|
|
|
0
|
return $self->SPLICE(0, 0, @value); |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
sub POP{ |
420
|
0
|
|
|
0
|
|
0
|
my($self) = @_; |
421
|
0
|
|
|
|
|
0
|
return $self->SPLICE(-1); |
422
|
|
|
|
|
|
|
} |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub SHIFT{ |
425
|
0
|
|
|
0
|
|
0
|
my($self) = @_; |
426
|
0
|
|
|
|
|
0
|
return $self->SPLICE(0, 1); |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
sub STORESIZE { |
430
|
4
|
|
|
4
|
|
1510
|
my ($self, $p) = @_; |
431
|
4
|
|
|
|
|
8
|
$self->SPLICE($p, $self->FETCHSIZE - $p); |
432
|
4
|
|
|
|
|
22
|
return undef; |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
sub CLEAR{ |
436
|
3
|
|
|
3
|
|
1472
|
my($self) = @_; |
437
|
3
|
|
|
|
|
15
|
return $self->Tie::Array::CLEAR(); |
438
|
0
|
|
|
|
|
0
|
$self->DELETE($_) for 0 .. $#{$self->{storage}}; |
|
0
|
|
|
|
|
0
|
|
439
|
0
|
|
|
|
|
0
|
return undef; |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
# Scalar ///////////////////////// |
443
|
|
|
|
|
|
|
package |
444
|
|
|
|
|
|
|
Tie::Trace::Scalar; |
445
|
|
|
|
|
|
|
|
446
|
5
|
|
|
5
|
|
679
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
120
|
|
447
|
5
|
|
|
5
|
|
13
|
use strict; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
82
|
|
448
|
|
|
|
|
|
|
|
449
|
5
|
|
|
5
|
|
13
|
use base qw/Tie::Trace/; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
632
|
|
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
sub STORE{ |
452
|
8
|
|
|
8
|
|
15
|
my($self, $value) = @_; |
453
|
8
|
100
|
|
|
|
18
|
$self->_carpit(value => $value) unless $QUIET; |
454
|
8
|
|
|
|
|
8
|
local $QUIET = 1; |
455
|
8
|
|
|
|
|
8
|
Tie::Trace::_data_filter($value, $self); |
456
|
8
|
|
|
|
|
22
|
${$self->{storage}} = $value; |
|
8
|
|
|
|
|
21
|
|
457
|
|
|
|
|
|
|
}; |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=head1 NAME |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
Tie::Trace - easy print debugging with tie, for watching variable |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
=head1 VERSION |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
Version 0.16 |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=cut |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
=head1 SYNOPSIS |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
use Tie::Trace qw/watch/; # or qw/:all/ |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
my %hash = (key => 'value'); |
476
|
|
|
|
|
|
|
watch %hash; |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
$hash{hoge} = 'hogehoge'; # warn "main:: %hash => {hoge} => hogehgoe at ..." |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
my @array; |
481
|
|
|
|
|
|
|
tie @array; |
482
|
|
|
|
|
|
|
push @array, "array"; # warn "main:: @array [0] => array at ..." |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
my $scalar; |
485
|
|
|
|
|
|
|
watch $scalar; |
486
|
|
|
|
|
|
|
$scalar = "scalar"; # warn "main:: $scalar => scalar at ..." |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
=head1 DESCRIPTION |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
This is useful for print debugging. Using tie mechanism, |
491
|
|
|
|
|
|
|
you can see stored/deleted value for the specified variable. |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
If the stored value is scalar/array/hash ref, this can check |
494
|
|
|
|
|
|
|
recursively. |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
for example; |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
watch %hash; |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
$hash{foo} = {a => 1, b => 2}; # warn "main:: %hash => {foo} => {a => 1, b => 2}" |
501
|
|
|
|
|
|
|
$hash{foo}->{a} = 2 # warn "main:: %hash => {foo}{a} => 2" |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
But This ignores blessed reference and tied value. |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=head1 FUNCTION |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
This provides one function C from version 0.06. |
508
|
|
|
|
|
|
|
Then you should use only this function. Don't use C function instead. |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=over 4 |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=item watch |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
watch $variables; |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
watch $scalar, %options; |
517
|
|
|
|
|
|
|
watch @array, %options; |
518
|
|
|
|
|
|
|
watch %hash, %options; |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
When you C variables and value is stored/delete in the variables, |
521
|
|
|
|
|
|
|
warn the message like as the following. |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
main:: %hash => {key} => value at ... |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
If the variables has values before C, it is no problem. Tie::Trace work well. |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
my %hash = (key => 'value'); |
528
|
|
|
|
|
|
|
watch %hash; |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
=back |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=head1 OPTIONS |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
You can use C with some options. |
535
|
|
|
|
|
|
|
If you want global options, see L. |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=over 4 |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
=item key => [values/regexs/coderef] |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
watch %hash, key => [qw/foo bar/]; |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
It is for hash. You can specify key name/regex/coderef for checking. |
544
|
|
|
|
|
|
|
Not specified/matched keys are ignored for warning. |
545
|
|
|
|
|
|
|
When you give coderef, this coderef receive tied value and key as arguments, |
546
|
|
|
|
|
|
|
it returns false, the key is ignored. |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
for example; |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
watch %hash, key => [qw/foo bar/, qr/x/]; |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
$hash{foo} = 1 # warn ... |
553
|
|
|
|
|
|
|
$hash{bar} = 1 # warn ... |
554
|
|
|
|
|
|
|
$hash{var} = 1 # *no* warnings |
555
|
|
|
|
|
|
|
$hash{_x_} = 1 # warn ... |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
=item value => [contents/regexs/coderef] |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
watch %hash, value => [qw/foo bar/]; |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
You can specify value's content/regex/coderef for checking. |
562
|
|
|
|
|
|
|
Not specified/matched are ignored for warning. |
563
|
|
|
|
|
|
|
When you give coderef, this coderef receive tied value and value as arguments, |
564
|
|
|
|
|
|
|
it returns false, the value is ignored. |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
for example; |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
watch %hash, value => [qw/foo bar/, qr/\)/]; |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
$hash{a} = 'foo' # warn ... |
571
|
|
|
|
|
|
|
$hash{b} = 'foo1' # *no* warnings |
572
|
|
|
|
|
|
|
$hash{c} = 'bar' # warn ... |
573
|
|
|
|
|
|
|
$hash{d} = ':-)' # warn ... |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
=item use => [qw/hash array scalar/] |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
tie %hash, "Tie::Trace", use => [qw/array/]; |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
It specify type(scalar, array or hash) of variable for checking. |
580
|
|
|
|
|
|
|
As default, all type will be checked. |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
for example; |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
watch %hash, use => [qw/array/]; |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
$hash{foo} = 1 # *no* warnings |
587
|
|
|
|
|
|
|
$hash{bar} = 1 # *no* warnings |
588
|
|
|
|
|
|
|
$hash{var} = [] # *no* warnings |
589
|
|
|
|
|
|
|
push @{$hash{var}} = 1 # warn ... |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=item debug => 'dumper'/coderef |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
watch %hash, debug => 'dumper' |
594
|
|
|
|
|
|
|
watch %hash, debug => sub{my($self, @v) = @_; return @v } |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
It specify value representation. As default, "dumper" is set. |
597
|
|
|
|
|
|
|
"dumper" makes value show with Data::Dumper::Dumper format(but ::Terse = 0 and ::Indent = 0). |
598
|
|
|
|
|
|
|
You can use coderef instead of "dumper". |
599
|
|
|
|
|
|
|
When you specify your coderef, its first argument is tied value and |
600
|
|
|
|
|
|
|
second argument is value, it should modify it and return it. |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=item debug_value => [contents/regexs/coderef] |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
watch %hash, debug => sub{my($s,$v) = @_; $v =~tr/op/po/;}, debug_value => [qw/foo boo/]; |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
You can specify debugged value's content/regex for checking. |
607
|
|
|
|
|
|
|
Not specified/matched are ignored for warning. |
608
|
|
|
|
|
|
|
When you give coderef, this coderef receive tied value and value as arguments, |
609
|
|
|
|
|
|
|
it returns false, the value is ignored. |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
for example; |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
watch %hash, debug => sub{my($s,$v) = @_; $v =~tr/op/po/;}, debug_value => [qw/foo boo/]; |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
$hash{a} = 'fpp' # warn ... because debugged value is foo |
616
|
|
|
|
|
|
|
$hash{b} = 'foo' # *no* warnings because debugged value is fpp |
617
|
|
|
|
|
|
|
$hash{c} = 'bpp' # warn ... because debugged value is boo |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=item r => 0/1 |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
tie %hash, "Tie::Trace", r => 0; |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
If r is 0, this won't check recursively. 1 is default. |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=item caller => number/[numbers] |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
watch %hash, caller => 2; |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
It effects warning message. |
630
|
|
|
|
|
|
|
default is 0. If you set grater than 0, it goes upstream to check. |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
You can specify array ref. |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
watch %hash, caller => [1, 2, 3]; |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
It display following messages. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
main %hash => {key} => 'hoge' at filename line 61. |
639
|
|
|
|
|
|
|
at filename line 383. |
640
|
|
|
|
|
|
|
at filename line 268. |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
=back |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=head1 METHODS |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
It is used in coderef which is passed for options, for example, |
647
|
|
|
|
|
|
|
key, value and/or debug_value or as the method of the returned of tied function. |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
=over 4 |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
=item storage |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
watch %hash, debug => |
654
|
|
|
|
|
|
|
sub { |
655
|
|
|
|
|
|
|
my($self, $v) = @_; |
656
|
|
|
|
|
|
|
my $storage = $self->storage; |
657
|
|
|
|
|
|
|
return $storage; |
658
|
|
|
|
|
|
|
}; |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
This returns reference in which value(s) stored. |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
=item parent |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
watch %hash, debug => |
665
|
|
|
|
|
|
|
sub { |
666
|
|
|
|
|
|
|
my($self, $v) = @_; |
667
|
|
|
|
|
|
|
my $parent = $self->parent->storage; |
668
|
|
|
|
|
|
|
return $parent; |
669
|
|
|
|
|
|
|
}; |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
This method returns $self's parent tied value. |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
for example; |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
watch my %hash; |
676
|
|
|
|
|
|
|
my %hash2; |
677
|
|
|
|
|
|
|
$hash{1} = \%hash2; |
678
|
|
|
|
|
|
|
my $tied_hash2 = tied %hash2; |
679
|
|
|
|
|
|
|
print tied %hash eq $tied_hash2->parent; # 1 |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=back |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
=head1 GLOBAL VARIABLES |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
=over 4 |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
=item %Tie::Trace::OPTIONS |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
This is Global options for Tie::Trace. |
690
|
|
|
|
|
|
|
If you don't specify any options, this option is used. |
691
|
|
|
|
|
|
|
If you use override options, you use C with options. |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
%Tie::Trace::OPTIONS = (debug => undef, ...); |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
# global options will be used |
696
|
|
|
|
|
|
|
watch my %hash; |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
# your options will be used |
699
|
|
|
|
|
|
|
watch my %hash2, debug => 'dumper', ...; |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=item $Tie::Trace::QUIET |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
If this value is true, Tie::Trace warn nothing. |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
watch my %hash; |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
$hash{1} = 1; # warn something |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
$Tie::Trace::QUIET = 1; |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
$hash{1} = 2; # no warn |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
=back |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
=head1 AUTHOR |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
Ktat, C<< >> |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
=head1 BUGS |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
722
|
|
|
|
|
|
|
C, or through the web interface at |
723
|
|
|
|
|
|
|
L. |
724
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
725
|
|
|
|
|
|
|
your bug as I make changes. |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
=head1 SUPPORT |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
perldoc Tie::Trace |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
You can also find documentation written in Japanese(euc-jp) for this module |
734
|
|
|
|
|
|
|
with the perldoc command. |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
perldoc Tie::Trace_JP |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
You can also look for information at: |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
=over 4 |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
L |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
=item * CPAN Ratings |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
L |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
L |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
=item * Search CPAN |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
L |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=back |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENT |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
JN told me the idea of new warning message(from 0.06). |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
Copyright 2006-2010 Ktat, all rights reserved. |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
769
|
|
|
|
|
|
|
under the same terms as Perl itself. |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
=cut |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
1; # End of Tie::Trace |