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.029;
2             # ABSTRACT: prune stuff that you probably don't mean to include
3              
4 10     10   8170 use Moose;
  10         34  
  10         98  
5 10     10   74702 use Moose::Util::TypeConstraints;
  10         27  
  10         137  
6             with 'Dist::Zilla::Role::FilePruner';
7              
8 10     10   23621 use Dist::Zilla::Pragmas;
  10         27  
  10         112  
9              
10 10     10   91 use namespace::autoclean;
  10         38  
  10         169  
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 3824 sub mvp_multivalue_args { qw(except) }
51             }
52              
53             sub _dont_exclude_file {
54 102     102   178 my ($self, $file) = @_;
55 102         159 for my $exception (@{ $self->except }) {
  102         2945  
56 4 100       13 return 1 if $file->name =~ $exception;
57             }
58 101         244 return;
59             }
60              
61             sub exclude_file {
62 102     102 0 755 my ($self, $file) = @_;
63              
64 102 100       244 return 0 if $self->_dont_exclude_file($file);
65 101 100       286 return 1 if index($file->name, $self->zilla->name . '-') == 0;
66 98 50       669 return 1 if $file->name =~ /\A\./;
67 98 100       385 return 1 if $file->name =~ /\A(?:Build|Makefile)\z/;
68 96 50       276 return 1 if $file->name eq 'Makefile.old';
69 96 50       255 return 1 if $file->name =~ /\Ablib/;
70 96 50       261 return 1 if $file->name =~ /\.(?:o|bs)$/;
71 96 100       260 return 1 if $file->name =~ /\A_Inline/;
72 95 50       265 return 1 if $file->name eq 'MYMETA.yml';
73 95 50       246 return 1 if $file->name eq 'MYMETA.json';
74 95 50       232 return 1 if $file->name eq 'pm_to_blib';
75 95 50       281 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       314 return 1 if substr($file->name, 0, 7) eq 'fatlib/';
79 95 50       259 return 1 if substr($file->name, 0, 4) eq 'tmp/';
80              
81 95 50       261 if (my $file = $file->name =~ s/\.c$//r) {
82 95         154 for my $other (@{ $self->zilla->files }) {
  95         2561  
83 905 50       2210 return 1 if $other->name eq "${file}.xs";
84             }
85             }
86              
87 95         316 return;
88             }
89              
90             sub prune_files {
91 12     12 0 48 my ($self) = @_;
92              
93             # Copy list (break reference) so we can mutate.
94 12         34 for my $file ((), @{ $self->zilla->files }) {
  12         436  
95 102 100       279 next unless $self->exclude_file($file);
96              
97 6         23 $self->log_debug([ 'pruning %s', $file->name ]);
98              
99 6         313 $self->zilla->prune_file($file);
100             }
101              
102 12         109 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.029
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 released
146             in the last two to three years. (That is, if the most recently released
147             version is v5.40, then this module should work on both v5.40 and v5.38.)
148              
149             Although it may work on older versions of perl, no guarantee is made that the
150             minimum required version will not be increased. The version may be increased
151             for any reason, and there is no promise that patches will be accepted to lower
152             the minimum required perl.
153              
154             =head1 SEE ALSO
155              
156             Dist::Zilla plugins:
157             L<@Basic|Dist::Zilla::PluginBundle::Basic>,
158             L<PruneFiles|Dist::Zilla::Plugin::PruneFiles>,
159             L<ManifestSkip|Dist::Zilla::Plugin::ManifestSkip>.
160              
161             =head1 AUTHOR
162              
163             Ricardo SIGNES 😏 <cpan@semiotic.systems>
164              
165             =head1 COPYRIGHT AND LICENSE
166              
167             This software is copyright (c) 2022 by Ricardo SIGNES.
168              
169             This is free software; you can redistribute it and/or modify it under
170             the same terms as the Perl 5 programming language system itself.
171              
172             =cut