File Coverage

blib/lib/Dist/Zilla/Plugin/ManifestSkip.pm
Criterion Covered Total %
statement 34 34 100.0
branch 6 6 100.0
condition 2 3 66.6
subroutine 4 4 100.0
pod 0 1 0.0
total 46 48 95.8


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::ManifestSkip 6.030;
2             # ABSTRACT: decline to build files that appear in a MANIFEST.SKIP-like file
3              
4 10     10   8042 use Moose;
  10         27  
  10         87  
5             with 'Dist::Zilla::Role::FilePruner';
6              
7 10     10   74330 use Dist::Zilla::Pragmas;
  10         28  
  10         103  
8              
9 10     10   119 use namespace::autoclean;
  10         294  
  10         129  
10              
11             #pod =head1 DESCRIPTION
12             #pod
13             #pod This plugin reads a MANIFEST.SKIP-like file, as used by L<ExtUtils::MakeMaker>
14             #pod and L<ExtUtils::Manifest>, and prunes any files that it declares should be
15             #pod skipped.
16             #pod
17             #pod This plugin is included in the L<@Basic|Dist::Zilla::PluginBundle::Basic>
18             #pod bundle.
19             #pod
20             #pod =attr skipfile
21             #pod
22             #pod This is the name of the file to read for MANIFEST.SKIP-like content. It
23             #pod defaults, unsurprisingly, to F<MANIFEST.SKIP>.
24             #pod
25             #pod =head1 SEE ALSO
26             #pod
27             #pod Dist::Zilla core plugins:
28             #pod L<@Basic|Dist::Zilla::PluginBundle::Basic>,
29             #pod L<PruneCruft|Dist::Zilla::Plugin::PruneCruft>,
30             #pod L<PruneFiles|Dist::Zilla::Plugin::PruneFiles>.
31             #pod
32             #pod Other modules: L<ExtUtils::Manifest>.
33             #pod
34             #pod =cut
35              
36             has skipfile => (is => 'ro', required => 1, default => 'MANIFEST.SKIP');
37              
38             sub prune_files {
39 11     11 0 43 my ($self) = @_;
40 11         371 my $files = $self->zilla->files;
41              
42 11         389 my $skipfile_name = $self->skipfile;
43 11         39 my ($skipfile) = grep { $_->name eq $skipfile_name } @$files;
  101         258  
44 11 100       78 unless (defined $skipfile) {
45 8         70 $self->log_debug([ 'file %s not found', $skipfile_name ]);
46 8         591 return;
47             }
48              
49 3         16 my $content = $skipfile->content;
50              
51             # If the content has been generated in memory or changed from disk,
52             # create a temp file with the content.
53             # (Unfortunately maniskip can't read from a string ref)
54 3         6 my $fh;
55 3 100 66     81 if (! -f $skipfile_name || (-s $skipfile_name) != length($content)) {
56 1         13 $fh = File::Temp->new;
57 1         672 $skipfile_name = $fh->filename;
58 1         14 $self->log_debug([ 'create temporary %s', $skipfile_name ]);
59 1         35 print $fh $content;
60 1         50 close $fh;
61             }
62              
63 3         651 require ExtUtils::Manifest;
64 3         6448 ExtUtils::Manifest->VERSION('1.54');
65              
66 3         22 my $skip = ExtUtils::Manifest::maniskip($skipfile_name);
67              
68             # Copy list (break reference) so we can mutate.
69 3         866 for my $file ((), @{ $files }) {
  3         11  
70 19 100       158 next unless $skip->($file->name);
71              
72 9         174 $self->log_debug([ 'pruning %s', $file->name ]);
73              
74 9         470 $self->zilla->prune_file($file);
75             }
76              
77 3         84 return;
78             }
79              
80             __PACKAGE__->meta->make_immutable;
81             1;
82              
83             __END__
84              
85             =pod
86              
87             =encoding UTF-8
88              
89             =head1 NAME
90              
91             Dist::Zilla::Plugin::ManifestSkip - decline to build files that appear in a MANIFEST.SKIP-like file
92              
93             =head1 VERSION
94              
95             version 6.030
96              
97             =head1 DESCRIPTION
98              
99             This plugin reads a MANIFEST.SKIP-like file, as used by L<ExtUtils::MakeMaker>
100             and L<ExtUtils::Manifest>, and prunes any files that it declares should be
101             skipped.
102              
103             This plugin is included in the L<@Basic|Dist::Zilla::PluginBundle::Basic>
104             bundle.
105              
106             =head1 PERL VERSION
107              
108             This module should work on any version of perl still receiving updates from
109             the Perl 5 Porters. This means it should work on any version of perl released
110             in the last two to three years. (That is, if the most recently released
111             version is v5.40, then this module should work on both v5.40 and v5.38.)
112              
113             Although it may work on older versions of perl, no guarantee is made that the
114             minimum required version will not be increased. The version may be increased
115             for any reason, and there is no promise that patches will be accepted to lower
116             the minimum required perl.
117              
118             =head1 ATTRIBUTES
119              
120             =head2 skipfile
121              
122             This is the name of the file to read for MANIFEST.SKIP-like content. It
123             defaults, unsurprisingly, to F<MANIFEST.SKIP>.
124              
125             =head1 SEE ALSO
126              
127             Dist::Zilla core plugins:
128             L<@Basic|Dist::Zilla::PluginBundle::Basic>,
129             L<PruneCruft|Dist::Zilla::Plugin::PruneCruft>,
130             L<PruneFiles|Dist::Zilla::Plugin::PruneFiles>.
131              
132             Other modules: L<ExtUtils::Manifest>.
133              
134             =head1 AUTHOR
135              
136             Ricardo SIGNES 😏 <cpan@semiotic.systems>
137              
138             =head1 COPYRIGHT AND LICENSE
139              
140             This software is copyright (c) 2023 by Ricardo SIGNES.
141              
142             This is free software; you can redistribute it and/or modify it under
143             the same terms as the Perl 5 programming language system itself.
144              
145             =cut