blib/lib/Iterator/Flex/Cycle.pm

filter: Statementstmt 100% 47 / 47 Branchbran 72.2% 13 / 18 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 16 / 16 Podpod 50.0% 1 / 2 totaltotal 77.3% 82 / 106 CC 15 SCAR 17.8
CC
15
Cov
81%
construct
13.7
new
2.1
__ANON__
2.0
CRAP 5.9
« blib/lib/Iterator/Flex/Array.pm ↑ Summary blib/lib/Iterator/Flex/Buffer.pm »
1 package Iterator::Flex::Cycle;
2  
3 # ABSTRACT: Array Cycle Iterator Class
4  
5 2 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.33';
11  
12 2 ▶use Iterator::Flex::Utils ':IterAttrs';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Ref::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use parent 'Iterator::Flex::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
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 ▶sub new ( $class, $array, $ ) {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
46  
47 4 ▶ throw_failure( parameter => q{argument must be an ARRAY reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_arrayref($array) 0 4 4
48 unless Ref::Util::is_arrayref( $array );
49  
50 4 $class->SUPER::new( { array => $array }, {} );
51 }
52  
53 ▶sub construct ( $class, $state ) {
Subroutine construct: called CC=11 SCAR=26.1
Pod undocumented
54  
55 5 ▶ throw_failure( parameter => q{state must be a HASH reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_hashref($state) 0 5 5
56 unless Ref::Util::is_hashref( $state );
57  
58 my ( $arr, $prev, $current, $next )
59 5 = @{$state}{qw[ array prev current next ]};
60  
61 5 my $len = @$arr;
62  
63 5 ▶ $next = 0 unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 4 1 5
64  
65 5 ▶ throw_failure( parameter => q{illegal value for 'prev'} )
Branch: 1 branch
BranchTrueFalseTotal
if defined $prev and $prev < 0 || $prev >= $len 0 5 5
Condition16%1/6
defined $prev and $prev < 0 || $prev >= $len
!ll&&!rl&&r
500
$prev < 0 or $prev >= $len
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $prev and $prev < 0 || $prev >= $len
defined $prev $prev < 0 $prev >= $len
Truth table25%1/4
A and B or C
A= defined $prevB= $prev < 0C= $prev >= $len
ABCresult
0XX0
1000
11X1
1011
66 if defined $prev && ( $prev < 0 || $prev >= $len );
67  
68 5 ▶ throw_failure( parameter => q{illegal value for 'current'} )
Branch: 1 branch
BranchTrueFalseTotal
if defined $current and $current < 0 || $current >= $len 0 5 5
Condition50%3/6
defined $current and $current < 0 || $current >= $len
!ll&&!rl&&r
410
$current < 0 or $current >= $len
l!l&&r!l&&!r
001
MC/DC0%0/3
defined $current and $current < 0 || $current >= $len
defined $current $current < 0 $current >= $len
Truth table50%2/4
A and B or C
A= defined $currentB= $current < 0C= $current >= $len
ABCresult
0XX0
1000
11X1
1011
69 if defined $current && ( $current < 0 || $current >= $len );
70  
71 5 ▶ throw_failure( parameter => q{illegal value for 'next'} )
Branch: 1 branch
BranchTrueFalseTotal
if $next < 0 or $next > $len 0 5 5
Condition33%1/3
$next < 0 or $next > $len
l!l&&r!l&&!r
005
MC/DC0%0/2
$next < 0 or $next > $len
$next < 0 $next > $len
Truth table33%1/3
A or B
A= $next < 0B= $next > $len
ABresult
1X1
011
000
72 if $next < 0 || $next > $len;
73  
74  
75 return {
76  
77 ( +RESET ) => sub {
78 1 ▶ $prev = $current = undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
79 1 $next = 0;
80 },
81  
82 ( +REWIND ) => sub {
83 1 ▶ $next = 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
84 },
85  
86 ( +PREV ) => sub {
87 22 ▶ return defined $prev ? $arr->[$prev] : undef;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $prev ? : 16 6 22
88 },
89  
90 ( +CURRENT ) => sub {
91 22 ▶ return defined $current ? $arr->[$current] : undef;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $current ? : 19 3 22
92 },
93  
94 ( +NEXT ) => sub {
95 23 ▶ $next = 0 if $next == $len;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $next == $len 4 19 23
96 23 $prev = $current;
97 23 $current = $next++;
98 23 return $arr->[$current];
99 },
100  
101 ( +FREEZE ) => sub {
102 return [
103 1 ▶ $class,
Subroutine __ANON__: called CC=1 SCAR=0.0
104 {
105 array => $arr,
106 prev => $prev,
107 current => $current,
108 next => $next,
109 },
110 ];
111 },
112 5 };
113 }
114  
115  
116 2 __PACKAGE__->_add_roles( qw[
117 State::Registry
118 Next::Closure
119 Rewind::Closure
120 Reset::Closure
121 Prev::Closure
122 Current::Closure
123 Freeze
124 ] );
125  
126  
127 2 1;
128  
129 #
130 # This file is part of Iterator-Flex
131 #
132 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
133 #
134 # This is free software, licensed under:
135 #
136 # The GNU General Public License, Version 3, June 2007
137 #
138  
139 __END__
« blib/lib/Iterator/Flex/Array.pm ↑ Summary blib/lib/Iterator/Flex/Buffer.pm »