Iterator.pm

filter: Statementstmt 75.6% 31 / 41 Branchbran 57.1% 8 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 100% 4 / 4 totaltotal 69.3% 52 / 75 SCAR 24.4
CC
9
Cov
69%
_isa
6.0
new
6.0
get_all
6.0
CRAP 11.4
« Util.pm ↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Lazy::Iterator;
5 1 $Lazy::Iterator::VERSION = '0.003';
6 #ABSTRACT: Objects encapsulating a set of lazy evaluation functions.
7  
8  
9 1 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util qw/ blessed /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use constant SCALAR_DEFER => eval { require Scalar::Defer; 1 };
Subroutine BEGIN: called CC=1 SCAR=0.1
13  
14 0 ▶sub _isa { defined blessed $_[0] and $_[0]->isa($_[1]); }
Subroutine _isa: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
defined builtin::blessed($_[0]) and $_[0]->isa($_[1]) 0 0 0
15  
16  
17 sub new {
18 37 ▶ my ($class, $source) = @_;
Subroutine new: called CC=4 SCAR=17.9
Pod documented
19  
20 37 ▶ if (SCALAR_DEFER and _isa($source, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&SCALAR_DEFER() and _isa($source, 0)) 0 37 37
Condition33%1/3
&SCALAR_DEFER() and _isa($source, 0)
!ll&&!rl&&r
3700
MC/DC0%0/2
&SCALAR_DEFER() and _isa($source, 0)
&SCALAR_DEFER() _isa($source, 0)
Truth table33%1/3
A and B
A= &SCALAR_DEFER()B= _isa($source, 0)
ABresult
0X0
100
111
21 0 my $sd = $source;
22 0 ▶ $source = sub { Scalar::Defer::force $sd };
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 }
24  
25 37 ▶ croak "Not a CODE reference: $source" if ref $source ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $source ne "CODE" 0 37 37
26  
27 37 return bless {code => $source, exhausted => 0}, $class;
28 }
29  
30  
31 sub exhausted {
32 10 ▶ my $self = shift;
Subroutine exhausted: called CC=1 SCAR=0.0
Pod documented
33  
34 10 $self->{get} = $self->get();
35  
36 10 return $self->{exhausted};
37 }
38  
39  
40 sub get {
41 158 ▶ my $self = shift;
Subroutine get: called CC=4 SCAR=13.9
Pod documented
42  
43 158 ▶ return delete $self->{get} if exists $self->{get};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"get"} 1 157 158
44  
45 157 ▶ return undef if $self->{exhausted};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"exhausted"} 13 144 157
46  
47 144 my $ret = $self->{code}->();
48 144 ▶ $self->{exhausted} = 1 if not defined $ret;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret 32 112 144
49  
50 144 return $ret;
51 }
52  
53  
54 sub get_all {
55 0 ▶ my $self = shift;
Subroutine get_all: not called CC=2 SCAR=17.9
Pod documented
56  
57 0 my @res;
58 0 ▶ while (defined(my $get = $self->get())) { push @res, $get; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $get = $self->get)) 0 0 0
59  
60 0 return @res;
61 }
62  
63 1 1;
64  
65 __END__
« Util.pm ↑ Summary