File Coverage

blib/lib/Dist/Zilla/Plugin/FileFinder/Filter.pm
Criterion Covered Total %
statement 25 25 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 33 36 91.6


line stmt bran cond sub pod time code
1             # ABSTRACT: filter matches from other FileFinders
2              
3             use Moose;
4 2     2   2204 with(
  2         5  
  2         21  
5             'Dist::Zilla::Role::FileFinder',
6             'Dist::Zilla::Role::FileFinderUser' => {
7             default_finders => [],
8             },
9             );
10              
11             use Dist::Zilla::Pragmas;
12 2     2   15082  
  2         11  
  2         20  
13             use namespace::autoclean;
14 2     2   15  
  2         5  
  2         20  
15             #pod =head1 SYNOPSIS
16             #pod
17             #pod In your F<dist.ini>:
18             #pod
19             #pod [FileFinder::Filter / MyFiles]
20             #pod finder = :InstallModules ; find files from :InstallModules
21             #pod finder = :ExecFiles ; or :ExecFiles
22             #pod skip = ignore ; that don't have "ignore" in the path
23             #pod
24             #pod =head1 CREDITS
25             #pod
26             #pod This plugin was originally contributed by Christopher J. Madsen.
27             #pod
28             #pod =cut
29              
30             use Moose::Util::TypeConstraints;
31 2     2   204 use MooseX::Types::Moose qw(ArrayRef RegexpRef Str);
  2         7  
  2         20  
32 2     2   4692  
  2         10  
  2         37  
33             {
34             my $type = subtype as ArrayRef[RegexpRef];
35             coerce $type, from ArrayRef[Str], via { [map { qr/$_/ } @$_] };
36              
37             #pod =attr finder
38             #pod
39             #pod A FileFinder to supply the initial list of files.
40             #pod May occur multiple times.
41             #pod
42             #pod =attr skip
43             #pod
44             #pod The pathname must I<not> match any of these regular expressions.
45             #pod May occur multiple times.
46             #pod
47             #pod =cut
48              
49             has skips => (
50             is => 'ro',
51             isa => $type,
52             coerce => 1,
53             default => sub { [] },
54             );
55             }
56              
57             skip skips
58 3     3 0 462 ) } }
59              
60              
61             my $self = shift;
62              
63             my $files = $self->found_files;
64              
65 3     3 0 9 foreach my $re (@{ $self->skips }) {
66             @$files = grep { $_->name !~ $re } @$files;
67 3         17 }
68              
69 3         11 $self->log_debug("No files found") unless @$files;
  3         138  
70 2         8 $self->log_debug("Found " . $_->name) for @$files;
  16         44  
71              
72             $files;
73 3 50       13 }
74 3         14  
75             __PACKAGE__->meta->make_immutable;
76 3         70 1;
77              
78             #pod =head1 DESCRIPTION
79             #pod
80             #pod FileFinder::Filter is a L<FileFinder|Dist::Zilla::Role::FileFinder> that
81             #pod selects files by filtering the selections of other FileFinders.
82             #pod
83             #pod You specify one or more FileFinders to generate the initial list of
84             #pod files. Any file whose pathname matches any of the C<skip> regexs is
85             #pod removed from that list.
86             #pod
87             #pod =for Pod::Coverage
88             #pod mvp_aliases
89             #pod mvp_multivalue_args
90             #pod find_files
91              
92              
93             =pod
94              
95             =encoding UTF-8
96              
97             =head1 NAME
98              
99             Dist::Zilla::Plugin::FileFinder::Filter - filter matches from other FileFinders
100              
101             =head1 VERSION
102              
103             version 6.028
104              
105             =head1 SYNOPSIS
106              
107             In your F<dist.ini>:
108              
109             [FileFinder::Filter / MyFiles]
110             finder = :InstallModules ; find files from :InstallModules
111             finder = :ExecFiles ; or :ExecFiles
112             skip = ignore ; that don't have "ignore" in the path
113              
114             =head1 DESCRIPTION
115              
116             FileFinder::Filter is a L<FileFinder|Dist::Zilla::Role::FileFinder> that
117             selects files by filtering the selections of other FileFinders.
118              
119             You specify one or more FileFinders to generate the initial list of
120             files. Any file whose pathname matches any of the C<skip> regexs is
121             removed from that list.
122              
123             =head1 PERL VERSION
124              
125             This module should work on any version of perl still receiving updates from
126             the Perl 5 Porters. This means it should work on any version of perl released
127             in the last two to three years. (That is, if the most recently released
128             version is v5.40, then this module should work on both v5.40 and v5.38.)
129              
130             Although it may work on older versions of perl, no guarantee is made that the
131             minimum required version will not be increased. The version may be increased
132             for any reason, and there is no promise that patches will be accepted to lower
133             the minimum required perl.
134              
135             =head1 ATTRIBUTES
136              
137             =head2 finder
138              
139             A FileFinder to supply the initial list of files.
140             May occur multiple times.
141              
142             =head2 skip
143              
144             The pathname must I<not> match any of these regular expressions.
145             May occur multiple times.
146              
147             =head1 CREDITS
148              
149             This plugin was originally contributed by Christopher J. Madsen.
150              
151             =for Pod::Coverage mvp_aliases
152             mvp_multivalue_args
153             find_files
154              
155             =head1 AUTHOR
156              
157             Ricardo SIGNES 😏 <cpan@semiotic.systems>
158              
159             =head1 COPYRIGHT AND LICENSE
160              
161             This software is copyright (c) 2022 by Ricardo SIGNES.
162              
163             This is free software; you can redistribute it and/or modify it under
164             the same terms as the Perl 5 programming language system itself.
165              
166             =cut