blib/lib/Iterator/Flex/Chunk.pm

filter: Statementstmt 100% 50 / 50 Branchbran 83.3% 10 / 12 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 13 / 13 Podpod 50.0% 1 / 2 totaltotal 87.7% 79 / 90 CC 11 SCAR 13.6
CC
11
Cov
91%
__ANON__
8.3
new
3.0
construct
2.0
CRAP 3.9
« blib/lib/Iterator/Flex/Sequence.pm ↑ Summary blib/lib/Iterator/Flex/Utils.pm »
1 package Iterator::Flex::Chunk;
2  
3 # ABSTRACT: Chunk Iterator Class
4  
5 3 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our $VERSION = '0.33';
11  
12 3 ▶use Iterator::Flex::Factory 'to_iterator';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Iterator::Flex::Utils qw[ THROW STATE EXHAUSTION :IterAttrs :IterStates ];
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Ref::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use parent 'Iterator::Flex::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
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 3 ▶sub new ( $class, $iterable, $pars = {} ) {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
55  
56 3 my %pars = $pars->%*;
57 3 ▶ my $capacity = delete $pars{capacity} // 1;
Condition50%1/2
delete $pars{"capacity"} // 1
l!l
30
MC/DC0%0/1
delete $pars{"capacity"} // 1
delete $pars{"capacity"}
Truth table50%1/2
A
A= delete $pars{"capacity"}
Aresult
11
00
58 3 $class->SUPER::new( {
59 capacity => $capacity,
60 src => $iterable,
61 },
62 \%pars,
63 );
64 }
65  
66 ▶sub construct ( $class, $state ) {
Subroutine construct: called CC=2 SCAR=7.0
Pod undocumented
67  
68 3 ▶ throw_failure( parameter => q{'state' parameter must be a HASH reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_hashref($state) 0 3 3
69 unless Ref::Util::is_hashref( $state );
70  
71 3 my ( $src, $capacity ) = @{$state}{qw[ src capacity ]};
72  
73 3 $src
74 = to_iterator( $src, { ( +EXHAUSTION ) => THROW } );
75  
76 3 my $self;
77 my $iterator_state;
78  
79 # This iterator may have to delay signalling exhaustion for one
80 # cycle if the input iterator is exhausted and the current chunk
81 # is not empty
82 3 my $next_is_exhausted = !!0;
83  
84 return {
85 ( +_NAME ) => 'ichunk',
86  
87 ( +_SELF ) => \$self,
88  
89 ( +STATE ) => \$iterator_state,
90  
91 ( +NEXT ) => sub {
92 16 ▶ return $self->signal_exhaustion
Subroutine __ANON__: called CC=8 SCAR=21.1
Branch: 1 branch
BranchTrueFalseTotal
if $iterator_state == 1 or $next_is_exhausted 2 14 16
Condition66%2/3
$iterator_state == 1 or $next_is_exhausted
l!l&&r!l&&!r
0214
MC/DC50%1/2
$iterator_state == 1 or $next_is_exhausted
$iterator_state == 1 $next_is_exhausted
Truth table66%2/3
A or B
A= $iterator_state == 1B= $next_is_exhausted
ABresult
1X1
011
000
93 if $iterator_state == IterState_EXHAUSTED || $next_is_exhausted;
94  
95 14 my @chunked;
96 eval {
97 14 ▶ push @chunked, $src->() while @chunked < $capacity;
Branch: 1 branch
BranchTrueFalseTotal
@chunked < $capacity and do { push @chunked, &$src() } 60 10 70
98 10 1;
99 14 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { push @chunked, &$src() while @chunked < $capacity; 1 } } or 4 10 14
100 4 ▶ die $@
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted") 0 4 4
Condition33%1/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
!ll&&!rl&&r
004
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 table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
ABresult
0X0
100
111
101 unless Ref::Util::is_blessed_ref( $@ )
102 && $@->isa( 'Iterator::Flex::Failure::Exhausted' );
103  
104 4 ▶ return $self->signal_exhaustion if !@chunked;
Branch: 1 branch
BranchTrueFalseTotal
unless @chunked 2 2 4
105 2 $next_is_exhausted = !!1;
106 };
107 12 return \@chunked;
108 },
109 ( +RESET ) => sub {
110 4 ▶ $next_is_exhausted = !!0;
Subroutine __ANON__: called CC=1 SCAR=0.0
111 },
112 3 ( +_DEPENDS ) => $src,
113 };
114 }
115  
116 3 __PACKAGE__->_add_roles( qw[
117 State::Closure
118 Next::ClosedSelf
119 Reset::Closure
120 ] );
121  
122 3 1;
123  
124 #
125 # This file is part of Iterator-Flex
126 #
127 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
128 #
129 # This is free software, licensed under:
130 #
131 # The GNU General Public License, Version 3, June 2007
132 #
133  
134 __END__
« blib/lib/Iterator/Flex/Sequence.pm ↑ Summary blib/lib/Iterator/Flex/Utils.pm »