blib/lib/Iterator/Flex/Base.pm

filter: Statementstmt 90.1% 193 / 214 Branchbran 67.5% 54 / 80 Conditioncond 60.5% 23 / 38 MC/DCmcdc 33.3% 8 / 24 Subroutinesub 94.2% 49 / 52 Podpod 76.1% 16 / 21 totaltotal 79.9% 343 / 429 CC 73 SCAR 26.8
CC
73
Cov
81%
foreach
49.8
new_from_attrs
34.9
drain
9.0
CRAP 14.6
« blib/lib/Iterator/Flex/Factory.pm ↑ Summary blib/lib/Iterator/Flex/Gather.pm »
1 package Iterator::Flex::Base;
2  
3 # ABSTRACT: Iterator object
4  
5 54 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 54 ▶use experimental qw( signatures postderef declared_refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 54 our $VERSION = '0.33';
12  
13 54 ▶use Ref::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 54 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 54 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 54 ▶use Role::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 54 ▶use Role::Tiny::With ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 54 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 54 use Iterator::Flex::Utils qw (
21 :default
22 :ExhaustionActions
23 :GeneralParameters
24 :RegistryIndices
25 :IterAttrs
26 :IterStates
27 :InterfaceParameters
28 :SignalParameters
29 load_role
30 throw_failure
31 54 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 54 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 use overload
36 180 ▶ '<>' => sub ( $self, $, $ ) { &{$self}() },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 fallback => 0,
38 1120 ▶ bool => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
39  
40 # these are required for the perldb to not barf
41 # see https://github.com/Perl/perl5/issues/23486
42 0 ▶ eq => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 ▶ q{""} => sub { q{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 54 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # We separate constructor parameters into two categories:
47 #
48 # 1. those that are used to construct the iterator
49 # 2. those that specify what happens when the iterator signals exhaustion
50 #
51 # Category #2 may be expanded. Category #2 parameters are *not* passed
52 # to the iterator class construct* routines
53  
54  
55 274 ▶sub new ( $class, $state = undef, $general = {} ) {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
56 274 return $class->new_from_state( $state, $general );
57 }
58  
59 ▶sub new_from_state ( $class, $state, $general ) {
Subroutine new_from_state: called CC=1 SCAR=0.0
Pod undocumented
60 295 return $class->new_from_attrs( $class->construct( $state ), $general );
61 }
62  
63 385 ▶sub new_from_attrs ( $class, $in_ipar = {}, $in_gpar = {} ) { ## no critic (ExcessComplexity)
Subroutine new_from_attrs: called CC=30 SCAR=35.5
Pod undocumented
64  
65 385 my %ipar = $in_ipar->%*;
66 385 my %gpar = $in_gpar->%*;
67  
68 385 $class->_validate_interface_pars( \%ipar );
69 385 $class->_validate_signal_pars( \%gpar );
70  
71 385 ▶ my @roles = ( delete( $ipar{ +_ROLES } ) // [] )->@*;
Condition100%2/2
delete $ipar{"_roles"} // []
l!l
108277
MC/DC100%1/1
delete $ipar{"_roles"} // []
delete $ipar{"_roles"}
Truth table100%2/2
A
A= delete $ipar{"_roles"}
Aresult
11
00
72  
73 385 ▶ $gpar{ +ERROR } //= [THROW];
Condition100%2/2
$gpar{"error"} //= ["throw"]
l!l
1384
MC/DC100%1/1
$gpar{"error"} //= ["throw"]
$gpar{"error"}
Truth table100%2/2
A
A= $gpar{"error"}
Aresult
11
00
74 $gpar{ +ERROR } = [ $gpar{ +ERROR } ]
75 385 ▶ unless Ref::Util::is_arrayref( $gpar{ +ERROR } );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_arrayref($gpar{"error"}) 0 385 385
76  
77 385 ▶ if ( $gpar{ +ERROR }[0] eq THROW ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gpar{'error'}[0] eq 'throw') { } 385 0 385
78 385 push @roles, 'Error::Throw';
79 }
80 else {
81 0 throw_failure( q{unknown specification of iterator error signaling behavior:}, $gpar{ +ERROR }[0] );
82 }
83  
84 385 ▶ my $exhaustion_action = $gpar{ +EXHAUSTION } // [ ( +RETURN ) => undef ];
Condition100%2/2
$gpar{"exhaustion"} // ["return", undef]
l!l
166219
MC/DC100%1/1
$gpar{"exhaustion"} // ["return", undef]
$gpar{"exhaustion"}
Truth table100%2/2
A
A= $gpar{"exhaustion"}
Aresult
11
00
85  
86 my @exhaustion_action
87 385 ▶ = Ref::Util::is_arrayref( $exhaustion_action )
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_arrayref($exhaustion_action) ? : 291 94 385
88 ? ( $exhaustion_action->@* )
89 : ( $exhaustion_action );
90  
91 385 $gpar{ +EXHAUSTION } = \@exhaustion_action;
92  
93 385 ▶ if ( $exhaustion_action[0] eq RETURN ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($exhaustion_action[0] eq 'return') { } 284 101 385
elsif ($exhaustion_action[0] eq 'throw') { } 101 0 101
94 284 push @roles, 'Exhaustion::Return';
95 }
96 elsif ( $exhaustion_action[0] eq THROW ) {
97  
98 101 ▶ push @roles,
Branch: 1 branch
BranchTrueFalseTotal
@exhaustion_action > 1 && $exhaustion_action[1] eq 'passthrough' ? : 2 99 101
Condition66%2/3
@exhaustion_action > 1 and $exhaustion_action[1] eq "passthrough"
!ll&&!rl&&r
9902
MC/DC50%1/2
@exhaustion_action > 1 and $exhaustion_action[1] eq "passthrough"
@exhaustion_action > 1 $exhaustion_action[1] eq "passthrough"
Truth table66%2/3
A and B
A= @exhaustion_action > 1B= $exhaustion_action[1] eq "passthrough"
ABresult
0X0
100
111
99 @exhaustion_action > 1 && $exhaustion_action[1] eq PASSTHROUGH
100 ? 'Exhaustion::PassthroughThrow'
101 : 'Exhaustion::Throw';
102 }
103 else {
104 0 throw_failure( parameter => "unknown exhaustion action: $exhaustion_action[0]" );
105 }
106  
107 385 ▶ if ( defined( my $par = $ipar{ +METHODS } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $par = $ipar{"methods"})) 17 368 385
108  
109 17 require Iterator::Flex::Method;
110  
111 17 ▶ throw_failure( parameter => q{value for methods parameter must be a hash reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_hashref($par) 0 17 17
112 unless Ref::Util::is_hashref( $par );
113  
114 17 for my $name ( keys $par->%* ) {
115  
116 29 my $code = $par->{$name};
117  
118 29 ▶ throw_failure( parameter => "value for 'methods' parameter key '$name' must be a code reference" )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_coderef($code) 0 29 29
119 unless Ref::Util::is_coderef( $code );
120  
121 # create role for the method
122 29 my $role = eval { Iterator::Flex::Method::Maker( $name, name => $name ) };
123  
124 29 ▶ if ( $@ ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 20 9 29
125 20 my $error = $@;
126 20 ▶ die $error
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_blessed_ref($error) and $error->isa("Iterator::Flex::Failure::RoleExists") 0 20 20
Condition33%1/3
Ref::Util::XS::is_blessed_ref($error) and $error->isa("Iterator::Flex::Failure::RoleExists")
!ll&&!rl&&r
0020
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($error) and $error->isa("Iterator::Flex::Failure::RoleExists")
Ref::Util::XS::is_blessed_ref($error) $error->isa("Iterator::Flex::Failure::RoleExists")
Truth table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($error)B= $error->isa("Iterator::Flex::Failure::RoleExists")
ABresult
0X0
100
111
127 unless Ref::Util::is_blessed_ref( $error )
128 && $error->isa( 'Iterator::Flex::Failure::RoleExists' );
129 20 $role = $error->payload;
130 }
131  
132 29 push @roles, q{+} . $role; # need '+', as these are fully qualified role module names.
133 }
134 }
135  
136 385 @roles = map { load_role( $_, $class->_role_namespaces ) } @roles;
137 385 $class = Role::Tiny->create_class_with_roles( $class, @roles );
138  
139 385 ▶ unless ( $class->can( '_construct_next' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can("_construct_next")) 0 385 385
140 0 throw_failure(
141 class => "Constructed class '$class' does not provide the required _construct_next method\n" );
142 }
143  
144 385 ▶ unless ( $class->does( 'Iterator::Flex::Role::State' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->does("Iterator::Flex::Role::State")) 0 385 385
145 0 throw_failure( class => "Constructed class '$class' does not provide a State role\n" );
146 }
147  
148 385 ▶ $ipar{ +_NAME } //= $class;
Condition66%2/3
$ipar{"_name"} //= $class
l!l&&r!l&&!r
1931920
MC/DC0%0/2
$ipar{"_name"} //= $class
$ipar{"_name"} $class
Truth table66%2/3
A //= B
A= $ipar{"_name"}B= $class
ABresult
1X1
011
000
149  
150 385 my $self = bless $class->_construct_next( \%ipar, \%gpar ), $class;
151  
152 throw_failure(
153 parameter => q{attempt to register an iterator subroutine which has already been registered.} )
154 385 ▶ if exists $REGISTRY{ refaddr $self };
Branch: 1 branch
BranchTrueFalseTotal
if exists $Iterator::Flex::Base::REGISTRY{builtin::refaddr($self)} 0 385 385
155  
156 385 my $regentry = $REGISTRY{ refaddr $self } = [];
157  
158 # convert to arrays. some of the parameter values are weak
159 # references so make sure we don't unweaken them
160 385 my @ipar;
161 385 for my $key ( keys %ipar ) {
162 2919 $ipar[ $RegIterationIndexMap{$key} ] = $ipar{$key};
163 Scalar::Util::weaken $ipar[ $RegIterationIndexMap{$key} ]
164 if Ref::Util::is_ref( $ipar{$key} )
165 2919 ▶ && Scalar::Util::isweak( $ipar{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_ref($ipar{$key}) and builtin::is_weak($ipar{$key}) 385 2534 2919
Condition100%3/3
Ref::Util::XS::is_ref($ipar{$key}) and builtin::is_weak($ipar{$key})
!ll&&!rl&&r
3852149385
MC/DC100%2/2
Ref::Util::XS::is_ref($ipar{$key}) and builtin::is_weak($ipar{$key})
Ref::Util::XS::is_ref($ipar{$key}) builtin::is_weak($ipar{$key})
Truth table100%3/3
A and B
A= Ref::Util::XS::is_ref($ipar{$key})B= builtin::is_weak($ipar{$key})
ABresult
0X0
100
111
166 }
167 385 my @gpar;
168 385 for my $key ( keys %gpar ) {
169 861 $gpar[ $RegGeneralParameterIndexMap{$key} ] = $gpar{$key};
170 Scalar::Util::weaken $gpar[ $RegGeneralParameterIndexMap{$key} ]
171 if Ref::Util::is_ref( $gpar{$key} )
172 861 ▶ && Scalar::Util::isweak( $gpar{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_ref($gpar{$key}) and builtin::is_weak($gpar{$key}) 0 861 861
Condition66%2/3
Ref::Util::XS::is_ref($gpar{$key}) and builtin::is_weak($gpar{$key})
!ll&&!rl&&r
38580
MC/DC0%0/2
Ref::Util::XS::is_ref($gpar{$key}) and builtin::is_weak($gpar{$key})
Ref::Util::XS::is_ref($gpar{$key}) builtin::is_weak($gpar{$key})
Truth table66%2/3
A and B
A= Ref::Util::XS::is_ref($gpar{$key})B= builtin::is_weak($gpar{$key})
ABresult
0X0
100
111
173 }
174  
175 385 $regentry->[REG_ITERATOR] = \@ipar;
176 385 $regentry->[REG_GENERAL] = \@gpar;
177  
178 385 $self->_clear_state;
179  
180 385 return $self;
181 }
182  
183 ▶sub _validate_interface_pars ( $class, $pars ) {
Subroutine _validate_interface_pars: called CC=7 SCAR=20.9
184 385 state %InterfaceParameters = {}->%{ +INTERFACE_PARAMETER_VALUES };
185  
186 385 my @bad = grep { !exists $InterfaceParameters{$_} } keys $pars->%*;
187  
188 385 ▶ throw_failure( parameter => "unknown interface parameters: @{[ join ', ', @bad ]}" )
Branch: 1 branch
BranchTrueFalseTotal
if @bad 0 385 385
189 if @bad;
190  
191 0 throw_failure( parameter => "@{[ _ROLES ]} must be an arrayref" )
192 385 ▶ if defined $pars->{_ROLES} && !Ref::Util::is_arrayref( $pars->{ +_ROLES } );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pars->{"_ROLES"} and not Ref::Util::XS::is_arrayref($pars->{"_roles"}) 0 385 385
Condition33%1/3
defined $pars->{"_ROLES"} and not Ref::Util::XS::is_arrayref($pars->{"_roles"})
!ll&&!rl&&r
38500
MC/DC0%0/2
defined $pars->{"_ROLES"} and not Ref::Util::XS::is_arrayref($pars->{"_roles"})
defined $pars->{"_ROLES"} not Ref::Util::XS::is_arrayref($pars->{"_roles"})
Truth table33%1/3
A and not(B)
A= defined $pars->{"_ROLES"}B= not Ref::Util::XS::is_arrayref($pars->{"_roles"})
ABresult
0X0
100
111
193  
194 385 ▶ if ( defined( my $par = $pars->{ +_DEPENDS } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $par = $pars->{"_depends"})) 98 287 385
195 98 ▶ $pars->{ +_DEPENDS } = $par = [$par] unless Ref::Util::is_arrayref( $par );
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_arrayref($par) 70 28 98
196 throw_failure( parameter => "dependency #$_ is not an iterator object" )
197 98 ▶ unless List::Util::all { $class->_is_iterator( $_ ) } $par->@*;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &List::Util::all(sub { $class->_is_iterator($_); } , @$par) 0 98 98
198 }
199  
200 385 return;
201 }
202  
203 ▶sub _validate_signal_pars ( $class, $pars ) {
Subroutine _validate_signal_pars: called CC=2 SCAR=7.4
204 385 state %SignalParameters = {}->%{ +SIGNAL_PARAMETER_VALUES };
205 385 my @bad = grep { !exists $SignalParameters{$_} } keys $pars->%*;
206  
207 385 ▶ throw_failure( parameter => "unknown signal parameters: @{[ join ', ', @bad ]}" )
Branch: 1 branch
BranchTrueFalseTotal
if @bad 0 385 385
208 if @bad;
209 }
210  
211  
212 ▶sub DESTROY ( $self ) {
Subroutine DESTROY: called CC=2 SCAR=7.2
213  
214 382 ▶ if ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) 382 0 382
215 382 delete $REGISTRY{ refaddr $self };
216 }
217 }
218  
219 ▶sub _name ( $self ) {
Subroutine _name: called CC=1 SCAR=0.0
220 2 $REGISTRY{ refaddr $self }[REG_ITERATOR][REG_ITER__NAME];
221 }
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244 # TODO: this is too restrictive. It should allow simple coderefs, or
245 # things with a next or __next__.
246  
247 ▶sub _is_iterator ( $, $obj ) {
Subroutine _is_iterator: called CC=2 SCAR=9.2
248 138 ▶ return Ref::Util::is_blessed_ref( $obj ) && $obj->isa( __PACKAGE__ );
Condition33%1/3
Ref::Util::XS::is_blessed_ref($obj) && $obj->isa(__PACKAGE__)
!ll&&!rl&&r
00138
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($obj) && $obj->isa(__PACKAGE__)
Ref::Util::XS::is_blessed_ref($obj) $obj->isa(__PACKAGE__)
Truth table33%1/3
A && B
A= Ref::Util::XS::is_blessed_ref($obj)B= $obj->isa(__PACKAGE__)
ABresult
0X0
100
111
249 }
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263 ▶sub __iter__ ( $self ) {
Subroutine __iter__: not called CC=1 SCAR=6.9
264 0 return $REGISTRY{ refaddr $self }[REG_ITERATOR][REG_ITER_NEXT];
265 }
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279 ▶sub may ( $self, $meth ) {
Subroutine may: called CC=4 SCAR=14.1
Pod documented
280  
281 16 my \@attributes = $REGISTRY{ refaddr $self }[REG_ITERATOR];
282 16 ▶ my $may = $attributes[REG_ITER_MAY_METHOD] //= {};
Condition100%2/2
$attributes[13] //= {}
l!l
97
MC/DC100%1/1
$attributes[13] //= {}
$attributes[13]
Truth table100%2/2
A
A= $attributes[13]
Aresult
11
00
283  
284 return $may->{"_may_$meth"}
285 //= defined $attributes[REG_ITER__DEPENDS]
286 3 ▶ ? !List::Util::first { !$_->may( $meth ) } $attributes[REG_ITER__DEPENDS]->@*
Subroutine __ANON__: called CC=1 SCAR=0.0
287 16 ▶ : defined $attributes[ $RegIterationIndexMap{$meth} ];
Branch: 1 branch
BranchTrueFalseTotal
defined $attributes[9] ? : 1 15 16
Condition33%1/3
$$may{"_may_$meth"} //= defined $attributes[9] ? !&List::Util::first(sub { not $_->may($meth); } , @{$attributes[9]}) : defined $attributes[$Iterator::Flex::Base::RegIterationIndexMap{$meth}]
l!l&&r!l&&!r
0160
MC/DC0%0/2
$$may{"_may_$meth"} //= defined $attributes[9] ? !&List::Util::first(sub { not $_->may($meth); } , @{$attributes[9]}) : defined $attributes[$Iterator::Flex::Base::RegIterationIndexMap{$meth}]
$$may{"_may_$meth"} defined $attributes[9] ? !&List::Util::first(sub { not $_->may($meth); } , @{$attributes[9]}) : defined $attributes[$Iterator::Flex::Base::RegIterationIndexMap{$meth}]
Truth table33%1/3
A //= B
A= $$may{"_may_$meth"}B= defined $attributes[9] ? !&List::Util::first(sub { not $_->may($meth); } , @{$attributes[9]}) : defined $attributes[$Iterator::Flex::Base::RegIterationIndexMap{$meth}]
ABresult
1X1
011
000
288 }
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305 sub _namespaces {
306 3 ▶ return 'Iterator::Flex';
Subroutine _namespaces: called CC=1 SCAR=0.0
307 }
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324 sub _role_namespaces {
325 1765 ▶ return 'Iterator::Flex::Role';
Subroutine _role_namespaces: called CC=1 SCAR=0.0
326 }
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344 ▶sub _add_roles ( $class, @roles ) {
Subroutine _add_roles: called CC=1 SCAR=0.0
345 Role::Tiny->apply_roles_to_package( $class,
346 73 map { load_role( $_, $class->_role_namespaces ) } @roles );
347 }
348  
349 ▶sub _apply_method_to_depends ( $self, $meth ) {
Subroutine _apply_method_to_depends: called CC=4 SCAR=13.9
350  
351 198 ▶ if ( defined( my $depends = $REGISTRY{ refaddr $self }[REG_ITERATOR][REG_ITER__DEPENDS] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $depends = $Iterator::Flex::Base::REGISTRY{builtin::refaddr($self)}[0][9])) 63 135 198
352 # first check if dependencies have method
353 63 ▶ my $cant = List::Util::first { !$_->can( $meth ) } $depends->@*;
Subroutine __ANON__: called CC=1 SCAR=0.0
354 63 ▶ throw_failure( Unsupported => "dependency: @{[ $cant->_name ]} does not have a '$meth' method" )
Branch: 1 branch
BranchTrueFalseTotal
if $cant 1 62 63
355 if $cant;
356  
357 # now apply the method
358 62 $_->$meth foreach $depends->@*;
359 }
360 }
361  
362  
363  
364  
365  
366  
367  
368  
369  
370 ▶sub is_exhausted ( $self ) {
Subroutine is_exhausted: called CC=1 SCAR=0.0
Pod documented
371 1206 $self->get_state == IterState_EXHAUSTED;
372 }
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387 ▶sub set_exhausted ( $self ) {
Subroutine set_exhausted: called CC=1 SCAR=0.0
Pod undocumented
388 564 $self->set_state( IterState_EXHAUSTED );
389 }
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404 ▶sub _clear_state ( $self ) {
Subroutine _clear_state: called CC=1 SCAR=0.0
405 605 $self->set_state( IterState_CLEAR );
406 }
407  
408  
409  
410  
411  
412  
413  
414  
415  
416 ▶sub is_error ( $self ) {
Subroutine is_error: called CC=1 SCAR=0.0
Pod documented
417 2 $self->get_state == IterState_ERROR;
418 }
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  
431  
432  
433 ▶sub set_error ( $self ) {
Subroutine set_error: called CC=1 SCAR=0.0
Pod undocumented
434 2 $self->set_state( IterState_ERROR );
435 }
436  
437  
438  
439  
440  
441  
442  
443  
444  
445 ▶sub throws_on_exhaustion( $self ) {
Subroutine throws_on_exhaustion: called CC=1 SCAR=0.0
Pod documented
446 1 return $REGISTRY{ refaddr $self }[REG_GENERAL][REG_GP_EXHAUSTION][0] eq THROW;
447  
448 }
449  
450  
451  
452  
453  
454  
455  
456  
457  
458 ▶sub returns_on_exhaustion( $self ) {
Subroutine returns_on_exhaustion: called CC=1 SCAR=0.0
Pod documented
459 1 return $REGISTRY{ refaddr $self }[REG_GENERAL][REG_GP_EXHAUSTION][0] eq RETURN;
460  
461 }
462  
463  
464  
465  
466  
467  
468  
469  
470  
471 1 ▶sub buffer ( $self, $n = 0, $pars = {} ) {
Subroutine buffer: called CC=3 SCAR=11.0
Pod documented
472 1 require Iterator::Flex::Buffer;
473 1 Iterator::Flex::Buffer->new( $self, $n, $pars );
474 }
475  
476  
477  
478  
479  
480  
481  
482  
483  
484  
485 1 ▶sub cache ( $self, $pars = {} ) {
Subroutine cache: called CC=2 SCAR=6.9
Pod documented
486 1 require Iterator::Flex::Cache;
487 1 Iterator::Flex::Cache->new( $self, $pars );
488 }
489  
490 sub icache;
491 54 *icache = \&cache;
492  
493  
494  
495  
496  
497  
498  
499  
500  
501  
502  
503  
504 ▶sub cat ( $self, @args ) {
Subroutine cat: called CC=1 SCAR=0.0
Pod documented
505 1 require Iterator::Flex::Cat;
506 1 Iterator::Flex::Cat->new( $self, @args );
507 }
508  
509 sub chain;
510 54 *chain = \&cat;
511  
512  
513  
514  
515  
516  
517  
518  
519  
520  
521  
522  
523 3 ▶sub chunk ( $self, $pars = {} ) {
Subroutine chunk: called CC=2 SCAR=6.9
Pod documented
524 3 require Iterator::Flex::Chunk;
525 3 Iterator::Flex::Chunk->new( $self, $pars );
526 }
527  
528 sub ichunk;
529 54 *ichunk = \&chunk;
530  
531 sub batch;
532 54 *batch = \&chunk;
533  
534  
535  
536  
537  
538  
539  
540  
541  
542  
543  
544  
545  
546  
547 115 ▶sub drain ( $self, $n = undef ) {
Subroutine drain: called CC=9 SCAR=22.0
Pod documented
548  
549 115 my @values;
550  
551 eval {
552 115 ▶ if ( $n ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) { } 41 74 115
553 41 ▶ while ( $n-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n--) 148 40 188
554 148 push @values, $self->next;
555 148 ▶ if ( $self->is_exhausted ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_exhausted) 1 147 148
556 1 pop @values;
557 1 last;
558 }
559 }
560 }
561 else {
562 74 while ( 1 ) {
563 501 push @values, $self->next;
564 498 ▶ if ( $self->is_exhausted ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_exhausted) 71 427 498
565 71 pop @values;
566 71 last;
567 }
568 }
569 }
570 112 1;
571 115 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { if ($n) { while ($n--) { push @values, $self->next; if ($self->is_exhausted) { pop @values; last; } ; } ; } else { while (1) { push @values, $self->next; if ($self->is_exhausted) { pop @values; last; } ; } ; } ; 1 } } or do { die $@ unless Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted") } 3 112 115
572 3 ▶ die $@
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted") 2 1 3
Condition66%2/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
!ll&&!rl&&r
021
MC/DC50%1/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@) $@->isa("Iterator::Flex::Failure::Exhausted")
Truth table66%2/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
ABresult
0X0
100
111
573 unless Ref::Util::is_blessed_ref( $@ )
574 && $@->isa( 'Iterator::Flex::Failure::Exhausted' );
575 };
576  
577 113 return \@values;
578 }
579  
580  
581  
582  
583  
584  
585  
586  
587  
588 1 ▶sub flatten ( $self, $pars = {} ) {
Subroutine flatten: called CC=2 SCAR=6.9
Pod documented
589 1 require Iterator::Flex::Flatten;
590 1 return Iterator::Flex::Flatten->new( $self, $pars );
591 }
592  
593 sub iflatten;
594 54 *iflatten = \*flatten;
595  
596  
597  
598  
599  
600  
601  
602  
603  
604  
605 ▶sub foreach ( $self, $code ) { ## no critic (BuiltinHomonyms)
Subroutine foreach: called CC=10 SCAR=39.1
Pod documented
606  
607 1 ▶ if ( $self->throws_on_exhaustion ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->throws_on_exhaustion) { } 0 1 1
elsif ($self->returns_on_exhaustion) { } 1 0 1
608 eval {
609 0 local $_; ## no critic (InitializationForLocalVars)
610 0 ▶ while ( $_ = $self->() ) { $code->() }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = &$self()) 0 0 0
611 0 1;
612 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $_; while ($_ = &$self()) { &$code(); } ; 1 } } or do { die $@ unless Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted") } 0 0 0
613 0 ▶ die $@
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted") 0 0 0
Condition0%0/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
!ll&&!rl&&r
000
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@) $@->isa("Iterator::Flex::Failure::Exhausted")
Truth table0%0/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
ABresult
0X0
100
111
614 unless Ref::Util::is_blessed_ref( $@ )
615 && $@->isa( 'Iterator::Flex::Failure::Exhausted' );
616 };
617 }
618 elsif ( $self->returns_on_exhaustion ) {
619  
620 # optimize for when sentinel is the undefined value
621 1 ▶ if ( !defined $self->sentinel ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sentinel) { } 1 0 1
622 1 local $_; ## no critic (InitializationForLocalVars)
623 1 ▶ $code->() while defined( $_ = $self->() );
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = &$self()) and do { &$code() } 4 1 5
624 }
625  
626 # yeah, this is too slow. should adapt the logic in Wrap::Return.
627 else {
628 0 local $_; ## no critic (InitializationForLocalVars)
629 0 $_ = $self->();
630 0 ▶ until ( $self->is_exhausted ) { ## no critic (UntilBlock)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_exhausted) 0 0 0
631 0 $code->();
632 0 $_ = $self->();
633 }
634 }
635 }
636 }
637  
638  
639  
640  
641  
642  
643  
644  
645  
646  
647 9 ▶sub gather ( $self, $code, $pars = {} ) {
Subroutine gather: called CC=2 SCAR=6.9
Pod documented
648 9 require Iterator::Flex::Gather;
649 9 Iterator::Flex::Gather->new( $code, $self, $pars );
650 }
651  
652 sub igather;
653 54 *igather = \&gather;
654  
655  
656  
657  
658  
659  
660  
661  
662  
663 1 ▶sub grep ( $self, $code, $pars = {} ) { ## no critic (BuiltinHomonyms)
Subroutine grep: called CC=2 SCAR=6.9
Pod documented
664  
665 1 require Iterator::Flex::Grep;
666 1 Iterator::Flex::Grep->new( $code, $self, $pars );
667 }
668  
669 sub igrep;
670 54 *igrep = \&grep;
671  
672  
673  
674  
675  
676  
677  
678  
679  
680 3 ▶sub map ( $self, $code, $pars = {} ) { ## no critic (BuiltinHomonyms)
Subroutine map: called CC=2 SCAR=6.9
Pod documented
681  
682 3 require Iterator::Flex::Map;
683 3 Iterator::Flex::Map->new( $code, $self, $pars );
684 }
685  
686 sub imap;
687 54 *imap = \&map;
688  
689  
690  
691  
692  
693  
694  
695  
696  
697 1 ▶sub take ( $self, $n, $pars = {} ) {
Subroutine take: called CC=2 SCAR=6.9
Pod documented
698 1 require Iterator::Flex::Take;
699 1 Iterator::Flex::Take->new( $self, $n, $pars );
700 }
701  
702 54 1;
703  
704 #
705 # This file is part of Iterator-Flex
706 #
707 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
708 #
709 # This is free software, licensed under:
710 #
711 # The GNU General Public License, Version 3, June 2007
712 #
713  
714 __END__
« blib/lib/Iterator/Flex/Factory.pm ↑ Summary blib/lib/Iterator/Flex/Gather.pm »