line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Syntax::Feature::EachOnArray; # don't confuse dzil? |
2
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
3
|
|
|
|
|
|
|
# BEGIN PORTION (c) Toby Inkster |
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
package Tie::ArrayAsHash; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
55101
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
94
|
|
8
|
3
|
|
|
3
|
|
16
|
no warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
93
|
|
9
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
225
|
|
10
|
3
|
|
|
3
|
|
2544
|
use Hash::FieldHash qw(fieldhash); |
|
3
|
|
|
|
|
6537
|
|
|
3
|
|
|
|
|
222
|
|
11
|
3
|
|
|
3
|
|
116
|
use Scalar::Util qw(reftype); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
148
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
17
|
use base qw(Exporter); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
370
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
3
|
|
|
3
|
|
9
|
our @EXPORT_OK = 'aeach'; |
16
|
3
|
|
|
|
|
82
|
$INC{'Tie/ArrayAsHash.pm'} = __FILE__; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use constant { |
20
|
3
|
|
|
|
|
2622
|
IDX_DATA => 0, |
21
|
|
|
|
|
|
|
IDX_EACH => 1, |
22
|
|
|
|
|
|
|
NEXT_IDX => 2, |
23
|
3
|
|
|
3
|
|
37
|
}; |
|
3
|
|
|
|
|
6
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
fieldhash our %cache; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub aeach (\[@%]) |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
0
|
0
|
my $thing = shift; |
30
|
0
|
0
|
|
|
|
0
|
return each %$thing |
31
|
|
|
|
|
|
|
if reftype $thing eq 'HASH'; |
32
|
0
|
0
|
|
|
|
0
|
confess "should be passed a HASH or ARRAY" |
33
|
|
|
|
|
|
|
unless reftype $thing eq 'ARRAY'; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
0
|
|
|
0
|
my $thing_h = $cache{$thing} ||= do { |
36
|
0
|
|
|
|
|
0
|
tie my %h, __PACKAGE__, $thing; |
37
|
0
|
|
|
|
|
0
|
\%h |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
each %$thing_h; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub TIEHASH |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
0
|
|
0
|
my ($class, $arrayref) = @_; |
46
|
0
|
|
|
|
|
0
|
bless [$arrayref, 0] => $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub STORE |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
|
0
|
my ($self, $k, $v) = @_; |
52
|
0
|
|
|
|
|
0
|
$self->[IDX_DATA][$k] = $v; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub FETCH |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
|
0
|
my ($self, $k) = @_; |
58
|
0
|
|
|
|
|
0
|
$self->[IDX_DATA][$k]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub FIRSTKEY |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
64
|
0
|
|
|
|
|
0
|
$self->[IDX_EACH] = 0; |
65
|
0
|
|
|
|
|
0
|
$self->NEXTKEY; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub NEXTKEY |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
71
|
0
|
|
|
|
|
0
|
my $curr = $self->[IDX_EACH]++; |
72
|
0
|
0
|
|
|
|
0
|
return if $curr >= @{ $self->[IDX_DATA] }; |
|
0
|
|
|
|
|
0
|
|
73
|
0
|
|
|
|
|
0
|
return $curr; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub EXISTS |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
0
|
|
0
|
my ($self, $k) = @_; |
79
|
|
|
|
|
|
|
!!($k eq $k+0 |
80
|
0
|
|
0
|
|
|
0
|
and $k < @{ $self->[IDX_DATA] } |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub DELETE |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
0
|
|
0
|
my ($self, $k) = @_; |
87
|
0
|
|
|
|
|
0
|
return pop @{ $self->[IDX_DATA] } |
|
0
|
|
|
|
|
0
|
|
88
|
0
|
0
|
|
|
|
0
|
if @{ $self->[IDX_DATA] } == $k + 1; |
89
|
0
|
|
|
|
|
0
|
confess "DELETE not fully implemented"; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub CLEAR |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
95
|
0
|
|
|
|
|
0
|
$self->[IDX_DATA] = []; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub SCALAR |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
101
|
0
|
|
|
|
|
0
|
my %tmp = |
102
|
0
|
|
|
|
|
0
|
map { $_ => $self->[IDX_DATA][$_] } |
103
|
0
|
|
|
|
|
0
|
0 .. $#{ $self->[IDX_DATA] }; |
104
|
0
|
|
|
|
|
0
|
return scalar(%tmp); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
# END PORTION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
package Syntax::Feature::EachOnArray; |
110
|
|
|
|
|
|
|
|
111
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
94
|
|
112
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
104
|
|
113
|
3
|
|
|
3
|
|
15
|
use Tie::ArrayAsHash qw(aeach); |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
257
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub install { |
116
|
1
|
|
|
1
|
0
|
8
|
my $class = shift; |
117
|
1
|
|
|
|
|
5
|
my %args = @_; |
118
|
|
|
|
|
|
|
|
119
|
1
|
50
|
|
|
|
23
|
return unless $^V lt 5.12.0; |
120
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
37
|
|
|
3
|
|
|
|
|
234
|
|
121
|
0
|
|
|
|
|
|
*{"$args{into}::each"} = \&aeach; |
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# XXX on uninstall, delete symbol |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
# ABSTRACT: Emulate each(@array) on Perl < 5.12 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |