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