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