| 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
| |||||||||||
| 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
| |||||||||||
| 65 | 115 | ▶ | return 1 if index($file->name, $self->zilla->name . '-') == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 112 | ▶ | return 1 if $file->name =~ /\A\./; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 112 | ▶ | return 1 if $file->name =~ /\A(?:Build|Makefile)\z/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 108 | ▶ | return 1 if $file->name eq 'Makefile.old'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 108 | ▶ | return 1 if $file->name =~ /\Ablib/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 108 | ▶ | return 1 if $file->name =~ /\.(?:o|bs)$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 108 | ▶ | return 1 if $file->name =~ /\A_Inline/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 107 | ▶ | return 1 if $file->name eq 'MYMETA.yml'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 107 | ▶ | return 1 if $file->name eq 'MYMETA.json'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 107 | ▶ | return 1 if substr($file->name, -12) eq 'perltidy.ERR'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 104 | ▶ | return 1 if $file->name eq 'pm_to_blib'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 104 | ▶ | return 1 if substr($file->name, -1) eq '~'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 101 | ▶ | return 1 if substr($file->name, 0, 6) eq '_eumm/'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 81 | 101 | ▶ | return 1 if substr($file->name, 0, 4) eq 'tmp/'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | |||||||||||
| 83 | 101 | ▶ | if (my $file = $file->name =~ s/\.c$//r) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 101 | for my $other (@{ $self->zilla->files }) { | |||||||||
| 85 | 931 | ▶ | return 1 if $other->name eq "${file}.xs"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||