| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Wrap a callback iterator to allow variable look-ahead. |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package File::Chunk::Iter; |
|
4
|
|
|
|
|
|
|
{ |
|
5
|
|
|
|
|
|
|
$File::Chunk::Iter::VERSION = '0.0035'; |
|
6
|
|
|
|
|
|
|
} |
|
7
|
|
|
|
|
|
|
BEGIN { |
|
8
|
1
|
|
|
1
|
|
83562
|
$File::Chunk::Iter::AUTHORITY = 'cpan:DHARDISON'; |
|
9
|
|
|
|
|
|
|
} |
|
10
|
1
|
|
|
1
|
|
487
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use namespace::autoclean; |
|
12
|
|
|
|
|
|
|
use Carp; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'iter' => ( |
|
15
|
|
|
|
|
|
|
traits => ['Code'], |
|
16
|
|
|
|
|
|
|
is => 'ro', |
|
17
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
18
|
|
|
|
|
|
|
required => 1, |
|
19
|
|
|
|
|
|
|
handles => { _next => 'execute' }, |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'look_ahead' => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
isa => 'Int', |
|
25
|
|
|
|
|
|
|
default => 2, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has '_queue' => ( |
|
29
|
|
|
|
|
|
|
traits => ['Array'], |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'ArrayRef', |
|
32
|
|
|
|
|
|
|
default => sub { [] }, |
|
33
|
|
|
|
|
|
|
handles => { |
|
34
|
|
|
|
|
|
|
next => 'shift', |
|
35
|
|
|
|
|
|
|
at => 'get', |
|
36
|
|
|
|
|
|
|
_size => 'count', |
|
37
|
|
|
|
|
|
|
_push => 'push', |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub BUILD { |
|
42
|
|
|
|
|
|
|
my $self = shift; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
croak "look-ahead must be > 1!" unless $self->look_ahead > 1; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
while ($self->_size < $self->look_ahead) { |
|
47
|
|
|
|
|
|
|
$self->_look_ahead or last; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
after 'next' => sub { |
|
52
|
|
|
|
|
|
|
my $self = shift; |
|
53
|
|
|
|
|
|
|
$self->_look_ahead; |
|
54
|
|
|
|
|
|
|
}; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# true if ->next would be undef |
|
57
|
|
|
|
|
|
|
sub is_done { |
|
58
|
|
|
|
|
|
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return 0 if $self->_size == 0; |
|
61
|
|
|
|
|
|
|
return not defined $self->at(0); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub is_last { |
|
65
|
|
|
|
|
|
|
my $self = shift; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return 0 if $self->_size == 0; |
|
68
|
|
|
|
|
|
|
return not defined $self->at(1); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _look_ahead { |
|
72
|
|
|
|
|
|
|
my $self = shift; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
unless ($self->is_done) { |
|
75
|
|
|
|
|
|
|
my $next = $self->_next; |
|
76
|
|
|
|
|
|
|
$self->_push( $next ); |
|
77
|
|
|
|
|
|
|
unless (defined $next) { |
|
78
|
|
|
|
|
|
|
return 0 |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
else { |
|
82
|
|
|
|
|
|
|
$self->_push(undef); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if ($self->_size > $self->look_ahead) { |
|
86
|
|
|
|
|
|
|
croak "we traveled farther than look-ahead!"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
return 1; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
File::Chunk::Iter - Wrap a callback iterator to allow variable look-ahead. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 VERSION |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
version 0.0035 |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Dylan William Hardison <dylan@hardison.net> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Infinity Interactive, Inc. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
118
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |