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