blib/lib/Dist/Zilla/Plugin/PruneCruft.pm

filter: Statementstmt 100% 57 / 57 Branchbran 70.0% 28 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 86.3% 95 / 110 CC 24 SCAR 27.1
CC
24
Cov
88%
exclude_file
23.5
_dont_exclude_file
3.0
prune_files
3.0
CRAP 15.0
« blib/lib/Dist/Zilla/Role/PrereqScanner.pm ↑ Summary blib/lib/Dist/Zilla/App/Command/release.pm »
1 package Dist::Zilla::Plugin::PruneCruft 6.040;
2 # ABSTRACT: prune stuff that you probably don't mean to include
3  
4 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 with 'Dist::Zilla::Role::FilePruner';
7  
8 10 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 10 my $type = subtype as 'ArrayRef[RegexpRef]';
43 1 ▶ coerce $type, from 'ArrayRef[Str]', via { [map { qr/$_/ } @$_] };
Subroutine __ANON__: called CC=1 SCAR=0.0
44 has except => (
45 is => 'ro',
46 isa => $type,
47 coerce => 1,
48 14 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 10 );
50 15 ▶ sub mvp_multivalue_args { qw(except) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
51 }
52  
53 10 ▶sub _dont_exclude_file {
Subroutine _dont_exclude_file: called CC=3 SCAR=11.0
54 116 my ($self, $file) = @_;
55 116 for my $exception (@{ $self->except }) {
56 4 ▶ return 1 if $file->name =~ $exception;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /$exception/u 1 3 4
57 }
58 115 return;
59 }
60  
61 116 ▶sub exclude_file {
Subroutine exclude_file: called CC=20 SCAR=31.6
Pod undocumented
62 116 my ($self, $file) = @_;
63  
64 116 ▶ return 0 if $self->_dont_exclude_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_dont_exclude_file($file) 1 115 116
65 115 ▶ return 1 if index($file->name, $self->zilla->name . '-') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($file->name, $self->zilla->name . '-') == 0 3 112 115
66 112 ▶ return 1 if $file->name =~ /\A\./;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\A\./u 0 112 112
67 112 ▶ return 1 if $file->name =~ /\A(?:Build|Makefile)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\A(?:Build|Makefile)\z/u 4 108 112
68 108 ▶ return 1 if $file->name eq 'Makefile.old';
Branch: 1 branch
BranchTrueFalseTotal
if $file->name eq "Makefile.old" 0 108 108
69 108 ▶ return 1 if $file->name =~ /\Ablib/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\Ablib/u 0 108 108
70 108 ▶ return 1 if $file->name =~ /\.(?:o|bs)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\.(?:o|bs)$/u 0 108 108
71 108 ▶ return 1 if $file->name =~ /\A_Inline/;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\A_Inline/u 1 107 108
72 107 ▶ return 1 if $file->name eq 'MYMETA.yml';
Branch: 1 branch
BranchTrueFalseTotal
if $file->name eq "MYMETA.yml" 0 107 107
73 107 ▶ return 1 if $file->name eq 'MYMETA.json';
Branch: 1 branch
BranchTrueFalseTotal
if $file->name eq "MYMETA.json" 0 107 107
74 107 ▶ return 1 if substr($file->name, -12) eq 'perltidy.ERR';
Branch: 1 branch
BranchTrueFalseTotal
if substr($file->name, -12) eq "perltidy.ERR" 3 104 107
75 104 ▶ return 1 if $file->name eq 'pm_to_blib';
Branch: 1 branch
BranchTrueFalseTotal
if $file->name eq "pm_to_blib" 0 104 104
76 104 ▶ return 1 if substr($file->name, -1) eq '~';
Branch: 1 branch
BranchTrueFalseTotal
if substr($file->name, -1) eq "~" 3 101 104
77 101 ▶ return 1 if substr($file->name, 0, 6) eq '_eumm/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($file->name, 0, 6) eq "_eumm/" 0 101 101
78 # Avoid bundling fatlib/ dir created by App::FatPacker
79 # https://github.com/andk/pause/pull/65
80 101 ▶ return 1 if substr($file->name, 0, 7) eq 'fatlib/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($file->name, 0, 7) eq "fatlib/" 0 101 101
81 101 ▶ return 1 if substr($file->name, 0, 4) eq 'tmp/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($file->name, 0, 4) eq "tmp/" 0 101 101
82  
83 101 ▶ if (my $file = $file->name =~ s/\.c$//r) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $file->name =~ s/\.c$//ru) 101 0 101
84 101 for my $other (@{ $self->zilla->files }) {
85 931 ▶ return 1 if $other->name eq "${file}.xs";
Branch: 1 branch
BranchTrueFalseTotal
if $other->name eq "$file.xs" 0 931 931
86 }
87 }
88  
89 101 return;
90 }
91  
92 14 ▶sub prune_files {
Subroutine prune_files: called CC=3 SCAR=11.0
Pod undocumented
93 14 my ($self) = @_;
94  
95 # Copy list (break reference) so we can mutate.
96 14 for my $file ((), @{ $self->zilla->files }) {
97 116 ▶ next unless $self->exclude_file($file);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exclude_file($file) 102 14 116
98  
99 14 $self->log_debug([ 'pruning %s', $file->name ]);
100  
101 14 $self->zilla->prune_file($file);
102 }
103  
104 14 return;
105 }
106  
107 10 __PACKAGE__->meta->make_immutable;
108 10 1;
109  
110 __END__
« blib/lib/Dist/Zilla/Role/PrereqScanner.pm ↑ Summary blib/lib/Dist/Zilla/App/Command/release.pm »