line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2001 Simon Wistow |
2
|
|
|
|
|
|
|
# Distributed under the same terms as Perl itself |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Tie::Hash::Layered; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require 5.005_62; |
7
|
1
|
|
|
1
|
|
706
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
51
|
|
11
|
1
|
|
|
1
|
|
893
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1579
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.9'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# -- Tie ourselves into a hash |
20
|
|
|
|
|
|
|
# We set up a list of other hashes |
21
|
|
|
|
|
|
|
# so that we can check from L to R |
22
|
|
|
|
|
|
|
sub TIEHASH |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
# get our class |
25
|
1
|
|
|
1
|
|
72
|
my $class = shift; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
2
|
my $self = {}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# we assume the rest of our arguments are arrays |
31
|
1
|
|
|
|
|
2
|
$self->{_HASHES} = \@_; |
32
|
1
|
|
|
|
|
2
|
$self->{_OFFSET} = 0; |
33
|
1
|
|
|
|
|
2
|
$self->{_KEYSSEEN} = {}; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
5
|
return bless $self, $class; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub FETCH |
40
|
|
|
|
|
|
|
{ |
41
|
14
|
|
|
14
|
|
172
|
my ($self, $key) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# right, we have the key we need to check for |
44
|
|
|
|
|
|
|
# so we iterate down our list of arrays and |
45
|
|
|
|
|
|
|
# check to see if the value exists |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
14
|
|
|
|
|
14
|
foreach my $hashref (reverse @{$self->{_HASHES}}) |
|
14
|
|
|
|
|
27
|
|
51
|
|
|
|
|
|
|
{ |
52
|
22
|
100
|
|
|
|
77
|
return $hashref->{$key} if defined $hashref->{$key}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# hmm, none of our hashes have that key, |
57
|
|
|
|
|
|
|
# /shurg/ (sic), return undef; |
58
|
3
|
|
|
|
|
7
|
return undef; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub STORE |
64
|
|
|
|
|
|
|
{ |
65
|
3
|
|
|
3
|
|
76
|
my ($self,$key, $value) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# this is dead easy, we just store it in the first |
69
|
3
|
|
|
|
|
11
|
return $self->{_HASHES}->[_get_max($self)]->{$key} = $value; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub DELETE |
76
|
|
|
|
|
|
|
{ |
77
|
2
|
|
|
2
|
|
106
|
my ($self, $key) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# just delete the first key in the the first hash |
80
|
2
|
|
|
|
|
6
|
my $res = delete $self->{_HASHES}->[_get_max($self)]->{$key}; |
81
|
2
|
|
|
|
|
7
|
return $res; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub CLEAR |
85
|
|
|
|
|
|
|
{ |
86
|
1
|
|
|
1
|
|
5
|
my ($self) = @_; |
87
|
1
|
|
|
|
|
2
|
my %hash = (); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
1
|
pop @{$self->{_HASHES}}; |
|
1
|
|
|
|
|
3
|
|
91
|
1
|
|
|
|
|
1
|
push @{$self->{_HASHES}}, \%hash; |
|
1
|
|
|
|
|
4
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub EXISTS |
96
|
|
|
|
|
|
|
{ |
97
|
2
|
|
|
2
|
|
52
|
my ($self, $key) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# again with the iteration :) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
3
|
foreach my $hashref (reverse @{$self->{_HASHES}}) |
|
2
|
|
|
|
|
5
|
|
103
|
|
|
|
|
|
|
{ |
104
|
4
|
100
|
|
|
|
12
|
return 1 if (exists $hashref->{$key}); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
3
|
return 0; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub FIRSTKEY |
111
|
|
|
|
|
|
|
{ |
112
|
2
|
|
|
2
|
|
31
|
my ($self) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
4
|
$self->{_OFFSET} = 0; |
117
|
2
|
|
|
|
|
3
|
$self->{_KEYSSEEN} = {}; |
118
|
2
|
|
|
|
|
3
|
my $a = keys %{$self->{_HASHES}->[0]}; |
|
2
|
|
|
|
|
5
|
|
119
|
2
|
|
|
|
|
3
|
each (%{$self->{_HASHES}->[0]}); |
|
2
|
|
|
|
|
9
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub NEXTKEY |
127
|
|
|
|
|
|
|
{ |
128
|
4
|
|
|
4
|
|
6
|
my ($self) = @_; |
129
|
|
|
|
|
|
|
|
130
|
4
|
|
|
|
|
5
|
my $key; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
4
|
|
|
|
|
5
|
my %keys = %{$self->{_KEYSSEEN}}; |
|
4
|
|
|
|
|
12
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
do |
136
|
4
|
|
100
|
|
|
4
|
{ |
137
|
5
|
|
|
|
|
6
|
$key = each %{ $self->{_HASHES}->[$self->{_OFFSET}] }; |
|
5
|
|
|
|
|
9
|
|
138
|
5
|
100
|
|
|
|
18
|
if (defined $key) |
139
|
|
|
|
|
|
|
{ |
140
|
3
|
50
|
|
|
|
15
|
$key = undef if ($self->{_KEYSSEEN}->{$key}++); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
#print "Offset : ".$self->{_OFFSET}; |
144
|
|
|
|
|
|
|
#print " Key = $key" if (defined $key); |
145
|
|
|
|
|
|
|
#print "\n"; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
until (defined $key || ++$self->{_OFFSET} > _get_max($self)); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#return undef if ($self->{_OFFSET}==_get_max($self)); |
151
|
|
|
|
|
|
|
|
152
|
4
|
|
|
|
|
13
|
return $key; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _get_max |
158
|
|
|
|
|
|
|
{ |
159
|
7
|
|
|
7
|
|
10
|
my ($self) = @_; |
160
|
|
|
|
|
|
|
|
161
|
7
|
|
|
|
|
8
|
my $arrref = $self->{_HASHES}; |
162
|
7
|
|
|
|
|
11
|
my @arr = @$arrref; |
163
|
|
|
|
|
|
|
|
164
|
7
|
|
|
|
|
27
|
return $#arr; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub push |
170
|
|
|
|
|
|
|
{ |
171
|
3
|
|
|
3
|
0
|
100
|
my ($self, $val) = @_; |
172
|
3
|
|
|
|
|
5
|
return push @{$self->{_HASHES}}, $val; |
|
3
|
|
|
|
|
8
|
|
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub pop |
176
|
|
|
|
|
|
|
{ |
177
|
2
|
|
|
2
|
0
|
28
|
my ($self) = @_; |
178
|
2
|
|
|
|
|
2
|
return pop @{$self->{_HASHES}}; |
|
2
|
|
|
|
|
28
|
|
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub shift |
182
|
|
|
|
|
|
|
{ |
183
|
3
|
|
|
3
|
0
|
81
|
my ($self) = @_; |
184
|
3
|
|
|
|
|
3
|
return shift @{$self->{_HASHES}}; |
|
3
|
|
|
|
|
7
|
|
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub unshift |
188
|
|
|
|
|
|
|
{ |
189
|
1
|
|
|
1
|
0
|
26
|
my ($self, $val) = @_; |
190
|
1
|
|
|
|
|
2
|
return unshift @{$self->{_HASHES}}, $val; |
|
1
|
|
|
|
|
3
|
|
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
194
|
|
|
|
|
|
|
__END__ |