line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Directory::Scanner::Stream::Transformer; |
2
|
|
|
|
|
|
|
# ABSTRACT: Fmap a streaming directory iterator |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
7
|
use Carp (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
19
|
|
8
|
2
|
|
|
2
|
|
6
|
use Scalar::Util (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
91
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
50
|
2
|
|
10
|
use constant DEBUG => $ENV{DIR_SCANNER_STREAM_TRANSFORMER_DEBUG} // 0; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
97
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
## ... |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
9
|
use parent 'UNIVERSAL::Object'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
18
|
2
|
|
|
2
|
|
108
|
use roles 'Directory::Scanner::API::Stream'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
7
|
|
19
|
|
|
|
|
|
|
use slots ( |
20
|
|
|
|
|
|
|
stream => sub {}, |
21
|
|
|
|
|
|
|
transformer => sub {}, |
22
|
|
|
|
|
|
|
# internal state ... |
23
|
|
|
|
|
|
|
_head => sub {}, |
24
|
2
|
|
|
2
|
|
574
|
); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
18
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
## ... |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub BUILD { |
29
|
3
|
|
|
3
|
1
|
65
|
my $self = $_[0]; |
30
|
3
|
|
|
|
|
8
|
my $stream = $self->{stream}; |
31
|
3
|
|
|
|
|
3
|
my $f = $self->{transformer}; |
32
|
|
|
|
|
|
|
|
33
|
3
|
50
|
33
|
|
|
15
|
(Scalar::Util::blessed($stream) && $stream->roles::DOES('Directory::Scanner::API::Stream')) |
34
|
|
|
|
|
|
|
|| Carp::confess 'You must supply a directory stream'; |
35
|
|
|
|
|
|
|
|
36
|
3
|
50
|
|
|
|
438
|
(defined $f) |
37
|
|
|
|
|
|
|
|| Carp::confess 'You must supply a `transformer` value'; |
38
|
|
|
|
|
|
|
|
39
|
3
|
50
|
|
|
|
9
|
(ref $f eq 'CODE') |
40
|
|
|
|
|
|
|
|| Carp::confess 'The `transformer` value supplied must be a CODE reference'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub clone { |
44
|
0
|
|
|
0
|
0
|
0
|
my ($self, $dir) = @_; |
45
|
|
|
|
|
|
|
return $self->new( |
46
|
|
|
|
|
|
|
stream => $self->{stream}->clone( $dir ), |
47
|
|
|
|
|
|
|
transformer => $self->{transformer} |
48
|
0
|
|
|
|
|
0
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
## delegate |
52
|
|
|
|
|
|
|
|
53
|
12
|
|
|
12
|
0
|
1239
|
sub head { $_[0]->{_head} } |
54
|
5
|
|
|
5
|
0
|
2509
|
sub is_done { $_[0]->{stream}->is_done } |
55
|
8
|
|
|
8
|
0
|
1130
|
sub is_closed { $_[0]->{stream}->is_closed } |
56
|
3
|
|
|
3
|
0
|
186
|
sub close { $_[0]->{stream}->close } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub next { |
59
|
15
|
|
|
15
|
0
|
3875
|
my $self = $_[0]; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# skip out early if possible |
62
|
15
|
50
|
|
|
|
33
|
return if $self->{stream}->is_done; |
63
|
|
|
|
|
|
|
|
64
|
15
|
|
|
|
|
21
|
$self->_log('... calling next on underlying stream') if DEBUG; |
65
|
15
|
|
|
|
|
26
|
my $next = $self->{stream}->next; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# this means the stream is likely exhausted |
68
|
15
|
100
|
|
|
|
27
|
unless ( defined $next ) { |
69
|
3
|
|
|
|
|
5
|
$self->{_head} = undef; |
70
|
3
|
|
|
|
|
7
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
12
|
|
|
|
|
13
|
$self->_log('got value from stream'.$next.', transforming it now') if DEBUG; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# return the result of the Fmap |
76
|
12
|
|
|
|
|
16
|
local $_ = $next; |
77
|
12
|
|
|
|
|
25
|
return $self->{_head} = $self->{transformer}->( $next ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |