Flex/Sequence.pm

filter: Statementstmt 98.7% 79 / 80 Branchbran 94.1% 32 / 34 Conditioncond 66.6% 8 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 95.2% 20 / 21 Podpod 50.0% 1 / 2 totaltotal 91.6% 142 / 155 CC 22 SCAR 16.2
CC
22
Cov
94%
construct
12.0
new
5.2
__ANON__
3.0
CRAP 5.1
« Flex/Take.pm ↑ Summary 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.34';
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 77 ▶sub new ( $class, @args ) {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
54  
55 77 ▶ my $pars = Ref::Util::is_hashref( $args[-1] ) ? pop @args : {};
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_hashref($args[-1]) ? : 9 68 77
56  
57 77 ▶ throw_failure( parameter => q{incorrect number of arguments for sequence} )
Branch: 1 branch
BranchTrueFalseTotal
if @args < 1 or @args > 3 0 77 77
Condition33%1/3
@args < 1 or @args > 3
l!l&&r!l&&!r
0077
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 77 my %state;
61 77 ▶ $state{step} = pop @args if @args == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @args == 3 7 70 77
62 77 $state{end} = pop @args;
63 77 $state{begin} = pop @args;
64  
65  
66 77 $class->SUPER::new( \%state, $pars );
67 }
68  
69 85 ▶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 0 ▶ 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 85 85
73  
74 my ( $begin, $end, $step, $iter, $next, $current, $prev )
75 85 = @{$state}{qw[ begin end step iter next current prev ]};
76  
77 85 my $self;
78 my $iterator_state;
79  
80 85 my %params;
81  
82 85 ▶ if ( !defined $step ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $step) { } 77 8 85
83  
84 77 ▶ $begin = 0 unless defined $begin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $begin 55 22 77
85 77 ▶ $next = $begin unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 70 7 77
86  
87 %params = (
88 1036 ▶ ( +NEXT ) => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
89 1036 ▶ if ( $next > $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $end) 101 935 1036
90 101 ▶ $prev = $current
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_exhausted 73 28 101
91 unless $self->is_exhausted;
92 101 return $current = $self->signal_exhaustion;
93 }
94 935 $prev = $current;
95 935 $current = $next++;
96 935 return $current;
97 },
98 26 ▶ ( +FREEZE ) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
99 return [
100 26 $class,
101 {
102 begin => $begin,
103 end => $end,
104 prev => $prev,
105 current => $current,
106 next => $next,
107 },
108 ];
109 },
110 77 );
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/DC50%2/4
$begin < $end and $step <= 0 or $begin > $end and $step >= 0
$begin < $end $step <= 0 $begin > $end $step >= 0
Truth table42%3/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 1 ▶ ( +FREEZE ) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
124 return [
125 1 $class,
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 33 ▶ ? sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
140 33 ▶ if ( $next > $end ) {
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 8 ▶ : sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
151 8 ▶ if ( $next < $end ) {
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 19 ▶ ( +REWIND ) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
169 19 $next = $begin;
170 19 $iter = 0;
171 },
172 28 ▶ ( +RESET ) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
173 28 $prev = $current = undef;
174 28 $next = $begin;
175 28 $iter = 0;
176 },
177  
178 84 ( +_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__
« Flex/Take.pm ↑ Summary Flex/Chunk.pm »