File Coverage

blib/lib/Dist/Zilla/Plugin/PruneFiles.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 3 0.0
total 31 34 91.1


line stmt bran cond sub pod time code
1             # ABSTRACT: prune arbitrary files from the dist
2              
3             use Moose;
4 2     2   2238 with 'Dist::Zilla::Role::FilePruner';
  2         5  
  2         18  
5              
6             use Dist::Zilla::Pragmas;
7 2     2   14308  
  2         6  
  2         19  
8             use namespace::autoclean;
9 2     2   15  
  2         5  
  2         19  
10             #pod =head1 SYNOPSIS
11             #pod
12             #pod This plugin allows you to explicitly prune some files from your
13             #pod distribution. You can either specify the exact set of files (with the
14             #pod "filenames" parameter) or provide the regular expressions to
15             #pod check (using "match").
16             #pod
17             #pod This is useful if another plugin (maybe a FileGatherer) adds a
18             #pod bunch of files, and you only want a subset of them.
19             #pod
20             #pod In your F<dist.ini>:
21             #pod
22             #pod [PruneFiles]
23             #pod filename = xt/release/pod-coverage.t ; pod coverage tests are for jerks
24             #pod filename = todo-list.txt ; keep our secret plans to ourselves
25             #pod
26             #pod match = ^test_data/
27             #pod match = ^test.cvs$
28             #pod
29             #pod =cut
30              
31              
32 3     3 0 732 #pod =attr filenames
33 3     3 0 473 #pod
34             #pod This is an arrayref of filenames to be pruned from the distribution.
35             #pod
36             #pod =cut
37              
38             has filenames => (
39             is => 'ro',
40             isa => 'ArrayRef',
41             default => sub { [] },
42             );
43              
44             #pod =attr matches
45             #pod
46             #pod This is an arrayref of regular expressions and files matching any of them,
47             #pod will be pruned from the distribution.
48             #pod
49             #pod =cut
50              
51             has matches => (
52             is => 'ro',
53             isa => 'ArrayRef',
54             default => sub { [] },
55             );
56              
57             my ($self) = @_;
58              
59             # never match (at least the filename characters)
60             my $matches_regex = qr/\000/;
61 3     3 0 10  
62             $matches_regex = qr/$matches_regex|$_/ for (@{ $self->matches });
63              
64 3         14 # \A\Q$_\E should also handle the `eq` check
65             $matches_regex = qr/$matches_regex|\A\Q$_\E/ for (@{ $self->filenames });
66 3         7  
  3         107  
67             # Copy list (break reference) so we can mutate.
68             for my $file ((), @{ $self->zilla->files }) {
69 3         8 next unless $file->name =~ $matches_regex;
  3         95  
70              
71             $self->log_debug([ 'pruning %s', $file->name ]);
72 3         9  
  3         89  
73 9 100       29 $self->zilla->prune_file($file);
74             }
75 4         16  
76             return;
77 4         209 }
78              
79             __PACKAGE__->meta->make_immutable;
80 3         17 1;
81              
82             #pod =head1 SEE ALSO
83             #pod
84             #pod Dist::Zilla plugins:
85             #pod L<PruneCruft|Dist::Zilla::Plugin::PruneCruft>,
86             #pod L<GatherDir|Dist::Zilla::Plugin::GatherDir>,
87             #pod L<ManifestSkip|Dist::Zilla::Plugin::ManifestSkip>.
88             #pod
89             #pod =cut
90              
91              
92             =pod
93              
94             =encoding UTF-8
95              
96             =head1 NAME
97              
98             Dist::Zilla::Plugin::PruneFiles - prune arbitrary files from the dist
99              
100             =head1 VERSION
101              
102             version 6.028
103              
104             =head1 SYNOPSIS
105              
106             This plugin allows you to explicitly prune some files from your
107             distribution. You can either specify the exact set of files (with the
108             "filenames" parameter) or provide the regular expressions to
109             check (using "match").
110              
111             This is useful if another plugin (maybe a FileGatherer) adds a
112             bunch of files, and you only want a subset of them.
113              
114             In your F<dist.ini>:
115              
116             [PruneFiles]
117             filename = xt/release/pod-coverage.t ; pod coverage tests are for jerks
118             filename = todo-list.txt ; keep our secret plans to ourselves
119              
120             match = ^test_data/
121             match = ^test.cvs$
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 filenames
138              
139             This is an arrayref of filenames to be pruned from the distribution.
140              
141             =head2 matches
142              
143             This is an arrayref of regular expressions and files matching any of them,
144             will be pruned from the distribution.
145              
146             =head1 SEE ALSO
147              
148             Dist::Zilla plugins:
149             L<PruneCruft|Dist::Zilla::Plugin::PruneCruft>,
150             L<GatherDir|Dist::Zilla::Plugin::GatherDir>,
151             L<ManifestSkip|Dist::Zilla::Plugin::ManifestSkip>.
152              
153             =head1 AUTHOR
154              
155             Ricardo SIGNES 😏 <cpan@semiotic.systems>
156              
157             =head1 COPYRIGHT AND LICENSE
158              
159             This software is copyright (c) 2022 by Ricardo SIGNES.
160              
161             This is free software; you can redistribute it and/or modify it under
162             the same terms as the Perl 5 programming language system itself.
163              
164             =cut