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