line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Hash::ImmutableKeys; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
43859
|
use 5.008008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
49
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1099
|
use Tie::Hash; |
|
1
|
|
|
|
|
1111
|
|
|
1
|
|
|
|
|
31
|
|
10
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1250
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#use vars qw($VERSION @ISA); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @ISA = qw(Exporter Tie::StdHash); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
17
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
18
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This allows declaration use Tie::Hash::ImmutableKeys ':all'; |
21
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
22
|
|
|
|
|
|
|
# will save memory. |
23
|
|
|
|
|
|
|
#our %EXPORT_TAGS = ( |
24
|
|
|
|
|
|
|
# 'all' => [ |
25
|
|
|
|
|
|
|
# qw( |
26
|
|
|
|
|
|
|
# |
27
|
|
|
|
|
|
|
# ) |
28
|
|
|
|
|
|
|
# ], |
29
|
|
|
|
|
|
|
#); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @EXPORT_OK = qw( error ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our @EXPORT = qw( |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $VERSION = sprintf "1.%02d", '$Revision: 14 $ ' =~ /(\d+)/; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $__ERROR__ = "croak"; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub error |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
0
|
0
|
$__ERROR__ = $_[1]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub __HANDEL_ERROR__ |
47
|
|
|
|
|
|
|
{ |
48
|
1
|
50
|
|
1
|
|
5
|
if ( $__ERROR__ =~ /croak/i ) |
|
|
0
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
|
|
188
|
Carp::croak "COULD NOT DELETE key=" . $_[0] . " the val=" . $_[1]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( $__ERROR__ =~ /exit/i ) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
0
|
exit; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
0
|
Carp::carp "COULD NOT DELETE key=" . $_[0] . " the val=" . $_[1]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub TIEHASH |
63
|
|
|
|
|
|
|
{ |
64
|
6
|
|
|
6
|
|
40
|
my $class = $_[0]; |
65
|
6
|
|
|
|
|
9
|
my $list = $_[1]; |
66
|
6
|
|
|
|
|
7
|
my %all; |
67
|
6
|
|
|
|
|
17
|
foreach my $k ( keys %$list ) |
68
|
|
|
|
|
|
|
{ |
69
|
22
|
100
|
|
|
|
53
|
if ( ( ref( $list->{ $k } ) ) =~ /HASH/i ) |
70
|
|
|
|
|
|
|
{ |
71
|
5
|
|
|
|
|
23
|
tie my %c, 'Tie::Hash::ImmutableKeys', $list->{ $k }; |
72
|
5
|
|
|
|
|
12
|
$all{ $k } = \%c; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else |
75
|
|
|
|
|
|
|
{ |
76
|
17
|
|
|
|
|
210
|
$all{ $k } = $list->{ $k }; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
6
|
|
|
|
|
16
|
bless \%all, $class; |
80
|
6
|
|
|
|
|
16
|
return \%all; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub DELETE |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
0
|
|
0
|
|
0
|
if ( $_[2] ) |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
|
|
0
|
delete $_[0]{ $_[1] }; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
my $line = ( caller( 0 ) )[2]; |
93
|
0
|
|
0
|
|
|
0
|
my $sub = ( caller( 1 ) )[3] || "main"; |
94
|
0
|
|
|
|
|
0
|
__HANDEL_ERROR__( $_[1], $_[2] ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub FORCE_DELETE |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
0
|
0
|
0
|
my $class = $_[0]; |
101
|
0
|
|
|
|
|
0
|
my $key = $_[1]; |
102
|
0
|
|
|
|
|
0
|
my $leaf = $_[2]; |
103
|
0
|
0
|
|
|
|
0
|
if ( ( ref( $key ) ) =~ /HASH/i ) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
0
|
foreach my $k ( keys %$key ) |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
|
|
0
|
my %all; |
108
|
0
|
0
|
|
|
|
0
|
if ( ( ref( $key->{ $k } ) ) =~ /HASH/i ) |
109
|
|
|
|
|
|
|
{ |
110
|
0
|
|
|
|
|
0
|
tie( %all, 'Tie::Hash::ImmutableKeys', $class->{ $k } ); |
111
|
0
|
|
|
|
|
0
|
my $obj = tied( %all ); |
112
|
0
|
|
|
|
|
0
|
tie my %c, 'Tie::Hash::ImmutableKeys', $key->{ $k }; |
113
|
0
|
|
|
|
|
0
|
$obj->FORCE_DELETE( $key->{ $k } ); |
114
|
0
|
|
|
|
|
0
|
$class->{ $k } = \%all; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
|
|
|
|
0
|
tie( %all, 'Tie::Hash::ImmutableKeys', $class->{ $k } ); |
119
|
0
|
|
|
|
|
0
|
my $obj = tied( %all ); |
120
|
0
|
|
|
|
|
0
|
$obj->FORCE_DELETE( $key->{ $k }, 1 ); |
121
|
0
|
|
|
|
|
0
|
$class->{ $k } = \%all; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
0
|
|
|
|
0
|
$class->SUPER::DELETE( $key ) if $leaf; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub STORE |
133
|
|
|
|
|
|
|
{ |
134
|
2
|
50
|
|
2
|
|
479
|
if ( $_[3] ) |
135
|
|
|
|
|
|
|
{ |
136
|
0
|
|
|
|
|
0
|
$_[0]{ $_[1] } = $_[2]; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else |
139
|
|
|
|
|
|
|
{ |
140
|
2
|
100
|
|
|
|
8
|
if ( exists $_[0]{ $_[1] } ) |
141
|
|
|
|
|
|
|
{ |
142
|
|
|
|
|
|
|
|
143
|
1
|
50
|
|
|
|
11
|
$_[0]{ $_[1] } = $_[2] if exists $_[0]{ $_[1] }; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else |
146
|
|
|
|
|
|
|
{ |
147
|
1
|
|
|
|
|
4
|
my $line = ( caller( 0 ) )[2]; |
148
|
1
|
|
50
|
|
|
6
|
my $sub = ( caller( 1 ) )[3] || "main"; |
149
|
1
|
|
|
|
|
5
|
__HANDEL_ERROR__( $_[1], $_[2] ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub FORCE_STORE |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
0
|
0
|
|
my $class = $_[0]; |
157
|
0
|
|
|
|
|
|
my $key = $_[1]; |
158
|
0
|
|
|
|
|
|
my $val = $_[2]; |
159
|
0
|
0
|
|
|
|
|
if ( exists( $class->{ $key } ) ) |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
0
|
|
|
|
|
if ( ( ref( $val ) ) =~ /HASH/i ) |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
|
|
|
tie( my %all, 'Tie::Hash::ImmutableKeys', $class->{ $key } ); |
164
|
0
|
|
|
|
|
|
my $obj = tied( %all ); |
165
|
0
|
|
|
|
|
|
foreach my $k ( keys %$val ) |
166
|
|
|
|
|
|
|
{ |
167
|
0
|
0
|
|
|
|
|
if ( ( ref( $val->{ $k } ) ) =~ /HASH/i ) |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
|
|
|
tie my %c, 'Tie::Hash::ImmutableKeys', $val->{ $k }; |
170
|
0
|
|
|
|
|
|
$obj->FORCE_STORE( $k, \%c ); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else |
173
|
|
|
|
|
|
|
{ |
174
|
0
|
|
|
|
|
|
$obj->STORE( $k, $val->{ $k }, 1 ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
0
|
|
|
|
|
|
$class->STORE( $key, \%all, 1 ); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
else |
180
|
|
|
|
|
|
|
{ |
181
|
0
|
|
|
|
|
|
$class->SUPER::STORE( $key, $val ); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
else |
185
|
|
|
|
|
|
|
{ |
186
|
0
|
|
|
|
|
|
my %all; |
187
|
0
|
|
|
|
|
|
foreach my $k ( keys %$val ) |
188
|
|
|
|
|
|
|
{ |
189
|
0
|
0
|
|
|
|
|
if ( ( ref( $val->{ $k } ) ) =~ /HASH/i ) |
190
|
|
|
|
|
|
|
{ |
191
|
0
|
|
|
|
|
|
tie my %c, 'Tie::Hash::ImmutableKeys', $val->{ $k }; |
192
|
0
|
|
|
|
|
|
$all{ $k } = \%c; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else |
195
|
|
|
|
|
|
|
{ |
196
|
0
|
|
|
|
|
|
$all{ $k } = $val->{ $k }; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
0
|
|
|
|
|
|
my %tmp; |
200
|
0
|
|
|
|
|
|
tie( %tmp, 'Tie::Hash::ImmutableKeys', \%all ); |
201
|
0
|
|
|
|
|
|
$class->SUPER::STORE( $key, \%tmp ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
__END__ |