blib/lib/Iterator/Flex/Sequence.pm

filter: Statementstmt 98.7% 79 / 80 Branchbran 94.1% 32 / 34 Conditioncond 66.6% 8 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 95.2% 20 / 21 Podpod 50.0% 1 / 2 totaltotal 90.9% 141 / 155 CC 22 SCAR 16.2
CC
22
Cov
94%
construct
12.0
new
5.2
__ANON__
3.0
CRAP 5.1
« blib/lib/Iterator/Flex/Freeze.pm ↑ Summary blib/lib/Iterator/Flex/Chunk.pm »
1 package Iterator::Flex::Sequence;
2  
3 # ABSTRACT: Numeric Sequence Iterator Class
4  
5 10 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use experimental 'signatures', 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 our $VERSION = '0.33';
11  
12 10 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 ▶use parent 'Iterator::Flex::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Iterator::Flex::Utils qw( STATE :IterAttrs throw_failure );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 10 ▶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 ▶sub new ( $class, @args ) {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
54  
55 67 ▶ my $pars = Ref::Util::is_hashref( $args[-1] ) ? pop @args : {};
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_hashref($args[-1]) ? : 8 59 67
56  
57 67 ▶ throw_failure( parameter => q{incorrect number of arguments for sequence} )
Branch: 1 branch
BranchTrueFalseTotal
if @args < 1 or @args > 3 0 67 67
Condition33%1/3
@args < 1 or @args > 3
l!l&&r!l&&!r
0067
MC/DC0%0/2
@args < 1 or @args > 3
@args < 1 @args > 3
Truth table33%1/3
A or B
A= @args < 1B= @args > 3
ABresult
1X1
011
000
58 if @args < 1 || @args > 3;
59  
60 67 my %state;
61 67 ▶ $state{step} = pop @args if @args == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @args == 3 7 60 67
62 67 $state{end} = pop @args;
63 67 $state{begin} = pop @args;
64  
65  
66 67 $class->SUPER::new( \%state, $pars );
67 }
68  
69 ▶sub construct ( $class, $state ) {
Subroutine construct: called CC=12 SCAR=24.9
Pod undocumented
70  
71 throw_failure( parameter => "$class: arguments must be numbers\n" )
72 75 ▶ unless List::Util::all { Scalar::Util::looks_like_number( $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
unless &List::Util::all(sub { &Scalar::Util::looks_like_number($_); } ) 0 75 75
73  
74 my ( $begin, $end, $step, $iter, $next, $current, $prev )
75 75 = @{$state}{qw[ begin end step iter next current prev ]};
76  
77 75 my $self;
78 my $iterator_state;
79  
80 75 my %params;
81  
82 75 ▶ if ( !defined $step ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $step) { } 67 8 75
83  
84 67 ▶ $begin = 0 unless defined $begin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $begin 46 21 67
85 67 ▶ $next = $begin unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 60 7 67
86  
87 %params = (
88 ( +NEXT ) => sub {
89 1032 ▶ if ( $next > $end ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $end) 100 932 1032
90 100 ▶ $prev = $current
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_exhausted 72 28 100
91 unless $self->is_exhausted;
92 100 return $current = $self->signal_exhaustion;
93 }
94 932 $prev = $current;
95 932 $current = $next++;
96 932 return $current;
97 },
98 ( +FREEZE ) => sub {
99 return [
100 26 ▶ $class,
Subroutine __ANON__: called CC=1 SCAR=0.0
101 {
102 begin => $begin,
103 end => $end,
104 prev => $prev,
105 current => $current,
106 next => $next,
107 },
108 ];
109 },
110 67 );
111 }
112  
113 else {
114  
115 8 ▶ throw_failure(
Branch: 1 branch
BranchTrueFalseTotal
if $begin < $end and $step <= 0 or $begin > $end and $step >= 0 1 7 8
Condition77%7/9
$begin < $end and $step <= 0 or $begin > $end and $step >= 0
l!l&&r!l&&!r
107
$begin < $end and $step <= 0
!ll&&!rl&&r
251
$begin > $end and $step >= 0
!ll&&!rl&&r
520
MC/DC25%1/4
$begin < $end and $step <= 0 or $begin > $end and $step >= 0
$begin < $end $step <= 0 $begin > $end $step >= 0
Truth table28%2/7
A and B or C and D
A= $begin < $endB= $step <= 0C= $begin > $endD= $step >= 0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
116 parameter => q{sequence will be inifinite as $step is zero or has the incorrect sign} )
117 if ( $begin < $end && $step <= 0 ) || ( $begin > $end && $step >= 0 );
118  
119 7 ▶ $next = $begin unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 6 1 7
120 7 ▶ $iter = 0 unless defined $iter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $iter 6 1 7
121  
122 %params = (
123 ( +FREEZE ) => sub {
124 return [
125 1 ▶ $class,
Subroutine __ANON__: called CC=1 SCAR=0.0
126 {
127 begin => $begin,
128 end => $end,
129 step => $step,
130 iter => $iter,
131 prev => $prev,
132 current => $current,
133 next => $next,
134 },
135 ];
136 },
137  
138 ( +NEXT ) => $begin < $end
139 ? sub {
140 33 ▶ if ( $next > $end ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $end) 16 17 33
141 16 ▶ $prev = $current
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_exhausted 6 10 16
142 unless $self->is_exhausted;
143 16 return $current = $self->signal_exhaustion;
144 }
145 17 $prev = $current;
146 17 $current = $next;
147 17 $next = $begin + ++$iter * $step;
148 17 return $current;
149 }
150 : sub {
151 8 ▶ if ( $next < $end ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ($next < $end) 4 4 8
152 4 ▶ $prev = $current
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_exhausted 2 2 4
153 unless $self->is_exhausted;
154 4 return $current = $self->signal_exhaustion;
155 }
156 4 $prev = $current;
157 4 $current = $next;
158 4 $next = $begin + ++$iter * $step;
159 4 return $current;
160 },
161 7 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$begin < $end ? : 5 2 7
162 }
163  
164 return {
165 %params,
166 106 ▶ ( +CURRENT ) => sub { $current },
Subroutine __ANON__: called CC=1 SCAR=0.0
167 105 ▶ ( +PREV ) => sub { $prev },
Subroutine __ANON__: called CC=1 SCAR=0.0
168 ( +REWIND ) => sub {
169 19 ▶ $next = $begin;
Subroutine __ANON__: called CC=1 SCAR=0.0
170 19 $iter = 0;
171 },
172 ( +RESET ) => sub {
173 28 ▶ $prev = $current = undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
174 28 $next = $begin;
175 28 $iter = 0;
176 },
177  
178 74 ( +_SELF ) => \$self,
179  
180 ( +STATE ) => \$iterator_state,
181 };
182  
183 }
184  
185 10 __PACKAGE__->_add_roles( qw[
186 State::Closure
187 Next::ClosedSelf
188 Rewind::Closure
189 Reset::Closure
190 Prev::Closure
191 Current::Closure
192 Freeze
193 ] );
194  
195 10 1;
196  
197 #
198 # This file is part of Iterator-Flex
199 #
200 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
201 #
202 # This is free software, licensed under:
203 #
204 # The GNU General Public License, Version 3, June 2007
205 #
206  
207 __END__
« blib/lib/Iterator/Flex/Freeze.pm ↑ Summary blib/lib/Iterator/Flex/Chunk.pm »