line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Lazy::Iterator; |
5
|
|
|
|
|
|
|
$Lazy::Iterator::VERSION = '0.004'; |
6
|
|
|
|
|
|
|
#ABSTRACT: Objects encapsulating a set of lazy evaluation functions. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use Carp qw/ croak /; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw/ blessed /; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
94
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use constant SCALAR_DEFER => eval { require Scalar::Defer; 1 }; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
488
|
|
|
0
|
|
|
|
|
0
|
|
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
0
|
|
0
|
sub _isa { defined blessed $_[0] and $_[0]->isa($_[1]); } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
39
|
|
|
39
|
1
|
78
|
my ($class, $source) = @_; |
19
|
|
|
|
|
|
|
|
20
|
39
|
50
|
33
|
|
|
139
|
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
|
39
|
50
|
|
|
|
102
|
croak "Not a CODE reference: $source" if ref $source ne 'CODE'; |
26
|
|
|
|
|
|
|
|
27
|
39
|
|
|
|
|
147
|
return bless {code => $source, exhausted => 0}, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub exhausted { |
32
|
12
|
|
|
12
|
1
|
29
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
12
|
|
|
|
|
17
|
unshift @{ $self->{get} }, $self->get(); |
|
12
|
|
|
|
|
35
|
|
35
|
|
|
|
|
|
|
|
36
|
12
|
|
|
|
|
43
|
return $self->{exhausted}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
41
|
168
|
|
|
168
|
1
|
4942
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
168
|
100
|
|
|
|
214
|
return shift @{ $self->{get} } if @{ $self->{get} || [] }; |
|
3
|
100
|
|
|
|
14
|
|
|
168
|
|
|
|
|
703
|
|
44
|
|
|
|
|
|
|
|
45
|
165
|
100
|
|
|
|
367
|
return undef if $self->{exhausted}; |
46
|
|
|
|
|
|
|
|
47
|
152
|
|
|
|
|
322
|
my $ret = $self->{code}->(); |
48
|
152
|
100
|
|
|
|
327
|
$self->{exhausted} = 1 if not defined $ret; |
49
|
|
|
|
|
|
|
|
50
|
152
|
|
|
|
|
442
|
return $ret; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_all { |
55
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my @res; |
58
|
0
|
|
|
|
|
0
|
while (defined(my $get = $self->get())) { push @res, $get; } |
|
0
|
|
|
|
|
0
|
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
return @res; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub unget { |
65
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
66
|
1
|
|
|
|
|
3
|
my $value = shift; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
5
|
croak "Can't unget an undefined value." if not defined $value; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
unshift @{ $self->{get} }, $value; |
|
1
|
|
|
|
|
6
|
|
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
4
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |