line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Var::Pairs; |
2
|
21
|
|
|
21
|
|
1464761
|
use 5.014; |
|
21
|
|
|
|
|
290
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.004002'; |
5
|
|
|
|
|
|
|
|
6
|
21
|
|
|
21
|
|
131
|
use warnings; |
|
21
|
|
|
|
|
56
|
|
|
21
|
|
|
|
|
834
|
|
7
|
21
|
|
|
21
|
|
10023
|
no if $] >= 5.018, warnings => "experimental::smartmatch"; |
|
21
|
|
|
|
|
221
|
|
|
21
|
|
|
|
|
133
|
|
8
|
21
|
|
|
21
|
|
1772
|
use Carp; |
|
21
|
|
|
|
|
47
|
|
|
21
|
|
|
|
|
1475
|
|
9
|
21
|
|
|
21
|
|
9496
|
use Devel::Callsite; |
|
21
|
|
|
|
|
20328
|
|
|
21
|
|
|
|
|
1413
|
|
10
|
21
|
|
|
21
|
|
10722
|
use Scope::Upper qw< reap UP >; |
|
21
|
|
|
|
|
20327
|
|
|
21
|
|
|
|
|
1378
|
|
11
|
21
|
|
|
21
|
|
8965
|
use PadWalker qw< var_name >; |
|
21
|
|
|
|
|
12640
|
|
|
21
|
|
|
|
|
3640
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Check for autoboxing, and set up pairs() method if applicable.. |
14
|
|
|
|
|
|
|
my $autoboxing; |
15
|
|
|
|
|
|
|
BEGIN { |
16
|
21
|
50
|
|
21
|
|
81
|
if (eval{ require autobox }) { |
|
21
|
|
|
|
|
6437
|
|
17
|
0
|
|
|
|
|
0
|
$autoboxing = 1; |
18
|
0
|
|
|
|
|
0
|
push @Var::Pairs::ISA, 'autobox'; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::pairs = \&Var::Pairs::pairs; |
21
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::kvs = \&Var::Pairs::kvs; |
22
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::each_pair = \&Var::Pairs::each_pair; |
23
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::each_kv = \&Var::Pairs::each_kv; |
24
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::each_value = \&Var::Pairs::each_value; |
25
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::invert = \&Var::Pairs::invert; |
26
|
0
|
|
|
|
|
0
|
*Var::Pairs::autobox::invert_pairs = \&Var::Pairs::invert_pairs; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# API... |
31
|
|
|
|
|
|
|
my %EXPORTABLE; |
32
|
|
|
|
|
|
|
@EXPORTABLE{qw< pairs kvs each_pair each_kv each_value to_kv to_pair invert invert_pairs >} = (); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub import { |
35
|
21
|
|
|
21
|
|
192
|
my ($class, @exports) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Check for export requests... |
38
|
21
|
50
|
|
|
|
98
|
if (!@exports) { |
39
|
21
|
|
|
|
|
92
|
@exports = keys %EXPORTABLE; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
0
|
|
|
|
|
0
|
my @bad = grep { !exists $EXPORTABLE{$_} } @exports; |
|
0
|
|
|
|
|
0
|
|
43
|
0
|
0
|
|
|
|
0
|
carp 'Unknown subroutine' . (@bad==1 ? q{} : q{s}) . " requested: @bad" |
|
|
0
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if @bad; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Export API... |
48
|
21
|
|
|
21
|
|
162
|
no strict 'refs'; |
|
21
|
|
|
|
|
41
|
|
|
21
|
|
|
|
|
1323
|
|
49
|
21
|
|
|
|
|
323
|
my $caller = caller; |
50
|
21
|
|
|
|
|
56
|
for my $subname (@exports) { |
51
|
21
|
|
|
21
|
|
178
|
no strict 'refs'; |
|
21
|
|
|
|
|
56
|
|
|
21
|
|
|
|
|
42610
|
|
52
|
189
|
|
|
|
|
248
|
*{$caller.'::'.$subname} = \&{$subname}; |
|
189
|
|
|
|
|
1251
|
|
|
189
|
|
|
|
|
393
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Enable autoboxing of ->pairs() in caller's lexical scope, if possible... |
56
|
21
|
50
|
|
|
|
32378
|
if ($autoboxing) { |
57
|
0
|
|
|
|
|
0
|
$class->SUPER::import( |
58
|
|
|
|
|
|
|
HASH => 'Var::Pairs::autobox', |
59
|
|
|
|
|
|
|
ARRAY => 'Var::Pairs::autobox', |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Track iterators for each call... |
65
|
|
|
|
|
|
|
state %iterator_for; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Convert one or more vars into a ('varname', $varname,...) list... |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub to_kv (\[$@%];\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]) { |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Take each var ref and convert to 'name' => 'ref_or_val' pairs... |
72
|
5
|
|
|
5
|
1
|
149
|
return map { my $name = var_name(1, $_); $name =~ s/^.//; |
|
7
|
|
|
|
|
27
|
|
|
7
|
|
|
|
|
28
|
|
73
|
7
|
100
|
|
|
|
68
|
$name => (ref($_) =~ /SCALAR|REF/ ? $$_ : $_) |
74
|
|
|
|
|
|
|
} @_; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Convert one or more vars into 'varname' => $varname pairs... |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub to_pair (\[$@%];\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]) { |
80
|
|
|
|
|
|
|
|
81
|
9
|
|
|
9
|
1
|
116
|
return map { my $name = var_name(1, $_); $name =~ s/^.//; |
|
11
|
|
|
|
|
40
|
|
|
11
|
|
|
|
|
46
|
|
82
|
11
|
100
|
|
|
|
75
|
Var::Pairs::Pair->new($name => (ref($_) =~ /SCALAR|REF/ ? $$_ : $_), 'none') |
83
|
|
|
|
|
|
|
} @_; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Generate pairs for iterating hashes and arrays... |
88
|
|
|
|
|
|
|
sub pairs (+) { |
89
|
46
|
100
|
|
46
|
1
|
15253
|
if (!defined wantarray) { |
|
|
100
|
|
|
|
|
|
90
|
1
|
|
|
|
|
83
|
croak("Useless use of pairs() in void context"); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif (!wantarray) { |
93
|
1
|
|
|
|
|
84
|
croak("Invalid call to pairs() in scalar context.\nDid you mean each_pair()?\nError") |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
44
|
|
|
|
|
82
|
my $container_ref = shift; |
97
|
44
|
|
100
|
|
|
151
|
my $container_type = ref $container_ref || 'scalar value'; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Verify the single argument... |
100
|
44
|
100
|
|
|
|
196
|
if ($container_type !~ m{^ARRAY$|^HASH$}) { |
101
|
2
|
|
|
|
|
285
|
croak "Argument to pairs() must be array or hash (not \L$container_type\E)"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Uniquely identify this call, according to its lexical context... |
105
|
42
|
|
|
|
|
209
|
my $ID = callsite() . context() . $container_ref; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Short-circuit if this is a repeated call... |
108
|
42
|
0
|
33
|
|
|
122
|
if (!wantarray && $iterator_for{$ID}) { |
109
|
0
|
|
|
|
|
0
|
return _get_each_pair($ID); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Generate the list of pairs, according to the container type... |
113
|
42
|
|
|
|
|
83
|
my $container_is_array = $container_type eq 'ARRAY'; |
114
|
227
|
100
|
|
|
|
609
|
my @pairs = map { Var::Pairs::Pair->new($_, $container_ref, $container_is_array ? 'array' : 'hash') } |
115
|
42
|
100
|
|
|
|
100
|
$container_is_array ? 0..$#{$container_ref} : keys %{$container_ref}; |
|
29
|
|
|
|
|
68
|
|
|
13
|
|
|
|
|
49
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Return them all in list context... |
118
|
42
|
|
|
|
|
183
|
return @pairs; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# In scalar context, return the first pair, remembering the rest... |
121
|
0
|
|
|
|
|
0
|
$iterator_for{$ID} = \@pairs; |
122
|
0
|
|
|
|
|
0
|
return shift @pairs; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub each_pair (+) { |
126
|
134
|
|
|
134
|
1
|
1260
|
my ($container_ref) = @_; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Uniquely identify this call, according to its lexical context... |
129
|
134
|
50
|
33
|
|
|
937
|
my $ID = callsite() . context() . (ref($_[0]) && var_name(1,$_[0]) ? $container_ref : q{}); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Install a destructor for it at the send of the caller's block... |
132
|
21
|
100
|
|
21
|
|
1704
|
reap { delete $iterator_for{$ID} if exists $iterator_for{$ID} } UP UP |
133
|
134
|
100
|
|
|
|
474
|
if !$iterator_for{$ID}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Build an iterator... |
136
|
|
|
|
|
|
|
$iterator_for{$ID} //= ref($container_ref) eq 'CODE' |
137
|
|
|
|
|
|
|
? sub { |
138
|
0
|
|
|
0
|
|
0
|
state $n=0; |
139
|
0
|
0
|
|
|
|
0
|
my ($next) = $container_ref->() or return; |
140
|
0
|
|
|
|
|
0
|
return ($n++, $next); |
141
|
|
|
|
|
|
|
} |
142
|
134
|
50
|
66
|
|
|
327
|
: [ &pairs ]; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# Iterate... |
145
|
134
|
|
|
|
|
246
|
return _get_each_pair($ID); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Generate key, value,... lists for iterating hashes and arrays... |
149
|
|
|
|
|
|
|
sub kvs (+) { |
150
|
16
|
50
|
|
16
|
1
|
142
|
if (!defined wantarray) { |
|
|
50
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
croak("Useless use of kvs() in void context"); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
elsif (!wantarray) { |
154
|
0
|
|
|
|
|
0
|
croak("Invalid call to kvs() in scalar context.\nDid you mean each_kv()?\nError") |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
16
|
|
|
|
|
35
|
my $container_ref = shift; |
158
|
16
|
|
50
|
|
|
53
|
my $container_type = ref $container_ref || 'scalar value'; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# Verify the single argument... |
161
|
16
|
50
|
|
|
|
71
|
if ($container_type !~ m{^ARRAY$|^HASH$}) { |
162
|
0
|
|
|
|
|
0
|
croak "Argument to pairs() must be array or hash (not \L$container_type\E)"; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# Uniquely identify this call, according to its lexical context... |
166
|
16
|
|
|
|
|
72
|
my $ID = callsite() . context() . $container_ref; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Return the key/value list, according to the container type... |
169
|
16
|
100
|
|
|
|
45
|
if ($container_type eq 'ARRAY') { |
170
|
14
|
|
|
|
|
30
|
return map { ($_, $container_ref->[$_]) } 0..$#{$container_ref}; |
|
84
|
|
|
|
|
210
|
|
|
14
|
|
|
|
|
37
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else { |
173
|
2
|
|
|
|
|
5
|
return %{$container_ref}; |
|
2
|
|
|
|
|
14
|
|
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub each_kv (+) { |
178
|
91
|
|
|
91
|
1
|
29344
|
my ($container_ref) = @_; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Uniquely identify this call, according to its lexical context and iteration target... |
181
|
91
|
50
|
33
|
|
|
700
|
my $ID = callsite() . context() . (ref($_[0]) && var_name(1,$_[0]) ? $container_ref : q{}); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# Install a destructor for it at the send of the caller's block... |
184
|
15
|
100
|
|
15
|
|
2075
|
reap { delete $iterator_for{$ID} if exists $iterator_for{$ID} } UP UP |
185
|
91
|
100
|
|
|
|
372
|
if !$iterator_for{$ID}; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$iterator_for{$ID} //= ref($container_ref) eq 'CODE' |
188
|
|
|
|
|
|
|
? sub { |
189
|
0
|
|
|
0
|
|
0
|
state $n=0; |
190
|
0
|
0
|
|
|
|
0
|
my ($next) = $container_ref->() or return; |
191
|
0
|
|
|
|
|
0
|
return ($n++, $next); |
192
|
|
|
|
|
|
|
} |
193
|
91
|
50
|
66
|
|
|
237
|
: [ &kvs ]; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# Iterate... |
196
|
91
|
|
|
|
|
173
|
return _get_each_kv($ID); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# Iterate just the values of a container... |
200
|
|
|
|
|
|
|
sub each_value (+) { |
201
|
0
|
|
|
0
|
1
|
0
|
my ($container_ref) = @_; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Uniquely identify this call, according to its lexical context and iteration target... |
204
|
0
|
0
|
0
|
|
|
0
|
my $ID = callsite() . context() . (ref($_[0]) && var_name(1,$_[0]) ? $container_ref : q{}); |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Install a destructor for it at the send of the caller's block... |
207
|
0
|
0
|
|
0
|
|
0
|
reap { delete $iterator_for{$ID} if exists $iterator_for{$ID} } UP UP |
208
|
0
|
0
|
|
|
|
0
|
if !$iterator_for{$ID}; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
$iterator_for{$ID} //= ref($container_ref) eq 'CODE' |
211
|
|
|
|
|
|
|
? sub { |
212
|
0
|
|
|
0
|
|
0
|
state $n=0; |
213
|
0
|
0
|
|
|
|
0
|
my ($next) = $container_ref->() or return; |
214
|
0
|
|
|
|
|
0
|
return ($n++, $next); |
215
|
|
|
|
|
|
|
} |
216
|
0
|
0
|
0
|
|
|
0
|
: [ &kvs ]; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Iterate... |
219
|
0
|
0
|
|
|
|
0
|
my @next = _get_each_kv($ID) or return; |
220
|
0
|
|
|
|
|
0
|
return $next[1]; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Invert the key=>values of a hash or array... |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub invert (+) { |
226
|
0
|
|
|
0
|
1
|
0
|
goto &_invert; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub invert_pairs (+) { |
230
|
0
|
|
|
0
|
1
|
0
|
push @_, 1; |
231
|
0
|
|
|
|
|
0
|
goto &_invert; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# Utilities... |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# Perform var inversions... |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub _invert { |
240
|
0
|
|
|
0
|
|
0
|
my ($var_ref, $return_as_pairs) = @_; |
241
|
0
|
|
|
|
|
0
|
my %inversion; |
242
|
|
|
|
|
|
|
|
243
|
0
|
0
|
|
|
|
0
|
if (!defined wantarray) { |
|
|
0
|
|
|
|
|
|
244
|
0
|
|
|
|
|
0
|
croak 'Useless use of invert() in void context'; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
elsif (!wantarray) { |
247
|
0
|
|
|
|
|
0
|
croak 'Invalid call to invert() in scalar context'; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
0
|
|
|
0
|
for my $var_type (ref($var_ref) || 'SCALAR') { |
251
|
0
|
0
|
|
|
|
0
|
if ($var_type eq 'HASH') { |
|
|
0
|
|
|
|
|
|
252
|
0
|
|
|
|
|
0
|
for my $key (keys %{$var_ref}) { |
|
0
|
|
|
|
|
0
|
|
253
|
0
|
|
|
|
|
0
|
my $values = $var_ref->{$key}; |
254
|
0
|
0
|
|
|
|
0
|
for my $value ( ref $values eq 'ARRAY' ? @$values : $values ) { |
255
|
0
|
|
0
|
|
|
0
|
$inversion{$value} //= []; |
256
|
0
|
|
|
|
|
0
|
push @{$inversion{$value}}, $key; |
|
0
|
|
|
|
|
0
|
|
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
elsif ($var_type eq 'ARRAY') { |
261
|
0
|
|
|
|
|
0
|
for my $key (0..$#{$var_ref}) { |
|
0
|
|
|
|
|
0
|
|
262
|
0
|
|
|
|
|
0
|
my $values = $var_ref->[$key]; |
263
|
0
|
0
|
|
|
|
0
|
for my $value ( ref $values eq 'ARRAY' ? @$values : $values ) { |
264
|
0
|
|
0
|
|
|
0
|
$inversion{$value} //= []; |
265
|
0
|
|
|
|
|
0
|
push @{$inversion{$value}}, $key; |
|
0
|
|
|
|
|
0
|
|
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
else { |
270
|
0
|
|
|
|
|
0
|
croak "Argument to invert() must be hash or array (not \L$_\E)"; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
0
|
0
|
|
|
|
0
|
return $return_as_pairs ? pairs %inversion : %inversion; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
# Iterate, cleaning up if appropriate... |
278
|
|
|
|
|
|
|
sub _get_each_pair { |
279
|
134
|
|
|
134
|
|
190
|
my $ID = shift; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# Iterate the requested iterator... |
282
|
134
|
|
|
|
|
194
|
my $iterator = $iterator_for{$ID}; |
283
|
134
|
|
|
|
|
197
|
my $each_pair; |
284
|
134
|
50
|
|
|
|
278
|
if (ref($iterator) eq 'CODE') { |
285
|
0
|
|
|
|
|
0
|
my @kv = $iterator->(); |
286
|
0
|
0
|
|
|
|
0
|
$each_pair = Var::Pairs::Pair->new(@kv, 'none') if @kv; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
else { |
289
|
134
|
|
|
|
|
162
|
$each_pair = shift @{$iterator}; |
|
134
|
|
|
|
|
209
|
|
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# If nothing was left to iterate, clean up the empty iterator... |
293
|
134
|
100
|
|
|
|
292
|
if (!defined $each_pair) { |
294
|
18
|
|
|
|
|
36
|
delete $iterator_for{$ID}; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
134
|
|
|
|
|
296
|
return $each_pair; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
sub _get_each_kv { |
301
|
91
|
|
|
91
|
|
135
|
my $ID = shift; |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# Iterate the requested iterator... |
304
|
91
|
|
|
|
|
124
|
my $iterator = $iterator_for{$ID}; |
305
|
|
|
|
|
|
|
my @each_kv = ref($iterator) eq 'CODE' |
306
|
|
|
|
|
|
|
? $iterator->() |
307
|
91
|
50
|
|
|
|
177
|
: splice @{$iterator}, 0, 2; |
|
91
|
|
|
|
|
173
|
|
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# If nothing was left to iterate, clean up the empty iterator... |
310
|
91
|
100
|
|
|
|
182
|
if (!@each_kv) { |
311
|
11
|
|
|
|
|
24
|
delete $iterator_for{$ID}; |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# Return key or key/value, as appropriate (a la each())... |
315
|
91
|
50
|
|
|
|
383
|
return wantarray ? @each_kv : $each_kv[0]; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
21
|
|
|
21
|
|
214
|
use if $] < 5.022, 'Var::Pairs::Pair_DataAlias'; |
|
21
|
|
|
|
|
55
|
|
|
21
|
|
|
|
|
193
|
|
319
|
21
|
|
|
21
|
|
1052
|
use if $] >= 5.022, 'Var::Pairs::Pair_BuiltIn'; |
|
21
|
|
|
|
|
75
|
|
|
21
|
|
|
|
|
161
|
|
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
322
|
|
|
|
|
|
|
__END__ |