Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Dist-Zilla CPAN distribution.

Report information
The Basics
Id: 55982
Status: open
Priority: 0/
Queue: Dist-Zilla

People
Owner: Nobody in particular
Requestors: doherty [...] cs.dal.ca
marcel [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.100711
Fixed in: (no value)



Subject: [PkgVersion]: add 'skip' configuration key
It would be nice if the user could set a 'skip' configuration key to indicate which packages he doesn't want a VERSION to be added to. package 'DB' should be in there by default.
CC: Mike Doherty <doherty [...] cs.dal.ca>
Subject: [PATCH] PkgVersion: Allow skipping nameed files/packages
Date: Sat, 14 Jul 2012 01:00:21 -0300
To: bug-Dist-Zilla [...] rt.cpan.org
From: Mike Doherty <doherty [...] cs.dal.ca>
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
On Fri Mar 26 15:44:12 2010, MARCEL wrote: Show quoted text
> It would be nice if the user could set a 'skip' configuration key to > indicate which packages he > doesn't want a VERSION to be added to. package 'DB' should be in there > by default.
blargh, I created a new ticket with the patch - https://rt.cpan.org/Ticket/Display.html?id=78367
Note that you can already skip files by supplying a different FileFinder. FileFinder::Filter is often useful for this. e.g.: [PkgVersion] finder = FilesToVersion [FileFinder::Filter / FilesToVersion] finder = :InstallModules skip = Private.pm$ You might also want to look at OurPkgVersion, which puts a version only where it finds a # VERSION comment.
On Sat Jul 14 00:09:52 2012, CJM wrote: Show quoted text
> Note that you can already skip files by supplying a different > FileFinder. FileFinder::Filter is often useful for this. e.g.: > > [PkgVersion] > finder = FilesToVersion > [FileFinder::Filter / FilesToVersion] > finder = :InstallModules > skip = Private.pm$
I think it would probably be helpful if that were documented well and more prominently.