lib/OpenSky/API/Utils/Iterator.pm

filter: Statementstmt 54.1% 13 / 24 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 5 / 5 totaltotal 53.8% 21 / 39 CC 2 SCAR 9.4
CC
2
Cov
50%
next
6.0
first
2.0
reset
2.0
CRAP 2.6
« blib/lib/OpenSky/API/Core/StateVector.pm ↑ Summary lib/OpenSky/API/Types.pm »
1 # ABSTARCT: Internal iterator class for OpenSky::API
2  
3 package OpenSky::API::Utils::Iterator;
4  
5 5 our $VERSION = '0.002';
6 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 use OpenSky::API::Types qw(
8 ArrayRef
9 Defined
10 InstanceOf
11 PositiveOrZeroInt
12 5 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use experimental qw(signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 has '_rows' => (
16 is => 'ro',
17 isa => ArrayRef [Defined],
18 init_arg => 'rows',
19 );
20  
21 5 has '_index' => (
22 is => 'rw',
23 writer => '_set_index',
24 isa => PositiveOrZeroInt,
25 default => 0,
26 );
27  
28 ▶sub first ($self) {
Subroutine first: not called CC=1 SCAR=6.9
Pod documented
29 0 return $self->_rows->[0];
30 }
31  
32 ▶sub next ($self) {
Subroutine next: not called CC=2 SCAR=17.9
Pod documented
33 0 my $i = $self->_index;
34 0 ▶ my $next = $self->_rows->[$i] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $next = $self->_rows->[$i] or return 0 0 0
35 0 $self->_set_index( $i + 1 );
36 0 return $next;
37 }
38  
39 ▶sub reset ($self) {
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
40 0 $self->set_index(0);
41 0 return 1;
42 }
43  
44 ▶sub all ($self) {
Subroutine all: not called CC=1 SCAR=6.9
Pod documented
45 0 return @{ $self->_rows };
46 }
47  
48 ▶sub count ($self) {
Subroutine count: not called CC=1 SCAR=6.9
Pod documented
49 0 my @all = $self->all;
50 0 return scalar @all;
51 }
52  
53 5 __PACKAGE__->meta->make_immutable;
54  
55 __END__
56  
57 =pod
58  
59 =encoding UTF-8
60  
61 =head1 NAME
62  
63 OpenSky::API::Utils::Iterator
64  
65 =head1 VERSION
66  
67 version 0.002
68  
69 =head1 SYNOPSIS
70  
71 use OpenSky::API::Utils::Iterator;
72  
73 my $results = OpenSky::API::Utils::Iterator->new( rows => [ 1, 2, 3 ] );
74  
75 while ( my $result = $results->next ) {
76 ...
77 }
78  
79 =head1 DESCRIPTION
80  
81 A simple iterator class. To keep it dead simple, it only allows defined values
82 to be passed in.
83  
84 =head1 METHODS
85  
86 =head2 C<next>
87  
88 while ( my $result = $results->next ) {
89 ...
90 }
91  
92 Returns the next member in the iterator. Returns C<undef> if the iterator is
93 exhausted.
94  
95 =head2 C<count>
96  
97 if ( $results->count ) {
98 ...
99 }
100  
101 Returns the number of members in the iterator.
102  
103 =head2 C<first>
104  
105 my $object = $results->first;
106  
107 Returns the first object in the results.
108  
109 =head2 C<reset>
110  
111 $results->reset;
112  
113 Resets the iterator to point to the first member.
114  
115 =head2 C<all>
116  
117 my @objects = $results->all;
118  
119 Returns a list of all members in the iterator.
120  
121 =head1 AUTHOR
122  
123 Curtis "Ovid" Poe <curtis.poe@gmail.com>
124  
125 =head1 COPYRIGHT AND LICENSE
126  
127 This software is Copyright (c) 2023 by Curtis "Ovid" Poe.
128  
129 This is free software, licensed under:
130  
131 The Artistic License 2.0 (GPL Compatible)
132  
133 =cut
« blib/lib/OpenSky/API/Core/StateVector.pm ↑ Summary lib/OpenSky/API/Types.pm »