Attean/IteratorSequence.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 48 / 48 CC 3 SCAR 4.7
CC
3
Cov
100%
next
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« AtteanX/Serializer/SPARQLTSV.pm ↑ Summary Attean/Variable.pm »
1 50 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Attean::IteratorSequence - Iterator implementation backed by zero or more sub-iterators
7  
8 =head1 VERSION
9  
10 This document describes Attean::IteratorSequence version 0.040
11  
12 =head1 SYNOPSIS
13  
14 use v5.14;
15 use Attean;
16 my $iter = Attean::IteratorSequence->new(iterators => [$iter1, $iter2]);
17  
18 =head1 DESCRIPTION
19  
20 The Attean::IteratorSequence class represents a typed iterator that is backed
21 by zero or more sub-iterators. When iterated over, it will return all the
22 elements of all of its sub-iterators, in order, before returning undef.
23 It conforms to the L<Attean::API::Iterator> role.
24  
25 The Attean::IteratorSequence constructor requires two named arguments:
26  
27 =over 4
28  
29 =item iterators
30  
31 An array reference containing zero or more L<Attean::API::Iterator> objects.
32  
33 =item item_type
34  
35 A string representing the type of the items that will be returned from the
36 iterator.
37  
38 =back
39  
40 =head1 METHODS
41  
42 =over 4
43  
44 =cut
45  
46 50 package Attean::IteratorSequence 0.040 {
47 50 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 50 ▶ use Types::Standard qw(ArrayRef ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 50 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
50
51 50 with 'Attean::API::Iterator';
52
53 1 ▶ has iterators => (is => 'ro', isa => ArrayRef[ConsumerOf['Attean::API::Iterator']], default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
54
55 =item C<< next >>
56  
57 Returns the iterator's next item, or undef upon reaching the end of iteration.
58  
59 =cut
60  
61 377 ▶ sub next {
Subroutine next: called CC=3 SCAR=11.0
Pod documented
62 377 my $self = shift;
63 377 my $list = $self->iterators;
64
65 377 while (1) {
66 519 ▶ return unless (scalar(@$list));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$list 127 392 519
67 392 my $iter = $list->[0];
68 392 my $item = $iter->next;
69 392 ▶ unless (defined($item)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $item) 142 250 392
70 142 shift(@$list);
71 142 next;
72 }
73 250 return $item;
74 }
75 }
76
77 =item C<< push( $iterator ) >>
78  
79 Adds the new C<< $iterator >> to the end of the array of sub-iterators.
80  
81 After this call, C<< $iterator >> will be owned by the IteratorSequence,
82 so making any method calls on C<< $iterator >> after this point may produce
83 unexpected results.
84  
85 =cut
86  
87 2 ▶ sub push {
Subroutine push: called CC=1 SCAR=0.0
Pod documented
88 2 my $self = shift;
89 2 my $iter = shift;
90 2 push(@{ $self->iterators }, $iter);
91 2 return;
92 }
93 }
94  
95 50 1;
96  
97 __END__
« AtteanX/Serializer/SPARQLTSV.pm ↑ Summary Attean/Variable.pm »