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