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