line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Directory::Scanner::StreamBuilder::Application; |
2
|
|
|
|
|
|
|
# ABSTRACT: Apply function to streaming directory iterator |
3
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
48
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
222
|
|
5
|
8
|
|
|
8
|
|
38
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
160
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
32
|
use Carp (); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
87
|
|
8
|
8
|
|
|
8
|
|
29
|
use Scalar::Util (); |
|
8
|
|
|
|
|
202
|
|
|
8
|
|
|
|
|
155
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
41
|
use UNIVERSAL::Object; |
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
141
|
|
11
|
8
|
|
|
8
|
|
35
|
use Directory::Scanner::API::Stream; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
370
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
15
|
|
|
|
|
|
|
|
16
|
8
|
|
50
|
8
|
|
37
|
use constant DEBUG => $ENV{DIR_SCANNER_STREAM_APPLICATION_DEBUG} // 0; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
567
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
## ... |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
8
|
|
487
|
our @ISA; BEGIN { @ISA = ('UNIVERSAL::Object', 'Directory::Scanner::API::Stream') } |
21
|
|
|
|
|
|
|
our %HAS; BEGIN { |
22
|
|
|
|
|
|
|
%HAS = ( |
23
|
|
|
|
|
|
|
stream => sub {}, |
24
|
|
|
|
|
|
|
function => sub {}, |
25
|
|
|
|
|
|
|
) |
26
|
8
|
|
|
8
|
|
2181
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
## ... |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub BUILD { |
31
|
2
|
|
|
2
|
1
|
123
|
my $self = $_[0]; |
32
|
2
|
|
|
|
|
6
|
my $stream = $self->{stream}; |
33
|
2
|
|
|
|
|
4
|
my $f = $self->{function}; |
34
|
|
|
|
|
|
|
|
35
|
2
|
50
|
33
|
|
|
20
|
(Scalar::Util::blessed($stream) && $stream->DOES('Directory::Scanner::API::Stream')) |
36
|
|
|
|
|
|
|
|| Carp::confess 'You must supply a directory stream'; |
37
|
|
|
|
|
|
|
|
38
|
2
|
50
|
|
|
|
7
|
(defined $f) |
39
|
|
|
|
|
|
|
|| Carp::confess 'You must supply a `function` value'; |
40
|
|
|
|
|
|
|
|
41
|
2
|
50
|
|
|
|
7
|
(ref $f eq 'CODE') |
42
|
|
|
|
|
|
|
|| Carp::confess 'The `function` value supplied must be a CODE reference'; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub clone { |
46
|
0
|
|
|
0
|
1
|
0
|
my ($self, $dir) = @_; |
47
|
|
|
|
|
|
|
return $self->new( |
48
|
|
|
|
|
|
|
stream => $self->{stream}->clone( $dir ), |
49
|
|
|
|
|
|
|
function => $self->{function} |
50
|
0
|
|
|
|
|
0
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## delegate |
54
|
|
|
|
|
|
|
|
55
|
9
|
|
|
9
|
1
|
793
|
sub head { $_[0]->{stream}->head } |
56
|
4
|
|
|
4
|
1
|
6653
|
sub is_done { $_[0]->{stream}->is_done } |
57
|
6
|
|
|
6
|
1
|
754
|
sub is_closed { $_[0]->{stream}->is_closed } |
58
|
2
|
|
|
2
|
1
|
162
|
sub close { $_[0]->{stream}->close } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub next { |
61
|
12
|
|
|
12
|
1
|
2787
|
my $self = $_[0]; |
62
|
12
|
|
|
|
|
32
|
my $next = $self->{stream}->next; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# this means the stream is likely exhausted |
65
|
12
|
100
|
|
|
|
30
|
return unless defined $next; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# apply the function ... |
68
|
10
|
|
|
|
|
16
|
local $_ = $next; |
69
|
10
|
|
|
|
|
28
|
$self->{function}->( $next ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# return the next value |
72
|
10
|
|
|
|
|
1904
|
return $next; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |