| 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.004'; | |||||||||||||||||||||||||||
| 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 | 0 | ▶ | 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
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 39 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 39 | my ($class, $source) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 39 | ▶ | if (SCALAR_DEFER and _isa($source, 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&SCALAR_DEFER() and _isa($source, 0)
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)
| |||||||||||||||||||||||||||||
| 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 | 39 | ▶ | croak "Not a CODE reference: $source" if ref $source ne 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 39 | return bless {code => $source, exhausted => 0}, $class; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 12 | ▶ | sub exhausted { | ||||||||||||||||||||||||||
|
Subroutine
exhausted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 12 | unshift @{ $self->{get} }, $self->get(); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 12 | return $self->{exhausted}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 168 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 168 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 168 | ▶ | return shift @{ $self->{get} } if @{ $self->{get} || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'get'} || []
MC/DC100%1/1
$self->{'get'} || []
$self->{'get'}
Truth table100%2/2
A
A= $self->{'get'}
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 165 | ▶ | return undef if $self->{exhausted}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 152 | my $ret = $self->{code}->(); | |||||||||||||||||||||||||||
| 48 | 152 | ▶ | $self->{exhausted} = 1 if not defined $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 152 | return $ret; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub get_all { | ||||||||||||||||||||||||||
|
Subroutine
get_all: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my @res; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | while (defined(my $get = $self->get())) { push @res, $get; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return @res; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub unget { | ||||||||||||||||||||||||||
|
Subroutine
unget: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 1 | my $value = shift; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | croak "Can't unget an undefined value." if not defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | unshift @{ $self->{get} }, $value; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | return $self; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||