blib/lib/Dist/Zilla/Plugin/FileFinder/ByName.pm

filter: Statementstmt 100% 59 / 59 Branchbran 83.3% 5 / 6 Conditioncond 100% 15 / 15 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 3 totaltotal 96.1% 100 / 104 CC 10 SCAR 12.8
CC
10
Cov
99%
find_files
8.0
_join_re
3.0
BEGIN
1.0
CRAP 3.6
« blib/lib/Dist/Zilla/Path.pm ↑ Summary blib/lib/Dist/Zilla/Prereqs.pm »
1 package Dist::Zilla::Plugin::FileFinder::ByName 6.040;
2 # ABSTRACT: FileFinder matching on pathnames
3  
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 with 'Dist::Zilla::Role::FileFinder';
6  
7 2 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #pod =head1 SYNOPSIS
12 #pod
13 #pod In your F<dist.ini>:
14 #pod
15 #pod [FileFinder::ByName / MyFiles]
16 #pod dir = bin ; look in the bin/ directory
17 #pod dir = lib ; and the lib/ directory
18 #pod file = *.pl ; for .pl files
19 #pod match = \.pm$ ; and for .pm files
20 #pod skip = ignore ; that don't have "ignore" in the path
21 #pod
22 #pod =head1 CREDITS
23 #pod
24 #pod This plugin was originally contributed by Christopher J. Madsen.
25 #pod
26 #pod =cut
27  
28 2 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use MooseX::Types::Moose qw(ArrayRef RegexpRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use Text::Glob 0.08 qw(glob_to_regex_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 #pod =attr dir
34 #pod
35 #pod The file must be located in one of the specified directories (relative
36 #pod to the root directory of the dist).
37 #pod
38 #pod =attr file
39 #pod
40 #pod The filename must match one of the specified patterns (which are
41 #pod converted to regexs using L<Text::Glob> and combined with any C<match>
42 #pod rules).
43 #pod
44 #pod =cut
45  
46 has dirs => (
47 is => 'ro',
48 isa => ArrayRef[Str],
49 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 2 );
51  
52 has files => (
53 is => 'ro',
54 isa => ArrayRef[Str],
55 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
56 2 );
57  
58 {
59 2 my $type = subtype as ArrayRef[RegexpRef];
60 6 ▶ coerce $type, from ArrayRef[Str], via { [map { qr/$_/ } @$_] };
Subroutine __ANON__: called CC=1 SCAR=0.0
61  
62 #pod =attr match
63 #pod
64 #pod The pathname must match one of these regular expressions.
65 #pod
66 #pod =attr skip
67 #pod
68 #pod The pathname must I<not> match any of these regular expressions.
69 #pod
70 #pod =cut
71  
72 has matches => (
73 is => 'ro',
74 isa => $type,
75 coerce => 1,
76 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 2 );
78  
79 has skips => (
80 is => 'ro',
81 isa => $type,
82 coerce => 1,
83 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 2 );
85 }
86  
87 7 ▶sub mvp_aliases { +{ qw(
Subroutine mvp_aliases: called CC=1 SCAR=0.0
Pod undocumented
88 dir dirs
89 file files
90 match matches
91 matching matches
92 skip skips
93 except skips
94 ) } }
95  
96 7 ▶sub mvp_multivalue_args { qw(dirs files matches skips) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
97  
98 39 ▶sub _join_re {
Subroutine _join_re: called CC=3 SCAR=11.0
99 39 my $list = shift;
100 39 ▶ return undef unless @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list 17 22 39
101 # Special case to avoid stringify+compile
102 22 ▶ return $list->[0] if @$list == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$list == 1 14 8 22
103 # Wrap each element to ensure that alternations are isolated
104 8 my $re = join('|', map { "(?:$_)" } @$list);
105 8 qr/$re/
106 }
107  
108 13 ▶sub find_files {
Subroutine find_files: called CC=8 SCAR=20.8
Pod undocumented
109 13 my $self = shift;
110  
111 13 my $skip = _join_re($self->skips);
112 13 my $dir = _join_re([ map { qr!^\Q$_/! } @{ $self->dirs } ]);
113 my $match = _join_re([
114 8 (map { my $re = glob_to_regex_string($_); qr!(?:\A|/)$re\z! }
115 13 @{ $self->files }),
116 13 @{ $self->matches }
117 ]);
118  
119 13 my $files = $self->zilla->files;
120  
121 $files = [ grep {
122 13 my $name = $_->name;
123 455 ▶ (not defined $dir or $name =~ $dir) and
Condition100%15/15
(!defined($dir) || $name =~ /$dir/u) && (!defined($match) || $name =~ /$match/u) && !(defined $skip && $name =~ /$skip/u)
!ll&&!rl&&r
29634125
!defined($dir) || $name =~ /$dir/u and !defined($match) || $name =~ /$match/u
!ll&&!rl&&r
22472159
not defined $dir or $name =~ /$dir/u
l!l&&r!l&&!r
17556224
not defined $match or $name =~ /$match/u
l!l&&r!l&&!r
906972
defined $skip && $name =~ /$skip/u
!ll&&!rl&&r
725334
MC/DC100%6/6
(!defined($dir) || $name =~ /$dir/u) && (!defined($match) || $name =~ /$match/u) && !(defined $skip && $name =~ /$skip/u)
not defined $dir $name =~ /$dir/u not defined $match $name =~ /$match/u defined $skip $name =~ /$skip/u
Truth table73%11/15
not(A) or B and not(C) or D && not(E && F)
A= not defined $dirB= $name =~ /$dir/uC= not defined $matchD= $name =~ /$match/uE= defined $skipF= $name =~ /$skip/u
ABCDEFresult
00XXXX0
1X00XX0
0100XX0
1X1X110
1X01110
011X110
0101110
1X1X0X1
1X1X101
1X010X1
1X01101
011X0X1
011X101
01010X1
0101101
124 (not defined $match or $name =~ $match) and
125 (not defined $skip or $name !~ $skip)
126 } @$files ];
127  
128 13 ▶ $self->log_debug("No files found") unless @$files;
Branch: 1 branch
BranchTrueFalseTotal
unless @$files 0 13 13
129 13 $self->log_debug("Found " . $_->name) for @$files;
130  
131 13 $files;
132 }
133  
134 2 __PACKAGE__->meta->make_immutable;
135 2 1;
136  
137 #pod =head1 DESCRIPTION
138 #pod
139 #pod FileFinder::ByName is a L<FileFinder|Dist::Zilla::Role::FileFinder> that
140 #pod selects files by matching the criteria you specify against the pathname.
141 #pod
142 #pod There are three types of criteria you can use. C<dir> limits the
143 #pod search to a particular directory. C<match> is a regular expression
144 #pod that must match the pathname. C<skip> is a regular expression that
145 #pod must not match the pathname.
146 #pod
147 #pod Each key can be specified multiple times. Multiple occurrences of the
148 #pod same key are ORed together. Different keys are ANDed together. That
149 #pod means that to be selected, a file must be located in one of the
150 #pod C<dir>s, must match one of the C<match> regexs, and must not match any
151 #pod of the C<skip> regexs.
152 #pod
153 #pod Note that C<file> and C<match> are considered to be the I<same> key.
154 #pod They're just different ways to write a regex that the pathname must match.
155 #pod
156 #pod Omitting a particular key means that criterion will not apply to the
157 #pod search. Omitting all keys will select every file in your dist.
158 #pod
159 #pod Note: If you need to OR different types of criteria, then use more
160 #pod than one instance of FileFinder::ByName. A
161 #pod L<FileFinderUser|Dist::Zilla::Role::FileFinderUser> should allow you
162 #pod to specify more than one FileFinder to use.
163 #pod
164 #pod =for Pod::Coverage
165 #pod mvp_aliases
166 #pod mvp_multivalue_args
167 #pod find_files
168  
169 __END__
« blib/lib/Dist/Zilla/Path.pm ↑ Summary blib/lib/Dist/Zilla/Prereqs.pm »