blib/lib/Iterator/Flex/ArrayLike.pm

filter: Statementstmt 100% 53 / 53 Branchbran 68.1% 15 / 22 Conditioncond 20.0% 3 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 15 / 15 Podpod 50.0% 1 / 2 totaltotal 75.6% 87 / 115 CC 18 SCAR 19.7
CC
18
Cov
79%
construct
16.1
new
3.1
__ANON__
3.0
CRAP 7.2
« blib/lib/Iterator/Flex/Zip.pm ↑ Summary blib/lib/Iterator/Flex/Permute.pm »
1 package Iterator::Flex::ArrayLike;
2  
3 # ABSTRACT: ArrayLike 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 Ref::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Iterator::Flex::Utils ':IterAttrs', 'resolve_meth';
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  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76 7 ▶sub new ( $class, $obj, $pars = {} ) {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
77  
78 7 ▶ $class->_croak( parameter => q{argument must be a blessed reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_blessed_ref($obj) 0 7 7
79 unless Ref::Util::is_blessed_ref( $obj );
80  
81 7 $class->SUPER::new( { object => $obj }, $pars );
82 }
83  
84 ▶sub construct ( $class, $state ) {
Subroutine construct: called CC=12 SCAR=27.8
Pod undocumented
85  
86 7 ▶ throw_failure( parameter => q{state must be a HASH reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_hashref($state) 0 7 7
87 unless Ref::Util::is_hashref( $state );
88  
89 my ( $obj, $prev, $current, $next, $length, $at )
90 7 = @{$state}{qw[ object prev current next length at ]};
91  
92 7 ▶ throw_failure( parameter => q{state 'object' argument must be a blessed reference} )
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_blessed_ref($obj) 0 7 7
93 unless Ref::Util::is_blessed_ref( $obj );
94  
95 7 $length = resolve_meth( $obj, $length, 'length', 'len' );
96  
97 7 $at = resolve_meth( $obj, $at, 'at', 'getitem' );
98  
99 7 my $len = $obj->$length;
100  
101 7 ▶ $next = 0 unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 7 0 7
102  
103 7 ▶ throw_failure( parameter => q{illegal value for state 'prev' argument} )
Branch: 1 branch
BranchTrueFalseTotal
if defined $prev and $prev < 0 || $prev >= $len 0 7 7
Condition16%1/6
defined $prev and $prev < 0 || $prev >= $len
!ll&&!rl&&r
700
$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
104 if defined $prev && ( $prev < 0 || $prev >= $len );
105  
106 7 ▶ throw_failure( parameter => q{illegal value for state 'current' argument} )
Branch: 1 branch
BranchTrueFalseTotal
if defined $current and $current < 0 || $current >= $len 0 7 7
Condition16%1/6
defined $current and $current < 0 || $current >= $len
!ll&&!rl&&r
700
$current < 0 or $current >= $len
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $current and $current < 0 || $current >= $len
defined $current $current < 0 $current >= $len
Truth table25%1/4
A and B or C
A= defined $currentB= $current < 0C= $current >= $len
ABCresult
0XX0
1000
11X1
1011
107 if defined $current && ( $current < 0 || $current >= $len );
108  
109 7 ▶ throw_failure( parameter => q{illegal value for state 'next' argument} )
Branch: 1 branch
BranchTrueFalseTotal
if $next < 0 or $next > $len 0 7 7
Condition33%1/3
$next < 0 or $next > $len
l!l&&r!l&&!r
007
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
110 if $next < 0 || $next > $len;
111  
112 7 my $self;
113  
114 return {
115  
116 ( +_SELF ) => \$self,
117  
118 ( +RESET ) => sub {
119 2 ▶ $prev = $current = undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
120 2 $next = 0;
121 },
122  
123 ( +REWIND ) => sub {
124 2 ▶ $next = 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
125 },
126  
127 ( +PREV ) => sub {
128 31 ▶ return defined $prev ? $obj->$at( $prev ) : undef;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $prev ? : 24 7 31
129 },
130  
131 ( +CURRENT ) => sub {
132 29 ▶ return defined $current ? $obj->$at( $current ) : undef;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $current ? : 18 11 29
133 },
134  
135 ( +NEXT ) => sub {
136 51 ▶ if ( $next == $len ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ($next == $len) 21 30 51
137 # if first time through, set current
138 21 ▶ $prev = $current
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_exhausted 9 12 21
139 if !$self->is_exhausted;
140 21 return $current = $self->signal_exhaustion;
141 }
142 30 $prev = $current;
143 30 $current = $next++;
144  
145 30 return $obj->$at( $current );
146 },
147 7 };
148 }
149  
150  
151 2 __PACKAGE__->_add_roles( qw[
152 State::Registry
153 Next::ClosedSelf
154 Rewind::Closure
155 Reset::Closure
156 Prev::Closure
157 Current::Closure
158 ] );
159  
160 2 1;
161  
162 #
163 # This file is part of Iterator-Flex
164 #
165 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
166 #
167 # This is free software, licensed under:
168 #
169 # The GNU General Public License, Version 3, June 2007
170 #
171  
172 __END__
« blib/lib/Iterator/Flex/Zip.pm ↑ Summary blib/lib/Iterator/Flex/Permute.pm »