LINQ/Iterator.pm

filter: Statementstmt 99.0% 99 / 100 Branchbran 97.0% 33 / 34 Conditioncond 85.7% 12 / 14 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 21 / 21 Podpod 100% 5 / 5 totaltotal 96.6% 174 / 180 CC 22 SCAR 14.6
CC
22
Cov
97%
extend_to
11.0
fetch_ref
3.0
element_at
3.0
CRAP 4.3
« LINQ/Util/Internal.pm ↑ Summary LINQ/Collection.pm »
1 100 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 100 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 100 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 100 ▶if ( $] < 5.010000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.01") 0 100 100
6 0 require UNIVERSAL::DOES;
7 }
8  
9 {
10 package # hide from PAUSE
11 LINQ::Iterator::_LazyList;
12
13 2 ▶ my $_throw_caller_error = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
14 2 shift;
15 2 require LINQ::Exception;
16 2 'LINQ::Exception::CallerError'->throw( message => @_ );
17 100 };
18
19 sub __GENERATOR () { 0 }
20 sub __EXHAUSTED () { 1 }
21 sub __VALUES () { 2 }
22 sub __NEXT_SLOT () { 3 }
23
24 668 ▶ sub TIEARRAY {
Subroutine TIEARRAY: called CC=1 SCAR=0.0
25 668 my $class = shift;
26 668 bless [
27 $_[0],
28 !!0,
29 [],
30 ], $class;
31 }
32
33 1180 ▶ sub FETCH {
Subroutine FETCH: called CC=2 SCAR=6.9
34 1180 my $self = shift;
35 1180 my ( $ix ) = @_;
36 1180 my $cache = $self->[__VALUES];
37
38 1180 $self->extend_to( $ix );
39
40 1180 ▶ $ix >= @$cache ? undef : $cache->[$ix];
Branch: 1 branch
BranchTrueFalseTotal
$ix >= @$cache ? : 1 1179 1180
41 }
42
43 1532 ▶ sub fetch_ref {
Subroutine fetch_ref: called CC=3 SCAR=11.0
44 1532 my $self = shift;
45 1532 my ( $ix ) = @_;
46 1532 my $cache = $self->[__VALUES];
47
48 1532 $self->extend_to( $ix );
49
50 1530 ▶ return if $ix > 0+ $#$cache;
Branch: 1 branch
BranchTrueFalseTotal
if $ix > 0 + $cache->$#* 163 1367 1530
51 1367 ▶ return if $ix < 0 - @$cache;
Branch: 1 branch
BranchTrueFalseTotal
if $ix < 0 - @$cache 2 1365 1367
52 1365 \( $cache->[$ix] );
53 } #/ sub fetch_ref
54
55 856 ▶ sub FETCHSIZE {
Subroutine FETCHSIZE: called CC=1 SCAR=0.0
56 856 my $self = shift;
57 856 $self->extend_to( -1 );
58 839 scalar @{ $self->[__VALUES] };
59 }
60
61 2 ▶ sub current_extension {
Subroutine current_extension: called CC=1 SCAR=0.0
62 2 my $self = shift;
63 2 scalar @{ $self->[__VALUES] };
64 }
65
66 1 ▶ sub is_fully_extended {
Subroutine is_fully_extended: called CC=1 SCAR=0.0
67 1 my $self = shift;
68 1 $self->[__EXHAUSTED];
69 }
70
71 3568 ▶ sub extend_to {
Subroutine extend_to: called CC=11 SCAR=24.0
72 3568 require LINQ;
73
74 3568 my $self = shift;
75 3568 my ( $ix ) = @_;
76 3568 my $cache = $self->[__VALUES];
77
78 EXTEND: {
79 3568 ▶ return if $self->[__EXHAUSTED];
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1] 1849 3966 5815
80 3966 ▶ return if $ix >= 0 && $ix < @$cache;
Branch: 1 branch
BranchTrueFalseTotal
if $ix >= 0 and $ix < @$cache 1242 2724 3966
Condition100%3/3
$ix >= 0 and $ix < @$cache
!ll&&!rl&&r
155411701242
MC/DC100%2/2
$ix >= 0 and $ix < @$cache
$ix >= 0 $ix < @$cache
Truth table100%3/3
A and B
A= $ix >= 0B= $ix < @$cache
ABresult
0X0
100
111
81
82 2724 my @got = $self->[__GENERATOR]->();
83 2707 my $got;
84
85 # Crazy optimized loop to find and handle LINQ::END
86 # within @got
87 # uncoverable condition count:1
88 # uncoverable condition count:5
89 2707 ▶ push( @$cache, shift @got )
Branch: 3 branches
BranchTrueFalseTotal
@got and 2709 2247 4956
and @got ? $self->$_throw_caller_error("Returned values after LINQ::END") : (return ()) 460 2249 2709
@got ? : 2 458 460
Condition81%9/11
and pop @$cache
!ll&&!rl&&r
22490460
push @$cache, shift @got and ref($got = $cache->[-1]) and $got == &LINQ::END() and
!ll
2249460
push @$cache, shift @got and ref($got = $cache->[-1]) and $got == &LINQ::END()
!ll&&!rl&&r
12371012460
push @$cache, shift @got and ref($got = $cache->[-1])
!ll&&!rl&&r
012371472
MC/DC50%2/4
and pop @$cache
push @$cache, shift @got ref($got = $cache->[-1]) $got == &LINQ::END() pop @$cache
Truth table60%3/5
A and B and C and D
A= push @$cache, shift @gotB= ref($got = $cache->[-1])C= $got == &LINQ::END()D= pop @$cache
ABCDresult
0XXX0
10XX0
110X0
11100
11111
90 and ref( $got = $cache->[-1] )
91 and $got == LINQ::END()
92 and ( $self->[__EXHAUSTED] = !!1 )
93 and pop( @$cache )
94 and (
95 @got
96 ? $self->$_throw_caller_error( 'Returned values after LINQ::END' )
97 : return ()
98 ) while @got;
99
100 2247 redo EXTEND;
101 } #/ EXTEND:
102 } #/ sub extend_to
103 }
104  
105 100 package LINQ::Iterator;
106  
107 100 our $AUTHORITY = 'cpan:TOBYINK';
108 100 our $VERSION = '0.003';
109  
110 100 ▶use Role::Tiny::With ();
Subroutine BEGIN: called CC=1 SCAR=0.0
111 100 ▶use LINQ::Util::Internal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
112  
113 100 Role::Tiny::With::with( qw( LINQ::Collection ) );
114  
115 538 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
116 538 my $class = shift;
117 538 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 537 1 538
118 537 tie my ( @arr ), 'LINQ::Iterator::_LazyList',
119 LINQ::Util::Internal::assert_code( @_ );
120 537 return bless \@arr, $class;
121 }
122 LINQ::Util::Internal::throw(
123 1 "CallerError",
124 message => "Expected a coderef"
125 );
126 } #/ sub new
127  
128 433 ▶sub _guts {
Subroutine _guts: called CC=1 SCAR=0.0
129 433 my $self = shift;
130 433 tied( @$self );
131 }
132  
133 266 ▶sub to_list {
Subroutine to_list: called CC=2 SCAR=6.9
Pod documented
134 266 my $self = shift;
135 266 my @list = @$self;
136
137 # We must have exhausted the iterator now,
138 # so remove all the magic and act like a
139 # plain old arrayref.
140 #
141 249 ▶ if ( tied( @$self ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (tied @$self) 184 65 249
142 100 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
143 184 untie( @$self );
144 184 @$self = @list;
145 }
146
147 249 @list;
148 } #/ sub to_list
149  
150  
151 134 ▶sub to_array {
Subroutine to_array: called CC=2 SCAR=6.9
Pod documented
152 134 my $self = shift;
153
154 134 ▶ if ( my $guts = $self->_guts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $guts = $self->_guts) 131 3 134
155 131 tie ( my @tied, 'LINQ::Iterator::_LazyList', undef );
156 131 @{ tied( @tied ) } = @$guts;
157 131 return \@tied;
158 }
159
160 3 $self->LINQ::Collection::to_array( @_ );
161 }
162  
163 61 ▶sub element_at {
Subroutine element_at: called CC=3 SCAR=11.0
Pod documented
164 61 my $self = shift;
165
166 61 ▶ if ( my $guts = $self->_guts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $guts = $self->_guts) 27 34 61
167 27 my $ref = $guts->fetch_ref( @_ );
168 27 ▶ return $$ref if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 23 4 27
169 4 require LINQ::Exception;
170 4 'LINQ::Exception::NotFound'->throw( collection => $self );
171 }
172
173 34 $self->LINQ::Collection::element_at( @_ );
174 } #/ sub element_at
175  
176 233 ▶sub to_iterator {
Subroutine to_iterator: called CC=2 SCAR=6.9
Pod documented
177 233 my $self = shift;
178
179 233 ▶ if ( my $guts = $self->_guts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $guts = $self->_guts) 231 2 233
180 231 my $idx = 0;
181 231 my $done = 0;
182 1506 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
183 1506 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 1 1505 1506
184 1505 my $val = $guts->fetch_ref( $idx++ );
185 1503 ▶ return $$val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 1342 161 1503
186 161 ++$done;
187 161 return;
188 231 };
189 } #/ if ( my $guts = $self->...)
190
191 2 $self->LINQ::Collection::to_iterator( @_ );
192 } #/ sub to_iterator
193  
194 100 1;
195  
196 __END__
« LINQ/Util/Internal.pm ↑ Summary LINQ/Collection.pm »