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