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-04-19'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Role-TinyCommons-Iterator'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
910
|
use Role::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
156
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
242
|
|
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
|
6921
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
6
|
$self->reset_iterator; |
23
|
1
|
|
|
|
|
56
|
my @items; |
24
|
1
|
|
|
|
|
7
|
while ($self->has_next_item) { |
25
|
3
|
|
|
|
|
41
|
push @items, $self->get_next_item; |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
18
|
@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
|
|
|
|
|
3
|
while ($self->has_next_item) { |
36
|
3
|
|
|
|
|
26
|
$self->get_next_item; |
37
|
3
|
|
|
|
|
24
|
$count++; |
38
|
|
|
|
|
|
|
} |
39
|
1
|
|
|
|
|
25
|
$count; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub each_item { |
43
|
1
|
|
|
1
|
1
|
4
|
my ($self, $coderef) = @_; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
6
|
$self->reset_iterator; |
46
|
1
|
|
|
|
|
5
|
my $pos = 0; |
47
|
1
|
|
|
|
|
4
|
while ($self->has_next_item) { |
48
|
3
|
|
|
|
|
24
|
my $item = $self->get_next_item; |
49
|
3
|
|
|
|
|
26
|
my $res = $coderef->($item, $self, $pos); |
50
|
3
|
50
|
|
|
|
13
|
return 0 unless $res; |
51
|
3
|
|
|
|
|
7
|
$pos++; |
52
|
|
|
|
|
|
|
} |
53
|
1
|
|
|
|
|
8
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
# ABSTRACT: A resettable iterator |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |