Scanner.pm

filter: Statementstmt 98.5% 66 / 67 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 8 totaltotal 88.8% 88 / 99 SCAR 13.9
CC
4
Cov
96%
stream
3.1
concat
2.0
BEGIN
1.0
CRAP 4.0
« Scanner/StreamBuilder/Application.pm ↑ Summary Scanner/API/Stream.pm »
1 package Directory::Scanner;
2 # ABSTRACT: Streaming directory scanner
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 Directory::Scanner::API::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 8 ▶use Directory::Scanner::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use Directory::Scanner::StreamBuilder::Concat;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Directory::Scanner::StreamBuilder::Recursive;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Directory::Scanner::StreamBuilder::Matching;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use Directory::Scanner::StreamBuilder::Ignoring;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use Directory::Scanner::StreamBuilder::Application;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use Directory::Scanner::StreamBuilder::Transformer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 8 our $VERSION = '0.01';
22 8 our $AUTHORITY = 'cpan:STEVAN';
23  
24 ## static builder constructors
25  
26 sub for {
27 15 ▶ my (undef, $dir) = @_;
Subroutine for: called CC=1 SCAR=0.0
Pod undocumented
28 15 return bless [ $dir ] => __PACKAGE__;
29 }
30  
31 sub concat {
32 1 ▶ my (undef, @streams) = @_;
Subroutine concat: called CC=2 SCAR=7.1
Pod undocumented
33  
34 1 ▶ Carp::confess 'You provide at least two streams to concat'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @streams < 2 0 1 1
35 if scalar @streams < 2;
36  
37 1 return Directory::Scanner::StreamBuilder::Concat->new( streams => [ @streams ] );
38 }
39  
40 ## builder instance methods
41  
42 sub recurse {
43 12 ▶ my ($builder) = @_;
Subroutine recurse: called CC=1 SCAR=0.0
Pod undocumented
44 12 push @$builder => [ 'Directory::Scanner::StreamBuilder::Recursive' ];
45 12 return $builder;
46 }
47  
48 sub ignore {
49 3 ▶ my ($builder, $filter) = @_;
Subroutine ignore: called CC=1 SCAR=0.0
Pod undocumented
50 # XXX - should this support using at .gitignore files?
51 3 push @$builder => [ 'Directory::Scanner::StreamBuilder::Ignoring', filter => $filter ];
52 3 return $builder;
53 }
54  
55 sub match {
56 6 ▶ my ($builder, $predicate) = @_;
Subroutine match: called CC=1 SCAR=0.0
Pod undocumented
57 6 push @$builder => [ 'Directory::Scanner::StreamBuilder::Matching', predicate => $predicate ];
58 6 return $builder;
59 }
60  
61 sub apply {
62 2 ▶ my ($builder, $function) = @_;
Subroutine apply: called CC=1 SCAR=0.0
Pod undocumented
63 2 push @$builder => [ 'Directory::Scanner::StreamBuilder::Application', function => $function ];
64 2 return $builder;
65 }
66  
67 sub transform {
68 2 ▶ my ($builder, $transformer) = @_;
Subroutine transform: called CC=1 SCAR=0.0
Pod undocumented
69 2 push @$builder => [ 'Directory::Scanner::StreamBuilder::Transformer', transformer => $transformer ];
70 2 return $builder;
71 }
72  
73 ## builder method
74  
75 sub stream {
76 15 ▶ my ($builder) = @_;
Subroutine stream: called CC=3 SCAR=11.2
Pod undocumented
77  
78 15 ▶ if ( my $dir = shift @$builder ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = shift @$builder) { } 15 0 15
79 15 my $stream = Directory::Scanner::Stream->new( origin => $dir );
80  
81 15 foreach my $layer ( @$builder ) {
82 25 my ($class, %args) = @$layer;
83 25 $stream = $class->new( stream => $stream, %args );
84 }
85  
86 15 return $stream;
87 }
88 else {
89 0 Carp::confess 'Nothing to construct a stream on';
90 }
91 }
92  
93 8 1;
94  
95 __END__
« Scanner/StreamBuilder/Application.pm ↑ Summary Scanner/API/Stream.pm »