line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Enumerator::Array; |
2
|
5
|
|
|
5
|
|
37
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
217
|
|
3
|
5
|
|
|
5
|
|
30
|
use warnings; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
189
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
28
|
use base qw/List::Enumerator::Role/; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
72553
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
5
|
|
|
|
|
74
|
'<<' => \&push, |
8
|
|
|
|
|
|
|
'+' => \&add, |
9
|
|
|
|
|
|
|
'@{}' => \&to_a, |
10
|
5
|
|
|
5
|
|
56
|
fallback => 1; |
|
5
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
541
|
no warnings 'once'; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
6123
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/array index/); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub BUILD { |
17
|
316
|
|
|
316
|
0
|
447
|
my ($self) = @_; |
18
|
316
|
50
|
|
|
|
849
|
$self->array([]) unless $self->array; |
19
|
316
|
|
|
|
|
23387
|
$self->index(0); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _next { |
23
|
267
|
|
|
267
|
|
393
|
my ($self) = @_; |
24
|
|
|
|
|
|
|
|
25
|
267
|
|
|
|
|
810
|
my $i = $self->index; |
26
|
|
|
|
|
|
|
|
27
|
267
|
100
|
|
|
|
999
|
if ($i < @{$self->array}) { |
|
267
|
|
|
|
|
633
|
|
28
|
217
|
|
|
|
|
1469
|
$self->index($i + 1); |
29
|
217
|
|
|
|
|
1221
|
$self->array->[$i]; |
30
|
|
|
|
|
|
|
} else { |
31
|
50
|
|
|
|
|
466
|
$self->stop; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _rewind { |
36
|
18
|
|
|
18
|
|
34
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
58
|
$self->index(0); |
39
|
18
|
|
|
|
|
103
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub to_a { |
43
|
199
|
|
|
199
|
0
|
464
|
my ($self) = @_; |
44
|
199
|
|
|
|
|
536
|
$self->array; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
*as_list = \&to_a; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub to_list { |
49
|
209
|
|
|
209
|
0
|
287
|
my ($self) = @_; |
50
|
209
|
|
|
|
|
225
|
@{$self->array}; |
|
209
|
|
|
|
|
507
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub push { |
54
|
2
|
|
|
2
|
0
|
14
|
my ($self, @args) = @_; |
55
|
2
|
|
|
|
|
3
|
CORE::push @{$self->array}, @args; |
|
2
|
|
|
|
|
8
|
|
56
|
2
|
|
|
|
|
15
|
$self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub add { |
60
|
2
|
|
|
2
|
0
|
18
|
my ($self, $array, $bool) = @_; |
61
|
1
|
|
|
|
|
5
|
$bool ? [ @$array, @{$self->array} ] |
|
1
|
|
|
|
|
5
|
|
62
|
2
|
100
|
|
|
|
8
|
: [ @{$self->array}, @$array ]; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub unshift { |
66
|
2
|
|
|
2
|
0
|
16
|
my ($self, @args) = @_; |
67
|
2
|
|
|
|
|
3
|
CORE::unshift @{$self->array}, @args; |
|
2
|
|
|
|
|
8
|
|
68
|
2
|
|
|
|
|
14
|
$self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub prepend { |
72
|
2
|
|
|
2
|
0
|
18
|
my ($self, $args) = @_; |
73
|
2
|
|
|
|
|
4
|
CORE::unshift @{$self->array}, @$args; |
|
2
|
|
|
|
|
9
|
|
74
|
2
|
|
|
|
|
17
|
$self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub concat { |
78
|
4
|
|
|
4
|
0
|
26
|
my ($self, $args) = @_; |
79
|
4
|
|
|
|
|
6
|
CORE::push @{$self->array}, @$args; |
|
4
|
|
|
|
|
14
|
|
80
|
4
|
|
|
|
|
29
|
$self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
*append = \&concat; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub shift { |
85
|
1
|
|
|
1
|
0
|
7
|
my ($self) = @_; |
86
|
1
|
|
|
|
|
2
|
CORE::shift @{$self->array}; |
|
1
|
|
|
|
|
62
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub pop { |
90
|
1
|
|
|
1
|
0
|
7
|
my ($self) = @_; |
91
|
1
|
|
|
|
|
3
|
CORE::pop @{$self->array}; |
|
1
|
|
|
|
|
4
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub delete { |
95
|
2
|
|
|
2
|
0
|
19
|
my ($self, $target, $block) = @_; |
96
|
2
|
|
|
|
|
6
|
my $ret = []; |
97
|
2
|
|
|
|
|
3
|
for (0 .. $#{$self->array}) { |
|
2
|
|
|
|
|
11
|
|
98
|
8
|
|
|
|
|
45
|
my $item = CORE::shift @{$self->array}; |
|
8
|
|
|
|
|
19
|
|
99
|
8
|
100
|
|
|
|
46
|
if ($item eq $target) { |
100
|
2
|
|
|
|
|
6
|
CORE::push @$ret, $self->array->[$_]; |
101
|
|
|
|
|
|
|
} else { |
102
|
6
|
|
|
|
|
10
|
CORE::push @{$self->array}, $item; |
|
6
|
|
|
|
|
15
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
2
|
50
|
|
|
|
31
|
@$ret ? $target |
|
|
100
|
|
|
|
|
|
106
|
|
|
|
|
|
|
: ref($block) eq "CODE" ? $block->(local $_ = $target) |
107
|
|
|
|
|
|
|
: undef; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub delete_if { |
111
|
1
|
|
|
1
|
0
|
10
|
my ($self, $block) = @_; |
112
|
1
|
|
|
|
|
2
|
my $ret = []; |
113
|
1
|
|
|
|
|
3
|
for my $index (0 .. $#{$self->array}) { |
|
1
|
|
|
|
|
5
|
|
114
|
5
|
|
|
|
|
20
|
my $item = CORE::shift @{$self->array}; |
|
5
|
|
|
|
|
14
|
|
115
|
5
|
100
|
|
|
|
27
|
if ($block->(local $_ = $item)) { |
116
|
2
|
|
|
|
|
11
|
CORE::push @$ret, $item; |
117
|
|
|
|
|
|
|
} else { |
118
|
3
|
|
|
|
|
12
|
CORE::push @{$self->array}, $item; |
|
3
|
|
|
|
|
8
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
1
|
50
|
|
|
|
12
|
wantarray? @$ret : List::Enumerator::Array->new(array => $ret); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub delete_at { |
125
|
3
|
|
|
3
|
0
|
19
|
my ($self, $index) = @_; |
126
|
3
|
100
|
|
|
|
7
|
return if $index > $#{$self->array}; |
|
3
|
|
|
|
|
10
|
|
127
|
2
|
|
|
|
|
16
|
my $ret; |
128
|
2
|
|
|
|
|
3
|
for (0 .. $#{$self->array}) { |
|
2
|
|
|
|
|
7
|
|
129
|
9
|
|
|
|
|
49
|
my $item = CORE::shift @{$self->array}; |
|
9
|
|
|
|
|
24
|
|
130
|
9
|
100
|
|
|
|
46
|
if ($_ == $index) { |
131
|
2
|
|
|
|
|
5
|
$ret = $item; |
132
|
|
|
|
|
|
|
} else { |
133
|
7
|
|
|
|
|
8
|
CORE::push @{$self->array}, $item; |
|
7
|
|
|
|
|
17
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
2
|
|
|
|
|
19
|
$ret; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# for performance |
140
|
|
|
|
|
|
|
sub each { |
141
|
13
|
|
|
13
|
0
|
53
|
my ($self, $block) = @_; |
142
|
13
|
|
|
|
|
52
|
$self->rewind; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
13
|
50
|
|
|
|
33
|
if ($block) { |
146
|
13
|
|
|
|
|
58
|
eval { |
147
|
13
|
|
|
|
|
149
|
for (@{ $self->array }) { |
|
13
|
|
|
|
|
40
|
|
148
|
32
|
|
|
|
|
181
|
$block->(local $_ = $_); |
149
|
|
|
|
|
|
|
} |
150
|
13
|
100
|
|
|
|
4354
|
}; if (Exception::Class->caught("StopIteration") ) { } else { |
151
|
6
|
|
|
|
|
50
|
my $e = Exception::Class->caught(); |
152
|
6
|
0
|
|
|
|
183
|
ref $e ? $e->rethrow : die $e if $e; |
|
|
50
|
|
|
|
|
|
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
13
|
|
|
|
|
481
|
$self; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub map { |
160
|
5
|
|
|
5
|
0
|
35
|
my ($self, $block) = @_; |
161
|
5
|
|
|
|
|
22
|
$self->rewind; |
162
|
5
|
|
|
|
|
7
|
my @ret; |
163
|
|
|
|
|
|
|
|
164
|
5
|
|
|
|
|
11
|
@ret = CORE::map({ $block->(local $_ = $_) } @{ $self->array }); |
|
15
|
|
|
|
|
86
|
|
|
5
|
|
|
|
|
17
|
|
165
|
|
|
|
|
|
|
|
166
|
5
|
100
|
|
|
|
75
|
wantarray? @ret : List::Enumerator::Array->new(array => \@ret); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
__END__ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|