Scanner/StreamBuilder/Transformer.pm

filter: Statementstmt 96.0% 48 / 50 Branchbran 60.0% 6 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 84.2% 16 / 19 Podpod 14.2% 1 / 7 totaltotal 77.6% 73 / 94 SCAR 21.0
CC
8
Cov
86%
BUILD
5.9
next
3.0
BEGIN
2.0
CRAP 8.2
« Scanner/StreamBuilder/Recursive.pm ↑ Summary Scanner/StreamBuilder/Ignoring.pm »
1 package Directory::Scanner::StreamBuilder::Transformer;
2 # ABSTRACT: Fmap a streaming directory iterator
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use UNIVERSAL::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Directory::Scanner::API::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 our $VERSION = '0.01';
14 8 our $AUTHORITY = 'cpan:STEVAN';
15  
16 8 ▶use constant DEBUG => $ENV{DIR_SCANNER_STREAM_TRANSFORMER_DEBUG} // 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"DIR_SCANNER_STREAM_TRANSFORMER_DEBUG"} // 0
l!l
08
MC/DC0%0/1
$ENV{"DIR_SCANNER_STREAM_TRANSFORMER_DEBUG"} // 0
$ENV{"DIR_SCANNER_STREAM_TRANSFORMER_DEBUG"}
Truth table50%1/2
A
A= $ENV{"DIR_SCANNER_STREAM_TRANSFORMER_DEBUG"}
Aresult
11
00
17  
18 ## ...
19  
20 8 ▶our @ISA; BEGIN { @ISA = ('UNIVERSAL::Object', 'Directory::Scanner::API::Stream') }
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 our %HAS; BEGIN {
22 %HAS = (
23 ▶ stream => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
24 ▶ transformer => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
25 # internal state ...
26 ▶ _head => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
27 )
28 8 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 ## ...
31  
32 sub BUILD {
33 2 ▶ my $self = $_[0];
Subroutine BUILD: called CC=5 SCAR=17.8
Pod documented
34 2 my $stream = $self->{stream};
35 2 my $f = $self->{transformer};
36  
37 2 ▶ (Scalar::Util::blessed($stream) && $stream->DOES('Directory::Scanner::API::Stream'))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($stream) and $stream->DOES("Directory::Scanner::API::Stream") or Carp::confess("You must supply a directory stream") 0 2 2
Condition33%1/3
builtin::blessed($stream) and $stream->DOES("Directory::Scanner::API::Stream")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($stream) and $stream->DOES("Directory::Scanner::API::Stream")
builtin::blessed($stream) $stream->DOES("Directory::Scanner::API::Stream")
Truth table33%1/3
A and B
A= builtin::blessed($stream)B= $stream->DOES("Directory::Scanner::API::Stream")
ABresult
0X0
100
111
38 || Carp::confess 'You must supply a directory stream';
39  
40 2 ▶ (defined $f)
Branch: 1 branch
BranchTrueFalseTotal
defined $f or Carp::confess("You must supply a `transformer` value") 0 2 2
41 || Carp::confess 'You must supply a `transformer` value';
42  
43 2 ▶ (ref $f eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
ref $f eq "CODE" or Carp::confess("The `transformer` value supplied must be a CODE reference") 0 2 2
44 || Carp::confess 'The `transformer` value supplied must be a CODE reference';
45 }
46  
47 sub clone {
48 0 ▶ my ($self, $dir) = @_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
49 return $self->new(
50 stream => $self->{stream}->clone( $dir ),
51 transformer => $self->{transformer}
52 0 );
53 }
54  
55 ## delegate
56  
57 9 ▶sub head { $_[0]->{_head} }
Subroutine head: called CC=1 SCAR=0.0
Pod undocumented
58 4 ▶sub is_done { $_[0]->{stream}->is_done }
Subroutine is_done: called CC=1 SCAR=0.0
Pod undocumented
59 6 ▶sub is_closed { $_[0]->{stream}->is_closed }
Subroutine is_closed: called CC=1 SCAR=0.0
Pod undocumented
60 2 ▶sub close { $_[0]->{stream}->close }
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
61  
62 sub next {
63 12 ▶ my $self = $_[0];
Subroutine next: called CC=3 SCAR=11.0
Pod undocumented
64  
65 # skip out early if possible
66 12 ▶ return if $self->{stream}->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stream"}->is_done 0 12 12
67  
68 12 $self->_log('... calling next on underlying stream') if DEBUG;
69 12 my $next = $self->{stream}->next;
70  
71 # this means the stream is likely exhausted
72 12 ▶ unless ( defined $next ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $next) 2 10 12
73 2 $self->{_head} = undef;
74 2 return;
75 }
76  
77 10 $self->_log('got value from stream'.$next.', transforming it now') if DEBUG;
78  
79 # return the result of the Fmap
80 10 local $_ = $next;
81 10 return $self->{_head} = $self->{transformer}->( $next );
82 }
83  
84 8 1;
85  
86 __END__
« Scanner/StreamBuilder/Recursive.pm ↑ Summary Scanner/StreamBuilder/Ignoring.pm »