line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Lazy::Util::OO; |
5
|
|
|
|
|
|
|
$Lazy::Util::OO::VERSION = '0.002'; |
6
|
|
|
|
|
|
|
#ABSTRACT: Objects encapsulating a set of lazy evaluation functions. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp qw/ croak /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw/ blessed /; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
89
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use constant SCALAR_DEFER => eval { require Scalar::Defer; 1 }; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
482
|
|
|
0
|
|
|
|
|
0
|
|
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
0
|
|
0
|
sub _isa { defined blessed $_[0] and $_[0]->isa($_[1]); } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
37
|
|
|
37
|
1
|
78
|
my ($class, $source) = @_; |
19
|
|
|
|
|
|
|
|
20
|
37
|
50
|
33
|
|
|
115
|
if (SCALAR_DEFER and _isa($source, 0)) { |
21
|
0
|
|
|
|
|
0
|
my $sd = $source; |
22
|
0
|
|
|
0
|
|
0
|
$source = sub { Scalar::Defer::force $sd }; |
|
0
|
|
|
|
|
0
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
37
|
50
|
|
|
|
99
|
croak "Not a CODE reference: $source" if ref $source ne 'CODE'; |
26
|
|
|
|
|
|
|
|
27
|
37
|
|
|
|
|
141
|
return bless {code => $source, exhausted => 0}, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub exhausted { |
32
|
10
|
|
|
10
|
1
|
23
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
23
|
$self->{get} = $self->get(); |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
39
|
return $self->{exhausted}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
41
|
158
|
|
|
158
|
1
|
4016
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
158
|
100
|
|
|
|
350
|
return delete $self->{get} if exists $self->{get}; |
44
|
|
|
|
|
|
|
|
45
|
157
|
100
|
|
|
|
321
|
return undef if $self->{exhausted}; |
46
|
|
|
|
|
|
|
|
47
|
144
|
|
|
|
|
297
|
my $ret = $self->{code}->(); |
48
|
144
|
100
|
|
|
|
323
|
$self->{exhausted} = 1 if not defined $ret; |
49
|
|
|
|
|
|
|
|
50
|
144
|
|
|
|
|
444
|
return $ret; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_all { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my @res; |
58
|
0
|
|
|
|
|
|
while (defined(my $get = $self->get())) { push @res, $get; } |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return @res; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |