line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
21900
|
use 5.008; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
202
|
|
2
|
5
|
|
|
5
|
|
31
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
168
|
|
3
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
464
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
package Tie::Hash::MultiValueOrdered; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
9
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use constant { |
12
|
5
|
|
|
|
|
928
|
IDX_DATA => 0, |
13
|
|
|
|
|
|
|
IDX_ORDER => 1, |
14
|
|
|
|
|
|
|
IDX_LAST => 2, |
15
|
|
|
|
|
|
|
IDX_SEEN => 3, |
16
|
|
|
|
|
|
|
IDX_MODE => 4, |
17
|
|
|
|
|
|
|
NEXT_IDX => 5, |
18
|
5
|
|
|
5
|
|
29
|
}; |
|
5
|
|
|
|
|
7
|
|
19
|
|
|
|
|
|
|
use constant { |
20
|
5
|
|
|
|
|
1252
|
MODE_LAST => -1, |
21
|
|
|
|
|
|
|
MODE_FIRST => 0, |
22
|
|
|
|
|
|
|
MODE_REF => 'ref', |
23
|
|
|
|
|
|
|
MODE_ITER => 'iter', |
24
|
5
|
|
|
5
|
|
28
|
}; |
|
5
|
|
|
|
|
10
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
1
|
24
|
sub fetch_first { $_[0][IDX_MODE] = MODE_FIRST } |
27
|
1
|
|
|
1
|
1
|
2
|
sub fetch_last { $_[0][IDX_MODE] = MODE_LAST } |
28
|
3
|
|
|
3
|
1
|
929
|
sub fetch_list { $_[0][IDX_MODE] = MODE_REF } |
29
|
0
|
|
|
0
|
1
|
0
|
sub fetch_iterator { $_[0][IDX_MODE] = MODE_ITER } |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
5
|
|
7183
|
use Storable qw( dclone ); |
|
5
|
|
|
|
|
20942
|
|
|
5
|
|
|
|
|
3422
|
|
32
|
|
|
|
|
|
|
sub TIEHASH { |
33
|
7
|
|
|
7
|
|
25
|
my $class = shift; |
34
|
7
|
|
|
|
|
43
|
bless [{}, [], 0, {}, -1], $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
sub STORE { |
37
|
22
|
|
|
22
|
|
68
|
my ($tied, $key, $value) = @_; |
38
|
22
|
|
|
|
|
27
|
$key = "$key"; |
39
|
22
|
|
|
|
|
26
|
push @{$tied->[IDX_ORDER]}, $key; |
|
22
|
|
|
|
|
153
|
|
40
|
22
|
|
|
|
|
27
|
push @{$tied->[IDX_DATA]{$key}}, $value; |
|
22
|
|
|
|
|
99
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
sub FETCH { |
43
|
10
|
|
|
10
|
|
48
|
my ($tied, $key) = @_; |
44
|
10
|
|
|
|
|
15
|
my $mode = $tied->[IDX_MODE]; |
45
|
10
|
100
|
|
|
|
34
|
if ($mode eq 'ref') |
|
|
50
|
|
|
|
|
|
46
|
|
|
|
|
|
|
{ |
47
|
4
|
|
50
|
|
|
71
|
return $tied->[IDX_DATA]{$key} || []; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($mode eq 'iter') |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
0
|
|
|
|
0
|
my @values = @{ $tied->[IDX_DATA]{$key} || [] }; |
|
0
|
|
|
|
|
0
|
|
52
|
0
|
|
|
0
|
|
0
|
return sub { shift @values }; |
|
0
|
|
|
|
|
0
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else |
55
|
|
|
|
|
|
|
{ |
56
|
6
|
50
|
|
|
|
24
|
return unless exists $tied->[IDX_DATA]{"$key"}; |
57
|
6
|
|
|
|
|
32
|
return $tied->[IDX_DATA]{$key}[$mode]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub EXISTS { |
61
|
4
|
|
|
4
|
|
56
|
my ($tied, $key) = @_; |
62
|
4
|
|
|
|
|
16
|
return exists $tied->[IDX_DATA]{"$key"}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
sub DELETE { |
65
|
0
|
|
|
0
|
|
0
|
my ($tied, $key) = @_; |
66
|
0
|
|
|
|
|
0
|
my $r = delete $tied->[IDX_DATA]{"$key"}; |
67
|
0
|
0
|
|
|
|
0
|
return $r->[-1] if $r; |
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
sub CLEAR { |
71
|
0
|
|
|
0
|
|
0
|
my $tied = shift; |
72
|
0
|
|
|
|
|
0
|
$tied->[IDX_DATA] = {}; |
73
|
0
|
|
|
|
|
0
|
$tied->[IDX_ORDER] = []; |
74
|
0
|
|
|
|
|
0
|
$tied->[IDX_LAST] = 0; |
75
|
0
|
|
|
|
|
0
|
$tied->[IDX_SEEN] = {}; |
76
|
0
|
|
|
|
|
0
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
sub FIRSTKEY { |
79
|
7
|
|
|
7
|
|
804
|
my $tied = shift; |
80
|
7
|
|
|
|
|
16
|
$tied->[IDX_LAST] = -1; |
81
|
7
|
|
|
|
|
22
|
$tied->[IDX_SEEN] = {}; |
82
|
7
|
|
|
|
|
27
|
return $tied->NEXTKEY; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
sub NEXTKEY { |
85
|
5
|
|
|
5
|
|
54
|
no warnings qw(uninitialized); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
10234
|
|
86
|
19
|
|
|
19
|
|
27
|
my $tied = shift; |
87
|
19
|
|
|
|
|
36
|
my $i = ++$tied->[IDX_LAST]; |
88
|
19
|
|
|
|
|
82
|
$i++ while $tied->[IDX_SEEN]{ $tied->[IDX_ORDER][$i] }; |
89
|
19
|
|
|
|
|
46
|
$tied->[IDX_SEEN]{ $tied->[IDX_ORDER][$i] }++; |
90
|
19
|
|
|
|
|
34
|
my $key = $tied->[IDX_ORDER][$i]; |
91
|
19
|
50
|
|
|
|
41
|
if (wantarray) { |
92
|
|
|
|
|
|
|
return ( |
93
|
0
|
|
|
|
|
0
|
$tied->[IDX_ORDER][$i], |
94
|
|
|
|
|
|
|
$tied->FETCH( $tied->[IDX_ORDER][$i] ), |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
19
|
|
|
|
|
97
|
return $tied->[IDX_ORDER][$i]; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
sub get { |
100
|
1
|
|
|
1
|
1
|
605
|
my ($tied, $key) = @_; |
101
|
1
|
50
|
|
|
|
2
|
return my @list = @{ $tied->[IDX_DATA]{"$key"} || [] }; |
|
1
|
|
|
|
|
13
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
sub pairs { |
104
|
5
|
|
|
5
|
1
|
7
|
my $tied = shift; |
105
|
5
|
|
|
|
|
512
|
my $clone = dclone( $tied->[IDX_DATA] ); |
106
|
18
|
|
|
|
|
63
|
return map { |
107
|
18
|
|
|
|
|
19
|
$_, shift @{$clone->{$_}} |
|
5
|
|
|
|
|
12
|
|
108
|
5
|
|
|
|
|
9
|
} @{$tied->[IDX_ORDER]} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
sub pair_refs { |
111
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
112
|
0
|
|
|
|
|
|
my $clone = dclone( $tied->[IDX_DATA] ); |
113
|
0
|
|
|
|
|
|
return map { |
114
|
0
|
|
|
|
|
|
[ $_, shift @{$clone->{$_}} ] |
|
0
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
} @{$tied->[IDX_ORDER]} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
sub all_keys { |
118
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
119
|
0
|
|
|
|
|
|
return @{$tied->[IDX_ORDER]}; |
|
0
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
sub keys { |
122
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
123
|
0
|
|
|
|
|
|
my %seen; |
124
|
0
|
|
|
|
|
|
return grep { not $seen{$_}++ } @{$tied->[IDX_ORDER]}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
sub rr_keys { |
127
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
128
|
0
|
|
|
|
|
|
my %seen; |
129
|
0
|
|
|
|
|
|
return reverse grep { not $seen{$_}++ } reverse @{$tied->[IDX_ORDER]}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
sub all_values { |
132
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
133
|
0
|
|
|
|
|
|
my $alt = 1; |
134
|
0
|
|
|
|
|
|
return grep { $alt=!$alt } $tied->pairs; |
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
sub values { |
137
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
138
|
0
|
|
|
|
|
|
return map { $tied->[IDX_DATA]{$_}[-1] } $tied->keys; |
|
0
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
sub rr_values { |
141
|
0
|
|
|
0
|
1
|
|
my $tied = shift; |
142
|
0
|
|
|
|
|
|
return map { $tied->[IDX_DATA]{$_}[0] } $tied->keys; |
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |