line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Role::TinyCommons::Iterator::Resettable; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
865
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use Role::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
142
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
304
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
8
|
|
|
|
|
|
|
our $DATE = '2021-10-07'; # DATE |
9
|
|
|
|
|
|
|
our $DIST = 'RoleBundle-TinyCommons-Iterator'; # DIST |
10
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Role::TinyCommons::Iterator::Basic'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
### required |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
requires 'reset_iterator'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
### provided |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get_all_items { |
21
|
1
|
|
|
1
|
1
|
5312
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
5
|
$self->reset_iterator; |
24
|
1
|
|
|
|
|
6
|
my @items; |
25
|
1
|
|
|
|
|
3
|
while ($self->has_next_item) { |
26
|
3
|
|
|
|
|
38
|
push @items, $self->get_next_item; |
27
|
|
|
|
|
|
|
} |
28
|
1
|
|
|
|
|
16
|
@items; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_item_count { |
32
|
1
|
|
|
1
|
1
|
17
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
5
|
$self->reset_iterator; |
35
|
1
|
|
|
|
|
6
|
my $count = 0; |
36
|
1
|
|
|
|
|
3
|
while ($self->has_next_item) { |
37
|
3
|
|
|
|
|
25
|
$self->get_next_item; |
38
|
3
|
|
|
|
|
25
|
$count++; |
39
|
|
|
|
|
|
|
} |
40
|
1
|
|
|
|
|
9
|
$count; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub each_item { |
44
|
1
|
|
|
1
|
1
|
4
|
my ($self, $coderef) = @_; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
5
|
$self->reset_iterator; |
47
|
1
|
|
|
|
|
5
|
my $pos = 0; |
48
|
1
|
|
|
|
|
3
|
while ($self->has_next_item) { |
49
|
3
|
|
|
|
|
24
|
my $item = $self->get_next_item; |
50
|
3
|
|
|
|
|
26
|
my $res = $coderef->($item, $self, $pos); |
51
|
3
|
50
|
|
|
|
14
|
return 0 unless $res; |
52
|
3
|
|
|
|
|
7
|
$pos++; |
53
|
|
|
|
|
|
|
} |
54
|
1
|
|
|
|
|
8
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
# ABSTRACT: A resettable iterator |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |