line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Trace; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
63307
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
108
|
|
4
|
5
|
|
|
5
|
|
13
|
use warnings; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
85
|
|
5
|
5
|
|
|
5
|
|
2408
|
use PadWalker (); |
|
5
|
|
|
|
|
2239
|
|
|
5
|
|
|
|
|
87
|
|
6
|
5
|
|
|
5
|
|
1727
|
use Tie::Hash (); |
|
5
|
|
|
|
|
2580
|
|
|
5
|
|
|
|
|
65
|
|
7
|
5
|
|
|
5
|
|
1987
|
use Tie::Array (); |
|
5
|
|
|
|
|
3916
|
|
|
5
|
|
|
|
|
71
|
|
8
|
5
|
|
|
5
|
|
2049
|
use Tie::Scalar (); |
|
5
|
|
|
|
|
1757
|
|
|
5
|
|
|
|
|
68
|
|
9
|
5
|
|
|
5
|
|
19
|
use Carp (); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
50
|
|
10
|
5
|
|
|
5
|
|
1517
|
use Data::Dumper (); |
|
5
|
|
|
|
|
16787
|
|
|
5
|
|
|
|
|
93
|
|
11
|
5
|
|
|
5
|
|
18
|
use base qw/Exporter/; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
322
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant { |
14
|
5
|
|
|
|
|
8168
|
SCALAR => 0, |
15
|
|
|
|
|
|
|
SCALARREF => 1, |
16
|
|
|
|
|
|
|
ARRAYREF => 2, |
17
|
|
|
|
|
|
|
HASHREF => 4, |
18
|
|
|
|
|
|
|
BLESSED => 8, |
19
|
|
|
|
|
|
|
TIED => 16, |
20
|
5
|
|
|
5
|
|
108
|
}; |
|
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
|
|
16028
|
my($self, @args) = @_; |
33
|
102
|
|
|
|
|
219
|
my($class, $method) = (split /::/, $AUTOLOAD)[2, 3]; |
34
|
102
|
|
|
|
|
88
|
my $sub = \&{'Tie::Std' . $class . '::' . $method}; |
|
102
|
|
|
|
|
220
|
|
35
|
102
|
100
|
|
|
|
242
|
defined &$sub ? $sub->($self->{storage}, @args) : return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
19
|
|
729
|
sub TIEHASH { Tie::Trace::_tieit({}, @_); } |
39
|
6
|
|
|
6
|
|
12
|
sub TIEARRAY { Tie::Trace::_tieit([], @_); } |
40
|
6
|
|
|
6
|
|
5
|
sub TIESCALAR{ my $tmp; Tie::Trace::_tieit(\$tmp, @_); } |
|
6
|
|
|
|
|
12
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub watch(\[$@%]@){ |
43
|
7
|
|
|
7
|
1
|
5105
|
my $s = shift; |
44
|
7
|
|
|
|
|
12
|
my $s_type = ref $s; |
45
|
7
|
|
|
|
|
6
|
my $s_ = $s; |
46
|
|
|
|
|
|
|
|
47
|
7
|
50
|
|
|
|
32
|
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
|
|
|
|
|
12
|
$s_ = { %$s }; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
7
|
50
|
|
|
|
15
|
Carp::croak("must pass one argument.") unless $s; |
56
|
7
|
|
|
|
|
11
|
my @options = @_; |
57
|
7
|
|
|
|
|
7
|
my $var_name; |
58
|
7
|
|
|
|
|
7
|
eval{ |
59
|
7
|
|
|
|
|
27
|
$var_name = PadWalker::var_name(1, $s); |
60
|
|
|
|
|
|
|
}; |
61
|
7
|
50
|
|
|
|
20
|
my $pkg = defined $var_name ? (caller)[0] : undef; |
62
|
7
|
100
|
|
|
|
38
|
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
|
|
|
|
|
7
|
local $QUIET = 1; |
64
|
|
|
|
|
|
|
|
65
|
7
|
50
|
|
|
|
24
|
if($s_type eq 'SCALAR'){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
$$s = $s_; |
67
|
|
|
|
|
|
|
}elsif($s_type eq 'ARRAY'){ |
68
|
1
|
50
|
|
|
|
3
|
@$s = @$s_ if @$s_; |
69
|
|
|
|
|
|
|
}elsif($s_type eq 'HASH'){ |
70
|
6
|
50
|
|
|
|
15
|
%$s = %$s_ if %$s_; |
71
|
|
|
|
|
|
|
} |
72
|
7
|
|
|
|
|
15
|
return $tied_value; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _dumper{ |
76
|
47
|
|
|
47
|
|
46
|
my($self, $value) = @_; |
77
|
47
|
|
|
|
|
45
|
local $Data::Dumper::Terse = 1; |
78
|
47
|
|
|
|
|
40
|
local $Data::Dumper::Indent = 0; |
79
|
47
|
|
|
|
|
27
|
local $Data::Dumper::Deparse = 1; |
80
|
47
|
|
|
|
|
96
|
$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
|
77
|
my($self) = @_; |
90
|
95
|
|
|
|
|
162
|
return $self->{parent}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _match{ |
94
|
52
|
|
|
52
|
|
46
|
my($self, $test, $value) = @_; |
95
|
52
|
100
|
|
|
|
81
|
if(ref $test eq 'Regexp'){ |
|
|
50
|
|
|
|
|
|
96
|
7
|
|
|
|
|
33
|
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
|
|
153
|
my($self, $test, $tested) = @_; |
107
|
107
|
100
|
|
|
|
223
|
return 1 unless $test; |
108
|
29
|
100
|
|
|
|
40
|
if($tested){ |
109
|
28
|
100
|
|
|
|
58
|
return 1 if grep $self->_match($_, $tested), @$test; |
110
|
|
|
|
|
|
|
} |
111
|
10
|
|
|
|
|
16
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _carpit{ |
115
|
66
|
|
|
66
|
|
339
|
my($self, %args) = @_; |
116
|
66
|
50
|
|
|
|
90
|
return if $QUIET; |
117
|
|
|
|
|
|
|
|
118
|
66
|
|
|
|
|
155
|
my $class = (split /::/, ref $self)[2]; |
119
|
66
|
|
50
|
|
|
139
|
my $op = $self->{options} || {}; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# key/value checking |
122
|
66
|
100
|
66
|
|
|
180
|
if($op->{key} or $op->{value}){ |
123
|
20
|
|
|
|
|
41
|
my $key = $self->_matching($self->{options}->{key}, $args{key}); |
124
|
20
|
|
|
|
|
44
|
my $value = $self->_matching($self->{options}->{value}, $args{value}); |
125
|
20
|
50
|
33
|
|
|
109
|
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
|
|
|
|
12
|
return unless $key; |
129
|
|
|
|
|
|
|
}elsif($op->{value}){ |
130
|
14
|
100
|
|
|
|
28
|
return unless $value; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# debug type |
135
|
58
|
|
|
|
|
154
|
my $value = $self->_debug_message($args{value}, $op->{debug}, $args{filter}); |
136
|
|
|
|
|
|
|
# debug_value checking |
137
|
58
|
50
|
|
|
|
167
|
return unless $self->_matching($self->{options}->{debug_value}, $value); |
138
|
|
|
|
|
|
|
# use scalar/array/hash ? |
139
|
58
|
50
|
|
|
|
58
|
return unless grep lc($class) eq lc($_) , @{$op->{use}}; |
|
58
|
|
|
|
|
205
|
|
140
|
|
|
|
|
|
|
# create warning message |
141
|
58
|
|
|
|
|
53
|
my $watch_msg = ''; |
142
|
58
|
|
|
|
|
102
|
my $msg = $self->_output_message($class, $value, \%args); |
143
|
58
|
100
|
|
|
|
79
|
if(defined $self->{options}->{pkg}){ |
144
|
56
|
|
|
|
|
49
|
$watch_msg = sprintf("%s:: %s", @{$self->{options}}{qw/pkg var/}); |
|
56
|
|
|
|
|
163
|
|
145
|
|
|
|
|
|
|
}else{ |
146
|
2
|
|
|
|
|
3
|
$msg =~ s/^ => //; |
147
|
|
|
|
|
|
|
} |
148
|
58
|
|
|
|
|
244
|
warn $watch_msg . $msg . "\n"; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _output_message{ |
152
|
58
|
|
|
58
|
|
61
|
my($self, $class, $value, $args) = @_; |
153
|
58
|
|
|
|
|
59
|
my($msg, @msg) = (''); |
154
|
|
|
|
|
|
|
|
155
|
58
|
|
|
|
|
75
|
my $caller = $self->{options}->{caller}; |
156
|
58
|
|
|
|
|
43
|
my $_caller_n = 1; |
157
|
58
|
|
|
|
|
311
|
while (my $c = (caller $_caller_n)[0]) { |
158
|
124
|
50
|
|
|
|
299
|
if (not $c) { |
|
|
100
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
last; |
160
|
|
|
|
|
|
|
} elsif ($c !~ /^Tie::Trace/) { |
161
|
58
|
|
|
|
|
62
|
last; |
162
|
|
|
|
|
|
|
} |
163
|
66
|
|
|
|
|
228
|
$_caller_n++; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
58
|
50
|
|
|
|
151
|
my @caller = map $_ + $_caller_n, ref $caller ? @{$caller} : $caller; |
|
0
|
|
|
|
|
0
|
|
167
|
58
|
|
|
|
|
46
|
my(@filename, @line); |
168
|
58
|
|
|
|
|
77
|
foreach(@caller){ |
169
|
58
|
|
|
|
|
128
|
my($f, $l) = (caller($_))[1, 2]; |
170
|
58
|
50
|
33
|
|
|
204
|
next unless $f and $l; |
171
|
|
|
|
|
|
|
|
172
|
58
|
|
|
|
|
46
|
push @filename, $f; |
173
|
58
|
|
|
|
|
77
|
push @line, $l; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
58
|
50
|
|
|
|
135
|
my $location = @line == 1 ? " at $filename[0] line $line[0]." : |
178
|
|
|
|
|
|
|
join "\n", map " at $filename[$_] line $line[$_].", (0 .. $#filename); |
179
|
58
|
|
|
|
|
86
|
my($_p, $p) = ($self, $self->parent); |
180
|
58
|
|
|
|
|
89
|
while($p){ |
181
|
36
|
|
|
|
|
34
|
my $s_type = ref $p->{storage}; |
182
|
36
|
|
|
|
|
27
|
my $s = $p->{storage}; |
183
|
36
|
100
|
|
|
|
47
|
if($s_type eq 'HASH'){ |
|
|
50
|
|
|
|
|
|
184
|
35
|
|
|
|
|
46
|
push @msg, "{$_p->{__key}}"; |
185
|
|
|
|
|
|
|
}elsif($s_type eq 'ARRAY'){ |
186
|
1
|
|
|
|
|
3
|
push @msg, "[$_p->{__point}]"; |
187
|
|
|
|
|
|
|
} |
188
|
36
|
|
|
|
|
30
|
$_p = $p; |
189
|
36
|
100
|
33
|
|
|
74
|
last if ! ref $p or ! ($p = $p->parent); |
190
|
|
|
|
|
|
|
} |
191
|
58
|
100
|
|
|
|
102
|
$msg = @msg > 0 ? ' => ' . join "", reverse @msg : ""; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
58
|
50
|
|
|
|
75
|
$value = '' unless defined $value; |
195
|
58
|
100
|
|
|
|
144
|
if ($class eq 'Scalar') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
196
|
2
|
|
|
|
|
6
|
return("${msg} => $value$location"); |
197
|
|
|
|
|
|
|
} elsif ($class eq 'Array') { |
198
|
19
|
100
|
|
|
|
25
|
unless(defined $args->{point}){ |
199
|
4
|
|
|
|
|
26
|
$msg =~ s/^( => )(.+)$/$1\@\{$2\}/; |
200
|
4
|
|
|
|
|
16
|
return("$msg => $value$location"); |
201
|
|
|
|
|
|
|
}else{ |
202
|
15
|
|
|
|
|
46
|
return("${msg}[$args->{point}] => $value$location"); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} elsif ($class eq 'Hash') { |
205
|
37
|
100
|
100
|
|
|
227
|
return("${msg}" . (! $self->{options}->{pkg} || @msg ? "" : " => "). "{$args->{key}} => $value$location"); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _debug_message{ |
210
|
58
|
|
|
58
|
|
75
|
my($self, $value, $debug, $filter) = @_; |
211
|
|
|
|
|
|
|
|
212
|
58
|
50
|
|
|
|
261
|
if(ref $debug eq 'CODE'){ |
|
|
100
|
|
|
|
|
|
213
|
0
|
|
|
|
|
0
|
$value = $debug->($self, $value); |
214
|
|
|
|
|
|
|
}elsif(lc($debug) eq 'dumper'){ |
215
|
43
|
|
|
|
|
57
|
$value = $self->_dumper($value); |
216
|
43
|
100
|
|
|
|
3939
|
if(defined $filter){ |
217
|
8
|
|
|
|
|
16
|
$filter->($value); |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
58
|
|
|
|
|
90
|
return $value; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _tieit { |
224
|
31
|
|
|
31
|
|
67
|
my($self, $class, %arg) = @_; |
225
|
31
|
|
|
|
|
53
|
foreach (keys %OPTIONS){ |
226
|
31
|
100
|
|
|
|
83
|
$arg{$_} = $OPTIONS{$_} if not exists $arg{$_}; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
31
|
100
|
|
|
|
76
|
if($class =~/^Tie::Trace$/){ |
230
|
9
|
|
|
|
|
15
|
my $type = lc(ref $self); |
231
|
9
|
|
|
|
|
18
|
substr($type, 0, 1) = uc(substr($type, 0, 1)); |
232
|
9
|
|
|
|
|
15
|
$class .= '::' . $type; |
233
|
|
|
|
|
|
|
} |
234
|
31
|
|
|
|
|
28
|
my $parent = $arg{parent}; |
235
|
31
|
|
|
|
|
24
|
my $options; |
236
|
31
|
100
|
66
|
|
|
90
|
if(defined $parent and $parent){ |
237
|
22
|
|
|
|
|
19
|
$options = $parent->{options}; |
238
|
|
|
|
|
|
|
}else{ |
239
|
9
|
|
|
|
|
9
|
$options = \%arg; |
240
|
9
|
50
|
|
|
|
17
|
unless($options->{use}){ |
241
|
9
|
|
|
|
|
16
|
$options->{use} = [qw/scalar array hash/]; |
242
|
|
|
|
|
|
|
} |
243
|
9
|
100
|
|
|
|
16
|
unless(defined $options->{r}){ |
244
|
5
|
|
|
|
|
7
|
$options->{r} = 1; |
245
|
|
|
|
|
|
|
} |
246
|
9
|
|
50
|
|
|
41
|
$options->{caller} ||= 0; |
247
|
|
|
|
|
|
|
} |
248
|
31
|
|
|
|
|
60
|
my $_self = |
249
|
|
|
|
|
|
|
{ |
250
|
|
|
|
|
|
|
self => $self, |
251
|
|
|
|
|
|
|
parent => $parent, |
252
|
|
|
|
|
|
|
options => $options, |
253
|
|
|
|
|
|
|
}; |
254
|
31
|
100
|
|
|
|
62
|
$_self->{__key} = delete $arg{__key} if exists $arg{__key}; |
255
|
31
|
100
|
|
|
|
49
|
$_self->{__point} = delete $arg{__point} if exists $arg{__point}; |
256
|
31
|
|
|
|
|
31
|
bless $_self, $class; |
257
|
31
|
|
|
|
|
93
|
return $_self; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub _data_filter{ |
261
|
160
|
|
|
160
|
|
139
|
my($structure, $self, $parent_info) = @_; |
262
|
160
|
100
|
|
|
|
234
|
return $structure unless $self->{options}->{r}; |
263
|
153
|
|
100
|
|
|
214
|
$parent_info ||= {}; |
264
|
|
|
|
|
|
|
|
265
|
153
|
|
|
|
|
126
|
my $ref = ref $structure; |
266
|
153
|
|
|
|
|
252
|
my %test = (SCALARREF() => 'SCALAR', ARRAYREF() => 'ARRAY', HASHREF() => 'HASH'); |
267
|
153
|
|
|
|
|
110
|
my $type = 0; |
268
|
153
|
|
|
|
|
90
|
my($class, $tied); |
269
|
153
|
50
|
|
|
|
196
|
if(defined $ref){ |
270
|
153
|
|
|
|
|
217
|
foreach my $i (keys %test){ |
271
|
440
|
100
|
100
|
|
|
2953
|
if($ref eq $test{$i}){ |
|
|
100
|
|
|
|
|
|
272
|
22
|
|
|
|
|
17
|
$type = $i; |
273
|
22
|
|
|
|
|
27
|
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
|
|
|
|
8
|
$type = $i | BLESSED | ($tied ? TIED : 0); |
277
|
2
|
|
|
|
|
2
|
$class = $ref; |
278
|
2
|
|
|
|
|
4
|
last; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
} |
282
|
153
|
100
|
66
|
|
|
427
|
unless($class or $tied){ |
283
|
151
|
100
|
|
|
|
353
|
if(($type & 0b11001) == SCALARREF){ |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
284
|
6
|
|
|
|
|
25
|
my $tmp = $$structure; |
285
|
6
|
|
|
|
|
40
|
tie $$structure, "Tie::Trace::Scalar", parent => $self, %$parent_info; |
286
|
6
|
|
|
|
|
15
|
$$structure = Tie::Trace::_data_filter($tmp, $self); |
287
|
6
|
|
|
|
|
14
|
return $structure; |
288
|
|
|
|
|
|
|
}elsif(($type & 0b11010) == ARRAYREF){ |
289
|
5
|
|
|
|
|
14
|
my @tmp = @$structure; |
290
|
5
|
|
|
|
|
28
|
tie @$structure, "Tie::Trace::Array", parent => $self, %$parent_info; |
291
|
5
|
|
|
|
|
12
|
foreach my $i (0 .. $#tmp){ |
292
|
23
|
|
|
|
|
37
|
$structure->[$i] = Tie::Trace::_data_filter($tmp[$i], $self, {__point => $i}); |
293
|
|
|
|
|
|
|
} |
294
|
5
|
|
|
|
|
17
|
return $structure; |
295
|
|
|
|
|
|
|
}elsif(($type & 0b11100) == HASHREF){ |
296
|
11
|
|
|
|
|
22
|
my %tmp = %$structure; |
297
|
11
|
|
|
|
|
57
|
tie %$structure, "Tie::Trace::Hash", parent => $self, %$parent_info;; |
298
|
11
|
|
|
|
|
30
|
while(my($k, $v) = each %tmp){ |
299
|
8
|
|
|
|
|
23
|
$structure->{$k} = Tie::Trace::_data_filter($v, $self, {__key => $k}); |
300
|
|
|
|
|
|
|
} |
301
|
11
|
|
|
|
|
24
|
return $structure; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
# tied variable / blessed ref / just a scalar |
305
|
131
|
|
|
|
|
231
|
return $structure; |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# Hash ///////////////////////// |
309
|
|
|
|
|
|
|
package |
310
|
|
|
|
|
|
|
Tie::Trace::Hash; |
311
|
|
|
|
|
|
|
|
312
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
128
|
|
313
|
5
|
|
|
5
|
|
19
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
82
|
|
314
|
|
|
|
|
|
|
|
315
|
5
|
|
|
5
|
|
13
|
use base qw/Tie::Trace/; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
1021
|
|
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub STORE{ |
318
|
52
|
|
|
52
|
|
12666
|
my($self, $key, $value) = @_; |
319
|
52
|
100
|
|
|
|
138
|
$self->_carpit(key => $key, value => $value) unless $QUIET; |
320
|
52
|
|
|
|
|
68
|
local $QUIET = 1; |
321
|
52
|
|
|
|
|
111
|
Tie::Trace::_data_filter($value, $self, {__key => $key}); |
322
|
52
|
|
|
|
|
209
|
$self->{storage}->{$key} = $value; |
323
|
|
|
|
|
|
|
}; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub DELETE { |
326
|
2
|
|
|
2
|
|
411
|
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
|
|
|
|
16
|
) unless $QUIET; |
|
|
50
|
|
|
|
|
|
332
|
2
|
|
|
|
|
10
|
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
|
|
266
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
109
|
|
345
|
5
|
|
|
5
|
|
14
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
97
|
|
346
|
|
|
|
|
|
|
|
347
|
5
|
|
|
5
|
|
12
|
use base qw/Tie::Trace/; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
2710
|
|
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub STORE{ |
350
|
32
|
|
|
32
|
|
382
|
my($self, $p, $value) = @_; |
351
|
32
|
100
|
|
|
|
48
|
$self->_carpit(point => $p, value => $value) unless $QUIET; |
352
|
32
|
|
|
|
|
29
|
local $QUIET = 1; |
353
|
32
|
|
|
|
|
61
|
Tie::Trace::_data_filter($value, $self, {__point => $p}); |
354
|
32
|
|
|
|
|
98
|
$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
|
|
|
|
|
3
|
|
360
|
|
|
|
|
|
|
$self->_carpit(point => $p, |
361
|
|
|
|
|
|
|
value => sprintf("DELETED(%s)", $self->_dumper(defined $deleted ? $deleted : "undef")), |
362
|
1
|
|
|
1
|
|
5
|
filter => sub{$_[0] =~ s/^\'(.*)\'$/$1/; $_[0] =~s /\\'/'/g} |
|
1
|
|
|
|
|
4
|
|
363
|
1
|
50
|
|
|
|
7
|
) unless $QUIET; |
|
|
50
|
|
|
|
|
|
364
|
1
|
|
|
|
|
9
|
return $deleted; |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub SPLICE{ |
368
|
9
|
|
|
9
|
|
14
|
my $self = shift; |
369
|
9
|
|
|
|
|
5
|
my $sz = @{$self->{storage}}; |
|
9
|
|
|
|
|
9
|
|
370
|
9
|
50
|
|
|
|
16
|
my $off = @_ ? shift : 0; |
371
|
9
|
|
|
|
|
11
|
my $fetchsize = $self->FETCHSIZE; |
372
|
9
|
|
|
|
|
18
|
my $caller_pkg = (caller)[0]; |
373
|
9
|
|
|
|
|
9
|
my $func = ""; |
374
|
9
|
100
|
|
|
|
17
|
if($caller_pkg eq "Tie::Trace::Array"){ |
375
|
8
|
|
|
|
|
20
|
$func = (caller 1)[3]; |
376
|
8
|
|
|
|
|
29
|
$func =~s/^Tie::Trace::Array:://; |
377
|
|
|
|
|
|
|
} |
378
|
9
|
50
|
|
|
|
16
|
$off += $sz if $off < 0; |
379
|
9
|
50
|
|
|
|
13
|
my $len = @_ ? shift : $sz - $off; |
380
|
9
|
|
|
|
|
12
|
my $to = $off + $len -1; |
381
|
9
|
100
|
|
|
|
23
|
my $p = $off eq $to ? $off : $off < $to ? "$off .. $to" : $off; |
|
|
100
|
|
|
|
|
|
382
|
9
|
100
|
100
|
|
|
36
|
my @point = ($func and $func ne 'STORESIZE') ? () : (point => $p); |
383
|
9
|
50
|
|
7
|
|
49
|
$self->_carpit(@point, value => \@_, filter => sub {$_[0] =~ s/^\[(.*)\]$/$func\($1\)/} ) unless $QUIET; |
|
7
|
|
|
|
|
48
|
|
384
|
9
|
|
|
|
|
23
|
local $QUIET = 1; |
385
|
9
|
100
|
|
|
|
17
|
if(@_){ |
386
|
5
|
|
|
|
|
5
|
my $cnt = 0; |
387
|
5
|
|
|
|
|
7
|
foreach(@_){ |
388
|
5
|
|
|
|
|
22
|
Tie::Trace::_data_filter($_, $self, {__point => $off + $cnt++}); |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
} |
391
|
9
|
|
|
|
|
5
|
my $ret = splice(@{$self->{storage}}, $off, $len, @_); |
|
9
|
|
|
|
|
23
|
|
392
|
9
|
100
|
|
|
|
24
|
if(@_ != $len){ |
393
|
6
|
|
|
|
|
7
|
my $diff = scalar @_ - $len; |
394
|
6
|
|
|
|
|
6
|
local $QUIET = 1; |
395
|
6
|
|
|
|
|
6
|
for(my $i = 0;$i < @{$self->{storage}}; $i++){ |
|
32
|
|
|
|
|
65
|
|
396
|
26
|
|
|
|
|
19
|
my $value = $self->{storage}->[$i]; |
397
|
26
|
|
|
|
|
42
|
Tie::Trace::_data_filter($value, $self, {__point => $i}); |
398
|
26
|
|
|
|
|
41
|
$self->{storage}->[$i] = $value; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
} |
401
|
9
|
|
|
|
|
25
|
return $ret; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
sub FETCHSIZE{ |
405
|
28
|
|
|
28
|
|
253
|
my($self) = shift; |
406
|
28
|
|
100
|
|
|
16
|
return scalar @{$self->{storage} ||= []}; |
|
28
|
|
|
|
|
107
|
|
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
sub PUSH{ |
410
|
4
|
|
|
4
|
|
21
|
my($self, @value) = @_; |
411
|
4
|
|
|
|
|
9
|
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
|
|
1443
|
my ($self, $p) = @_; |
431
|
4
|
|
|
|
|
7
|
$self->SPLICE($p, $self->FETCHSIZE - $p); |
432
|
4
|
|
|
|
|
19
|
return undef; |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
sub CLEAR{ |
436
|
3
|
|
|
3
|
|
1476
|
my($self) = @_; |
437
|
3
|
|
|
|
|
11
|
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
|
|
649
|
use warnings; |
|
5
|
|
|
|
|
3
|
|
|
5
|
|
|
|
|
111
|
|
447
|
5
|
|
|
5
|
|
12
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
79
|
|
448
|
|
|
|
|
|
|
|
449
|
5
|
|
|
5
|
|
14
|
use base qw/Tie::Trace/; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
603
|
|
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
sub STORE{ |
452
|
8
|
|
|
8
|
|
15
|
my($self, $value) = @_; |
453
|
8
|
100
|
|
|
|
16
|
$self->_carpit(value => $value) unless $QUIET; |
454
|
8
|
|
|
|
|
6
|
local $QUIET = 1; |
455
|
8
|
|
|
|
|
11
|
Tie::Trace::_data_filter($value, $self); |
456
|
8
|
|
|
|
|
24
|
${$self->{storage}} = $value; |
|
8
|
|
|
|
|
24
|
|
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.17 |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=cut |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
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 |