line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright 2000 M-J. Dominus and the Mad Hungarian Software Works |
4
|
|
|
|
|
|
|
# Unauthorized distribution strictly prohibited |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package ArrayHashMonster; |
8
|
|
|
|
|
|
|
$VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
0
|
121
|
my ($pack, $acode, $hcode) = @_; |
12
|
1
|
|
|
|
|
134
|
my $hash = new ArrayHashMonster::Siphuncle; |
13
|
1
|
|
|
|
|
2
|
my @a; |
14
|
1
|
|
|
|
|
4
|
tie @a => $pack, $hash, $acode, $hcode; |
15
|
1
|
|
|
|
|
5
|
\@a; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub TIEARRAY { |
19
|
1
|
|
|
1
|
|
3
|
my ($pack, $hash, $acode, $hcode) = @_; |
20
|
1
|
|
|
|
|
1
|
my $flag = undef; |
21
|
1
|
|
|
|
|
6
|
my $self = {FLAG => \$flag, HASH => $hash, ACODE => $acode, HCODE => $hcode}; |
22
|
1
|
|
|
|
|
6
|
(tied %$hash)->set_flag(\$flag); |
23
|
1
|
|
|
|
|
3
|
bless $self => $pack; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub FETCH { |
27
|
1
|
|
|
1
|
|
9
|
my ($self, $key) = @_; |
28
|
1
|
50
|
|
|
|
6
|
print "ARRAY FETCH on $self with key $key; flag is $ {$self->{FLAG}}\n" |
|
0
|
|
|
|
|
0
|
|
29
|
|
|
|
|
|
|
if $::DEBUG; |
30
|
1
|
50
|
|
|
|
5
|
return $self->{HASH} if $key == 0; |
31
|
1
|
50
|
|
|
|
2
|
if (defined $ {$self->{FLAG}}) { |
|
1
|
|
|
|
|
8
|
|
32
|
0
|
|
|
|
|
0
|
my $rv = $self->{HCODE}->($ {$self->{FLAG}}); |
|
0
|
|
|
|
|
0
|
|
33
|
0
|
|
|
|
|
0
|
undef $ {$self->{FLAG}}; |
|
0
|
|
|
|
|
0
|
|
34
|
0
|
|
|
|
|
0
|
return $rv; |
35
|
|
|
|
|
|
|
} else { |
36
|
1
|
|
|
|
|
5
|
return $self->{ACODE}->($key); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
package ArrayHashMonster::Siphuncle; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
1
|
|
|
1
|
|
2
|
my ($pack) = @_; |
44
|
1
|
|
|
|
|
3
|
my %h; |
45
|
1
|
|
|
|
|
16
|
tie %h => $pack; |
46
|
1
|
|
|
|
|
3
|
return \%h; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set_flag { |
50
|
1
|
|
|
1
|
|
2
|
my ($self, $flagref) = @_; |
51
|
1
|
|
|
|
|
8
|
$self->{FLAG} = $flagref; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub TIEHASH { |
55
|
1
|
|
|
1
|
|
3
|
my ($pack) = @_; |
56
|
1
|
|
|
|
|
3
|
my $self = {FLAG => undef}; |
57
|
1
|
|
|
|
|
6
|
bless $self => $pack; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub FETCH { |
61
|
0
|
|
|
0
|
|
|
my ($self, $key) = @_; |
62
|
0
|
0
|
|
|
|
|
print "HASH FETCH on $self with key $key\n" if $::DEBUG; |
63
|
0
|
|
|
|
|
|
${$self->{FLAG}} = $key; |
|
0
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |