| 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::Util::OO; | ||||||||||||||||||||||||||||
| 5 | 1 | $Lazy::Util::OO::VERSION = '0.002'; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
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 | 37 | ▶ | croak "Not a CODE reference: $source" if ref $source ne 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 157 | ▶ | return undef if $self->{exhausted}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 144 | my $ret = $self->{code}->(); | |||||||||||||||||||||||||||
| 48 | 144 | ▶ | $self->{exhausted} = 1 if not defined $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return @res; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||