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