Scanner/StreamBuilder/Matching.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 70.0% 7 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 83.3% 15 / 18 Podpod 14.2% 1 / 7 totaltotal 78.9% 75 / 95 SCAR 20.9
CC
8
Cov
88%
BUILD
5.9
next
3.0
BEGIN
2.0
CRAP 8.1
« Scanner/StreamBuilder/Ignoring.pm ↑ Summary Scanner/StreamBuilder/Application.pm »
1 package Directory::Scanner::StreamBuilder::Matching;
2 # ABSTRACT: Filtered 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_MATCHING_DEBUG} // 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"DIR_SCANNER_STREAM_MATCHING_DEBUG"} // 0
l!l
08
MC/DC0%0/1
$ENV{"DIR_SCANNER_STREAM_MATCHING_DEBUG"} // 0
$ENV{"DIR_SCANNER_STREAM_MATCHING_DEBUG"}
Truth table50%1/2
A
A= $ENV{"DIR_SCANNER_STREAM_MATCHING_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 ▶ predicate => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
25 )
26 8 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 ## ...
29  
30 sub BUILD {
31 6 ▶ my $self = $_[0];
Subroutine BUILD: called CC=5 SCAR=17.8
Pod documented
32 6 my $stream = $self->{stream};
33 6 my $predicate = $self->{predicate};
34  
35 6 ▶ (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 6 6
Condition33%1/3
builtin::blessed($stream) and $stream->DOES("Directory::Scanner::API::Stream")
!ll&&!rl&&r
006
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
36 || Carp::confess 'You must supply a directory stream';
37  
38 6 ▶ (defined $predicate)
Branch: 1 branch
BranchTrueFalseTotal
defined $predicate or Carp::confess("You must supply a predicate") 0 6 6
39 || Carp::confess 'You must supply a predicate';
40  
41 6 ▶ (ref $predicate eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
ref $predicate eq "CODE" or Carp::confess("The predicate supplied must be a CODE reference") 0 6 6
42 || Carp::confess 'The predicate supplied must be a CODE reference';
43 }
44  
45 sub clone {
46 0 ▶ my ($self, $dir) = @_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
47 return $self->new(
48 stream => $self->{stream}->clone( $dir ),
49 predicate => $self->{predicate}
50 0 );
51 }
52  
53 ## delegate
54  
55 17 ▶sub head { $_[0]->{stream}->head }
Subroutine head: called CC=1 SCAR=0.0
Pod undocumented
56 24 ▶sub is_done { $_[0]->{stream}->is_done }
Subroutine is_done: called CC=1 SCAR=0.0
Pod undocumented
57 18 ▶sub is_closed { $_[0]->{stream}->is_closed }
Subroutine is_closed: called CC=1 SCAR=0.0
Pod undocumented
58 6 ▶sub close { $_[0]->{stream}->close }
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
59  
60 sub next {
61 34 ▶ my $self = $_[0];
Subroutine next: called CC=3 SCAR=11.0
Pod undocumented
62  
63 34 my $next;
64 34 while (1) {
65 60 undef $next; # clear any previous values, just cause ...
66 60 $self->_log('Entering loop ... ') if DEBUG;
67  
68 60 $next = $self->{stream}->next;
69  
70 # this means the stream is likely
71 # exhausted, so jump out of the loop
72 60 ▶ last unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 6 54 60
73  
74 # now try to predicate the value
75 # and redo the loop if it does
76 # not pass
77 54 local $_ = $next;
78 54 ▶ next unless $self->{predicate}->( $next );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"predicate"}->($next) 26 28 54
79  
80 28 $self->_log('Exiting loop ... ') if DEBUG;
81  
82 # if we have gotten to this
83 # point, we have a value and
84 # want to return it
85 28 last;
86 }
87  
88 34 return $next;
89 }
90  
91 8 1;
92  
93 __END__
« Scanner/StreamBuilder/Ignoring.pm ↑ Summary Scanner/StreamBuilder/Application.pm »