line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Lazy::Iterator; |
5
|
|
|
|
|
|
|
$Lazy::Iterator::VERSION = '0.003'; |
6
|
|
|
|
|
|
|
#ABSTRACT: Objects encapsulating a set of lazy evaluation functions. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp qw/ croak /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
10
|
1
|
|
|
1
|
|
9
|
use Scalar::Util qw/ blessed /; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
170
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use constant SCALAR_DEFER => eval { require Scalar::Defer; 1 }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
497
|
|
|
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
|
86
|
my ($class, $source) = @_; |
19
|
|
|
|
|
|
|
|
20
|
37
|
50
|
33
|
|
|
124
|
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
|
|
|
|
108
|
croak "Not a CODE reference: $source" if ref $source ne 'CODE'; |
26
|
|
|
|
|
|
|
|
27
|
37
|
|
|
|
|
152
|
return bless {code => $source, exhausted => 0}, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub exhausted { |
32
|
10
|
|
|
10
|
1
|
19
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
22
|
$self->{get} = $self->get(); |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
37
|
return $self->{exhausted}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
41
|
158
|
|
|
158
|
1
|
5373
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
158
|
100
|
|
|
|
351
|
return delete $self->{get} if exists $self->{get}; |
44
|
|
|
|
|
|
|
|
45
|
157
|
100
|
|
|
|
328
|
return undef if $self->{exhausted}; |
46
|
|
|
|
|
|
|
|
47
|
144
|
|
|
|
|
310
|
my $ret = $self->{code}->(); |
48
|
144
|
100
|
|
|
|
318
|
$self->{exhausted} = 1 if not defined $ret; |
49
|
|
|
|
|
|
|
|
50
|
144
|
|
|
|
|
419
|
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__ |