line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PseudoHash; |
2
|
|
|
|
|
|
|
$Class::PseudoHash::VERSION = '1.10'; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
30
|
use 5.005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
5
|
1
|
|
|
1
|
|
36
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
4
|
use vars qw/$FixedKeys $Obj $Proxy/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
7
|
1
|
|
|
1
|
|
4
|
use constant NO_SUCH_FIELD => 'No such pseudohash field "%s"'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
71
|
|
8
|
1
|
|
|
1
|
|
3
|
use constant NO_SUCH_INDEX => 'Bad index while coercing array into hash'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
210
|
|
9
|
|
|
|
|
|
|
use overload ( |
10
|
4
|
|
|
4
|
|
66
|
'%{}' => sub { $$Obj = $_[0]; return $Proxy }, |
|
4
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
7
|
'""' => sub { overload::AddrRef($_[0]) }, |
12
|
|
|
|
|
|
|
'0+' => sub { |
13
|
1
|
|
|
1
|
|
5
|
my $str = overload::AddrRef($_[0]); |
14
|
1
|
|
|
|
|
15
|
hex(substr($str, index($str, '(') + 1, -1)); |
15
|
|
|
|
|
|
|
}, |
16
|
1
|
|
|
1
|
|
15
|
'bool' => sub { 1 }, |
17
|
0
|
|
|
0
|
|
0
|
'cmp' => sub { "$_[0]" cmp "$_[1]" }, |
18
|
0
|
|
|
0
|
|
0
|
'<=>' => sub { "$_[0]" cmp "$_[1]" }, # for completeness' sake |
19
|
1
|
|
|
|
|
12
|
'fallback' => 1, |
20
|
1
|
|
|
1
|
|
1479
|
); |
|
1
|
|
|
|
|
1039
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$FixedKeys = 1; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub import { |
25
|
1
|
|
|
1
|
|
108
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
620
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
2
|
my $class = shift; |
28
|
1
|
|
|
|
|
2
|
tie %{$Proxy}, $class; |
|
1
|
|
|
|
|
5
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
40
|
*{'fields::phash'} = sub { |
31
|
1
|
|
|
1
|
|
11
|
$class->new(@_); |
32
|
1
|
50
|
|
|
|
8
|
} unless defined $_[0]; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
2
|
|
|
2
|
0
|
23
|
my $class = shift; |
37
|
2
|
|
|
|
|
6
|
my @array = undef; |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
|
|
|
12
|
if (UNIVERSAL::isa($_[0], 'ARRAY')) { |
40
|
2
|
|
|
|
|
3
|
foreach my $k (@{$_[0]}) { |
|
2
|
|
|
|
|
7
|
|
41
|
8
|
|
|
|
|
33
|
$array[$array[0]{$k} = @array] = $_[1][$#array]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
0
|
|
|
|
|
0
|
while (my ($k, $v) = splice(@_, 0, 2)) { |
46
|
0
|
|
|
|
|
0
|
$array[$array[0]{$k} = @array] = $v; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
11
|
bless(\@array, $class); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub FETCH { |
54
|
1
|
|
|
1
|
|
3
|
my ($self, $key) = @_; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
3
|
$self = $$$self; |
57
|
|
|
|
|
|
|
|
58
|
1
|
0
|
|
|
|
9
|
return $self->[ |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->[0]{$key} >= 1 |
60
|
|
|
|
|
|
|
? $self->[0]{$key} : |
61
|
|
|
|
|
|
|
defined($self->[0]{$key}) |
62
|
|
|
|
|
|
|
? _croak(NO_SUCH_INDEX) : |
63
|
|
|
|
|
|
|
$FixedKeys |
64
|
|
|
|
|
|
|
? _croak(NO_SUCH_FIELD, $key) : |
65
|
|
|
|
|
|
|
@$self |
66
|
|
|
|
|
|
|
]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub STORE { |
70
|
2
|
|
|
2
|
|
5
|
my ($self, $key, $value) = @_; |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
5
|
$self = $$$self; |
73
|
|
|
|
|
|
|
|
74
|
2
|
0
|
|
|
|
15
|
return $self->[ |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$self->[0]{$key} >= 1 |
76
|
|
|
|
|
|
|
? $self->[0]{$key} : |
77
|
|
|
|
|
|
|
defined($self->[0]{$key}) |
78
|
|
|
|
|
|
|
? _croak(NO_SUCH_INDEX) : |
79
|
|
|
|
|
|
|
$FixedKeys |
80
|
|
|
|
|
|
|
? _croak(NO_SUCH_FIELD, $key) : |
81
|
|
|
|
|
|
|
@$self |
82
|
|
|
|
|
|
|
] = $value; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _croak { |
86
|
0
|
|
|
0
|
|
0
|
require Carp; |
87
|
0
|
|
|
|
|
0
|
Carp::croak(sprintf(shift, @_)); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub TIEHASH { |
91
|
1
|
|
|
1
|
|
4
|
bless \$Obj => shift; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub FIRSTKEY { |
95
|
1
|
|
|
1
|
|
3
|
scalar keys %{$${$_[0]}->[0]}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
96
|
1
|
|
|
|
|
2
|
each %{$${$_[0]}->[0]}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub NEXTKEY { |
100
|
4
|
|
|
4
|
|
6
|
each %{$${$_[0]}->[0]}; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
22
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub EXISTS { |
104
|
0
|
|
|
0
|
|
|
exists $${$_[0]}->[0]{$_[1]}; |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub DELETE { |
108
|
0
|
|
|
0
|
|
|
delete $${$_[0]}->[0]{$_[1]}; |
|
0
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub CLEAR { |
112
|
0
|
|
|
0
|
|
|
@{$${$_[0]}} = (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |