File Coverage

blib/lib/Dist/Zilla/Plugin/PruneCruft.pm
Criterion Covered Total %
statement 45 45 100.0
branch 24 36 66.6
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 77 92 83.7


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::PruneCruft 6.037;
2             # ABSTRACT: prune stuff that you probably don't mean to include
3              
4 10     10   32631 use Moose;
  10         25  
  10         89  
5 10     10   71678 use Moose::Util::TypeConstraints;
  10         23  
  10         210  
6             with 'Dist::Zilla::Role::FilePruner';
7              
8 10     10   19993 use Dist::Zilla::Pragmas;
  10         19  
  10         91  
9              
10 10     10   69 use namespace::autoclean;
  10         18  
  10         101  
11              
12             #pod =head1 SYNOPSIS
13             #pod
14             #pod This plugin tries to compensate for the stupid crap that turns up in your
15             #pod working copy, removing it before it gets into your dist and screws everything
16             #pod up.
17             #pod
18             #pod In your F<dist.ini>:
19             #pod
20             #pod [PruneCruft]
21             #pod
22             #pod If you would like to exclude certain exclusions, use the C<except> option (it
23             #pod can be specified multiple times):
24             #pod
25             #pod [PruneCruft]
26             #pod except = \.gitignore
27             #pod except = t/.*/\.keep$
28             #pod
29             #pod This plugin is included in the L<@Basic|Dist::Zilla::PluginBundle::Basic>
30             #pod bundle.
31             #pod
32             #pod =head1 SEE ALSO
33             #pod
34             #pod Dist::Zilla plugins:
35             #pod L<@Basic|Dist::Zilla::PluginBundle::Basic>,
36             #pod L<PruneFiles|Dist::Zilla::Plugin::PruneFiles>,
37             #pod L<ManifestSkip|Dist::Zilla::Plugin::ManifestSkip>.
38             #pod
39             #pod =cut
40              
41             {
42             my $type = subtype as 'ArrayRef[RegexpRef]';
43             coerce $type, from 'ArrayRef[Str]', via { [map { qr/$_/ } @$_] };
44             has except => (
45             is => 'ro',
46             isa => $type,
47             coerce => 1,
48             default => sub { [] },
49             );
50 13     13 0 3985 sub mvp_multivalue_args { qw(except) }
51             }
52              
53             sub _dont_exclude_file {
54 102     102   184 my ($self, $file) = @_;
55 102         151 for my $exception (@{ $self->except }) {
  102         3272  
56 4 100       10 return 1 if $file->name =~ $exception;
57             }
58 101         258 return;
59             }
60              
61             sub exclude_file {
62 102     102 0 211 my ($self, $file) = @_;
63              
64 102 100       248 return 0 if $self->_dont_exclude_file($file);
65 101 100       388 return 1 if index($file->name, $self->zilla->name . '-') == 0;
66 98 50       298 return 1 if $file->name =~ /\A\./;
67 98 100       225 return 1 if $file->name =~ /\A(?:Build|Makefile)\z/;
68 96 50       240 return 1 if $file->name eq 'Makefile.old';
69 96 50       247 return 1 if $file->name =~ /\Ablib/;
70 96 50       226 return 1 if $file->name =~ /\.(?:o|bs)$/;
71 96 100       245 return 1 if $file->name =~ /\A_Inline/;
72 95 50       239 return 1 if $file->name eq 'MYMETA.yml';
73 95 50       229 return 1 if $file->name eq 'MYMETA.json';
74 95 50       247 return 1 if $file->name eq 'pm_to_blib';
75 95 50       217 return 1 if substr($file->name, 0, 6) eq '_eumm/';
76             # Avoid bundling fatlib/ dir created by App::FatPacker
77             # https://github.com/andk/pause/pull/65
78 95 50       256 return 1 if substr($file->name, 0, 7) eq 'fatlib/';
79 95 50       269 return 1 if substr($file->name, 0, 4) eq 'tmp/';
80              
81 95 50       240 if (my $file = $file->name =~ s/\.c$//r) {
82 95         144 for my $other (@{ $self->zilla->files }) {
  95         2906  
83 906 50       2264 return 1 if $other->name eq "${file}.xs";
84             }
85             }
86              
87 95         353 return;
88             }
89              
90             sub prune_files {
91 12     12 0 41 my ($self) = @_;
92              
93             # Copy list (break reference) so we can mutate.
94 12         51 for my $file ((), @{ $self->zilla->files }) {
  12         529  
95 102 100       315 next unless $self->exclude_file($file);
96              
97 6         19 $self->log_debug([ 'pruning %s', $file->name ]);
98              
99 6         313 $self->zilla->prune_file($file);
100             }
101              
102 12         136 return;
103             }
104              
105             __PACKAGE__->meta->make_immutable;
106             1;
107              
108             __END__
109              
110             =pod
111              
112             =encoding UTF-8
113              
114             =head1 NAME
115              
116             Dist::Zilla::Plugin::PruneCruft - prune stuff that you probably don't mean to include
117              
118             =head1 VERSION
119              
120             version 6.037
121              
122             =head1 SYNOPSIS
123              
124             This plugin tries to compensate for the stupid crap that turns up in your
125             working copy, removing it before it gets into your dist and screws everything
126             up.
127              
128             In your F<dist.ini>:
129              
130             [PruneCruft]
131              
132             If you would like to exclude certain exclusions, use the C<except> option (it
133             can be specified multiple times):
134              
135             [PruneCruft]
136             except = \.gitignore
137             except = t/.*/\.keep$
138              
139             This plugin is included in the L<@Basic|Dist::Zilla::PluginBundle::Basic>
140             bundle.
141              
142             =head1 PERL VERSION
143              
144             This module should work on any version of perl still receiving updates from
145             the Perl 5 Porters. This means it should work on any version of perl
146             released in the last two to three years. (That is, if the most recently
147             released version is v5.40, then this module should work on both v5.40 and
148             v5.38.)
149              
150             Although it may work on older versions of perl, no guarantee is made that the
151             minimum required version will not be increased. The version may be increased
152             for any reason, and there is no promise that patches will be accepted to
153             lower the minimum required perl.
154              
155             =head1 SEE ALSO
156              
157             Dist::Zilla plugins:
158             L<@Basic|Dist::Zilla::PluginBundle::Basic>,
159             L<PruneFiles|Dist::Zilla::Plugin::PruneFiles>,
160             L<ManifestSkip|Dist::Zilla::Plugin::ManifestSkip>.
161              
162             =head1 AUTHOR
163              
164             Ricardo SIGNES 😏 <cpan@semiotic.systems>
165              
166             =head1 COPYRIGHT AND LICENSE
167              
168             This software is copyright (c) 2026 by Ricardo SIGNES.
169              
170             This is free software; you can redistribute it and/or modify it under
171             the same terms as the Perl 5 programming language system itself.
172              
173             =cut