Sometimes, it is helpful to skip files or packages that are
manually listed. Now, you can give PkgVersion the skip_file
and skip_package options to do so - give them multiple times
to provide multiple files or packages to skip.
Resolves RT #55982: [PkgVersion]: add 'skip' configuration key
---
lib/Dist/Zilla/Plugin/PkgVersion.pm | 23 ++++++++++++++++++++++-
t/plugins/pkgversion.t | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/lib/Dist/Zilla/Plugin/PkgVersion.pm b/lib/Dist/Zilla/Plugin/PkgVersion.pm
index 5b7d748..92c3c5f 100644
--- a/lib/Dist/Zilla/Plugin/PkgVersion.pm
+++ b/lib/Dist/Zilla/Plugin/PkgVersion.pm
@@ -9,6 +9,7 @@ with(
'Dist::Zilla::Role::PPI',
);
+use List::MoreUtils qw(any);
use PPI;
use MooseX::Types::Perl qw(LaxVersionStr);
@@ -44,10 +45,24 @@ typically used when doing monkey patching or other tricky things.
=cut
+sub mvp_multivalue_args { qw(skip_file skip_package) }
+has skip_file => (
+ is => 'ro',
+ isa => 'ArrayRef[Str]',
+ default => sub {[]},
+);
+has skip_package => (
+ is => 'ro',
+ isa => 'ArrayRef[Str]',
+ default => sub {[]},
+);
+
sub munge_files {
my ($self) = @_;
- $self->munge_file($_) for @{ $self->found_files };
+ my @files = @{ $self->found_files };
+
+ $self->munge_file($_) for @files;
}
sub munge_file {
@@ -57,6 +72,7 @@ sub munge_file {
return if $file->name =~ /^corpus\//;
return if $file->name =~ /\.t$/i;
+ return if any { $_ eq $file->name } @{ $self->skip_file };
return $self->munge_perl($file) if $file->name =~ /\.(?:pm|pl)$/i;
return $self->munge_perl($file) if $file->content =~ /^#!(?:.*)perl(?:$|\s)/;
return;
@@ -85,6 +101,11 @@ sub munge_perl {
for my $stmt (@$package_stmts) {
my $package = $stmt->namespace;
+ if ( any { $_ eq $package } @{ $self->skip_package } ) {
+ $self->log([ 'skipping package %s by request', $package ]);
+ next;
+ }
+
if ($seen_pkg{ $package }++) {
$self->log([ 'skipping package re-declaration for %s', $package ]);
next;
diff --git a/t/plugins/pkgversion.t b/t/plugins/pkgversion.t
index 92b91c4..1a88fac 100644
--- a/t/plugins/pkgversion.t
+++ b/t/plugins/pkgversion.t
@@ -55,6 +55,17 @@ package # hide me from toolchain
1;
';
+my $skip_file_requested = '
+package DZT::Skip;
+
+1;
+';
+
+my $skip_package_requested = '
+package DZT::Skip::Package;
+
+1;
+';
my $script = '
#!/usr/bin/perl
@@ -78,10 +89,19 @@ my $tzil = Builder->from_config(
'source/lib/DZT/R1.pm' => $repeated_packages,
'source/lib/DZT/Monkey.pm' => $monkey_patched,
'source/lib/DZT/HideMe.pm' => $hide_me_comment,
+ 'source/lib/DZT/Skip.pm' => $skip_file_requested,
+ 'source/lib/DZT/Skip/Package.pm' => $skip_package_requested,
'source/bin/script_pkg.pl' => $script_pkg,
'source/bin/script_ver.pl' => $script_pkg . "our \$VERSION = 1.234;\n",
'source/bin/script.pl' => $script,
- 'source/dist.ini' => simple_ini('GatherDir', 'PkgVersion', 'ExecDir'),
+ 'source/dist.ini' => simple_ini(
+ 'GatherDir',
+ [PkgVersion => {
+ skip_file => ['lib/DZT/Skip.pm'],
+ skip_package => ['DZT::Skip::Package'],
+ }],
+ 'ExecDir'
+ ),
},
},
);
@@ -175,6 +195,18 @@ unlike(
"no version for DZT::TP2 when it was hidden with a comment"
);
+my $dzt_skip_file = $tzil->slurp_file('build/lib/DZT/Skip.pm');
+unlike(
+ $dzt_skip_file => qr{VERSION},
+ 'No version added for lib/DZT/Skip.pm when it was excluded by skip_file directive'
+);
+
+my $dzt_skip_package = $tzil->slurp_file('build/lib/DZT/Skip/Package.pm');
+unlike(
+ $dzt_skip_package => qr{\$DZT::Skip::Package::VERSION},
+ 'No version added for DZT::Skip::Package when it was excluded by skip_package directive'
+);
+
{
local $ENV{TRIAL} = 1;
--
1.7.9.5