Flex/Cat.pm

filter: Statementstmt 95.1% 79 / 83 Branchbran 54.5% 12 / 22 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 90.4% 19 / 21 Podpod 50.0% 1 / 2 totaltotal 83.4% 116 / 139 CC 15 SCAR 11.6
CC
15
Cov
85%
construct
6.3
__ANON__
6.0
__ANON__
5.0
CRAP 3.2
« Flex/Role/Wrap/Return.pm ↑ Summary Flex/Cache.pm »
1 package Iterator::Flex::Cat;
2  
3 # ABSTRACT: An iterator which concatenates a set of iterators
4  
5 4 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use experimental qw( signatures declared_refs refaliasing );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our $VERSION = '0.34';
11  
12 use Iterator::Flex::Utils
13 4 ▶ qw( RETURN STATE EXHAUSTION :IterAttrs :IterStates can_meth throw_failure );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Iterator::Flex::Factory 'to_iterator';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use parent 'Iterator::Flex::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use List::Util 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56 3 ▶sub new ( $class, @args ) {
Subroutine new: called CC=3 SCAR=11.7
Pod documented
57 3 ▶ my $pars = Ref::Util::is_hashref( $args[-1] ) ? pop @args : {};
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_hashref($args[-1]) ? : 0 3 3
58  
59 @args
60 3 ▶ or throw_failure( parameter => 'not enough parameters' );
Branch: 1 branch
BranchTrueFalseTotal
@args or throw_failure("parameter", "not enough parameters") 3 0 3
61  
62 3 $class->SUPER::new( {
63 depends => \@args,
64 current_iterator_index => undef,
65 },
66 $pars,
67 );
68 }
69  
70 3 ▶sub construct ( $class, $state ) {
Subroutine construct: called CC=6 SCAR=18.4
Pod undocumented
71 3 ▶ throw_failure( parameter => q{state must be a HASH reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_hashref($state) 0 3 3
72 unless Ref::Util::is_hashref( $state );
73  
74 3 ▶ $state->{value} //= [];
Condition50%1/2
$state->{"value"} //= []
l!l
03
MC/DC0%0/1
$state->{"value"} //= []
$state->{"value"}
Truth table50%1/2
A
A= $state->{"value"}
Aresult
11
00
75  
76 my ( \@depends, $current_iterator, $prev, $current, $next, undef )
77 3 = @{$state}{ 'depends', 'current_iterator', 'prev', 'current', 'next', 'thaw' };
78  
79 # transform into iterators if required.
80 my @iterators
81 3 = map { to_iterator( $_, { ( +EXHAUSTION ) => RETURN } ) } @depends;
82  
83 # -- not sure if this is just cargo-culted
84 # my $value;
85 # $value = $current
86 # if $thaw;
87  
88 3 my $self;
89 my $iterator_state;
90 3 my $iter;
91 3 my $is_exhausted;
92  
93 7 ▶ my sub init {
Subroutine init: called CC=3 SCAR=12.0
94 7 ▶ $current_iterator //= 0;
Condition50%1/2
$current_iterator //= 0
l!l
07
MC/DC0%0/1
$current_iterator //= 0
$current_iterator
Truth table50%1/2
A
A= $current_iterator
Aresult
11
00
95 7 ▶ if ( $current_iterator >= @iterators ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_iterator >= @iterators) { } 0 7 7
96 0 $iterator_state = IterState_EXHAUSTED;
97 }
98 else {
99 7 $iter = $iterators[$current_iterator];
100 7 $is_exhausted = $iter->can( 'is_exhausted' );
101 }
102 }
103  
104 3 init();
105  
106 my %params = (
107  
108 ( +_SELF ) => \$self,
109  
110 ( +STATE ) => \$iterator_state,
111  
112 65 ▶ ( +NEXT ) => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
113 65 ▶ return $self->signal_exhaustion if $iterator_state == IterState_EXHAUSTED;
Branch: 1 branch
BranchTrueFalseTotal
if $iterator_state == 1 0 65 65
114  
115 65 while ( 1 ) {
116 73 my $value = $iter->();
117 73 ▶ if ( defined $value || !$iter->$is_exhausted ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value or not $iter->$is_exhausted) 58 15 73
Condition66%2/3
defined $value or not $iter->$is_exhausted
l!l&&r!l&&!r
58015
MC/DC50%1/2
defined $value or not $iter->$is_exhausted
defined $value not $iter->$is_exhausted
Truth table66%2/3
A or not(B)
A= defined $valueB= not $iter->$is_exhausted
ABresult
1X1
011
000
118 58 $prev = $current;
119 58 $current = $value;
120 58 return $current;
121 }
122  
123 15 ▶ last if ++$current_iterator >= @iterators;
Branch: 1 branch
BranchTrueFalseTotal
if ++$current_iterator >= @iterators 7 8 15
124 8 $iter = $iterators[$current_iterator];
125 8 $is_exhausted = $iter->can( 'is_exhausted' );
126 }
127  
128 # if we haven't returned, we've exhausted things
129 7 $current_iterator = undef;
130 7 $prev = $current;
131 7 return $current = $self->signal_exhaustion;
132 },
133  
134 6 ▶ ( +PREV ) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
135 6 return $prev;
136 },
137  
138 0 ▶ ( +CURRENT ) => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
139 0 ▶ return $self->signal_exhaustion if $iterator_state eq IterState_EXHAUSTED;
Branch: 1 branch
BranchTrueFalseTotal
if $iterator_state eq 1 0 0 0
140 0 return $current;
141 },
142  
143 3 ( +_ROLES ) => [],
144  
145 ( +_DEPENDS ) => \@iterators,
146 );
147  
148 # can only freeze if the iterators support a current method
149 3 ▶ if ( all { defined can_meth( $_, 'current' ) } @iterators ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { defined can_meth($_, "current"); } , @iterators)) 3 0 3
150 0 ▶ $params{ +FREEZE } = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
151 return [
152 0 $class,
153 {
154 current_iterator => $current_iterator,
155 prev => $prev,
156 current => $current,
157 next => $next,
158 } ];
159 3 };
160 3 push $params{ +_ROLES }->@*, 'Freeze';
161 }
162  
163 3 ▶ if ( all { defined can_meth( $_, 'reset' ) } @iterators ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { defined can_meth($_, "reset"); } , @iterators)) 3 0 3
164 2 ▶ $params{ +RESET } = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
165 2 $prev = $current = $current_iterator = undef;
166 2 init();
167 3 };
168 3 push $params{ +_ROLES }->@*, 'Reset::Closure';
169 }
170  
171 3 ▶ if ( all { defined can_meth( $_, 'rewind' ) } @iterators ) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { defined can_meth($_, "rewind"); } , @iterators)) 3 0 3
172 2 ▶ $params{ +REWIND } = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
173 2 $current_iterator = undef;
174 2 init();
175 3 };
176 3 push $params{ +_ROLES }->@*, 'Rewind::Closure';
177 }
178  
179 3 $params{ +_NAME } = 'icat';
180 3 return \%params;
181 }
182  
183  
184 4 __PACKAGE__->_add_roles( qw[
185 State::Closure
186 Next::ClosedSelf
187 Current::Closure
188 Prev::Closure
189 ] );
190  
191 4 1;
192  
193 #
194 # This file is part of Iterator-Flex
195 #
196 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
197 #
198 # This is free software, licensed under:
199 #
200 # The GNU General Public License, Version 3, June 2007
201 #
202  
203 __END__
« Flex/Role/Wrap/Return.pm ↑ Summary Flex/Cache.pm »