Skip to content

Commit

Permalink
add a test for 3-part checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Oct 30, 2011
1 parent 2caeb0d commit 1bf9902
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Changes
@@ -1,6 +1,20 @@
Revision history for {{$dist->name}}

{{$NEXT}}
[Dependencies]
- new: runtime requires Dist::Zilla::Plugin::MinimumPerl
- new: runtime requires perl 5.10.0
- new: runtime requires version

[Packages]
- new: Dist::Zilla::Plugin::Author::KENTNL::MinimumPerl, contains an
additional 3-part version check that forces Perl 5.10.0

[Packaging]


[Tests]
- new: xt/release/minimum-version.t

1.0.22 2011-10-07T21:14:49Z
[Dependencies]
Expand Down
6 changes: 6 additions & 0 deletions dist.ini
Expand Up @@ -20,6 +20,12 @@ git_versions = 1
twitter_hash_tags = #perl #cpan
;auto_prereqs_skip = File::Find

[Author::KENTNL::MinimumPerl]
; Will get upgraded to 5.010 due to 3part version
perl = 5.008000
[Test::MinimumVersion]


[ModuleShareDirs]
Dist::Zilla::MintingProfile::Author::KENTNL = share/profiles

Expand Down
2 changes: 1 addition & 1 deletion lib/Dist/Zilla/Plugin/Author/KENTNL/DistINI.pm
Expand Up @@ -94,7 +94,7 @@ sub gather_files {
q(; [Bootstrap::lib]), #
$empty, #
'[@Author::KENTNL]', #
':version = 1.0.8', #
':version = 1.1.0', #
'git_versions = 1', #
'; version_major = 0', #
'; version_minor = 1', #
Expand Down
111 changes: 111 additions & 0 deletions lib/Dist/Zilla/Plugin/Author/KENTNL/MinimumPerl.pm
@@ -0,0 +1,111 @@
use 5.010000;
use strict;
use warnings;

package Dist::Zilla::Plugin::Author::KENTNL::MinimumPerl;

# FILENAME: MinimumPerl.pm
# CREATED: 31/10/11 05:25:54 by Kent Fredric (kentnl) <kentfredric@gmail.com>
# ABSTRACT: The MinimumPerl Plugin with a few hacks

use Moose;
extends 'Dist::Zilla::Plugin::MinimumPerl';
use namespace::autoclean;

has 'detected_perl' => (
is => 'rw',
isa => 'Object',
lazy_build => 1,
);

sub _3part_check {
my ( $self, $file, $pmv, $minver ) = @_;
my $perl_required = version->parse('5.10.0');
return $minver if $minver >= $perl_required;
my $document = $pmv->Document;
my $version_declaration = sub {
$_[1]->isa('PPI::Token::Symbol') and $_[1]->content =~ /::VERSION\z/msx;
};
my $version_match = sub {
$_[1]->class eq 'PPI::Token::Quote::Single' and $_[1]->parent->find_any($version_declaration);
};
my (@versions) = @{ $document->find($version_match) || [] };
for my $versiondecl (@versions) {
next
if $minver >= $perl_required;
## no critic (ProhibitStringyEval)
my $v = eval $versiondecl;
if ( $v =~ /\A\d+[.]\d+[.]/msx ) {
$minver = $perl_required;
$self->log_debug( [ 'Upgraded to 5.10 due to %s having x.y.z', $file->name ] );
}
}
return $minver;
}

sub _build_detected_perl {
my ($self) = @_;
my $minver;

foreach my $file ( @{ $self->found_files } ) {

# TODO should we scan the content for the perl shebang?
# Only check .t and .pm/pl files, thanks RT#67355 and DOHERTY
next unless $file->name =~ /[.](?:t|p[ml])\z/imsx;

# TODO skip "bad" files and not die, just warn?
my $pmv = Perl::MinimumVersion->new( \$file->content );
if ( not defined $pmv ) {
$self->log_fatal( [ 'Unable to parse \'%s\'', $file->name ] );
}
my $ver = $pmv->minimum_version;
if ( not defined $ver ) {
$self->log_fatal( [ 'Unable to extract MinimumPerl from \'%s\'', $file->name ] );
}
if ( ( not defined $minver ) or $ver > $minver ) {
$minver = $ver;
}
$minver = $self->_3part_check( $file, $pmv, $minver );
}

# Write out the minimum perl found
if ( defined $minver ) {
return $minver;
}
return $self->log_fatal('Found no perl files, check your dist?');
}

=method C<minperl>
Returns the maximum of either the version requested for Perl, or the version detected for Perl.
=cut

sub minperl {
require version;
my $self = shift;
if ( not $self->_has_perl ) {
return $self->detected_perl;
}
my ($x) = version->parse( $self->perl );
my ($y) = $self->detected_perl;
if ( $x > $y ) {
return $x;
}
return $y;
}

override register_prereqs => sub {
my ( $self, @args ) = @_;

my $minperl = $self->minperl;

$self->log_debug( [ 'Minimum Perl is v%s', $minperl ] );
$self->zilla->register_prereqs( { phase => 'runtime' }, perl => $minperl->stringify, );

};

no Moose;
__PACKAGE__->meta->make_immutable;
1;

11 changes: 10 additions & 1 deletion perlcritic.rc
Expand Up @@ -10,5 +10,14 @@ allow_includes = 1
[CodeLayout::ProhibitTrailingWhitespace]

[Documentation::PodSpelling]
stop_words = metadata KiokuDB KENTNL KENTNL's CPAN blogged CPANized PluginBundles CPANID's CPANID dists DPCHRIST everyones irc cpan Doherty's Gorwits namespace Gorwit's blog PluginBundle Lesperance's Ghedini's Stauner's Ilmari Vacklin's Yanick Champoux's Znamensky's
stop_words = metadata KiokuDB KENTNL KENTNL's CPAN blogged CPANized PluginBundles CPANID's CPANID dists DPCHRIST everyones irc cpan Doherty's Gorwits namespace Gorwit's blog PluginBundle Lesperance's Ghedini's Stauner's Ilmari Vacklin's Yanick Champoux's Znamensky's MinimumPerl Plugin minperl

[Subroutines::ProhibitUnusedPrivateSubroutines]
private_name_regex = _(?!build_)\w

[TestingAndDebugging::RequireUseStrict]
equivalent_modules = Moose

[TestingAndDebugging::RequireUseWarnings]
equivalent_modules = Moose

1 change: 1 addition & 0 deletions share/profiles/default/skel/weaver.ini
@@ -1,4 +1,5 @@
[@CorePrep]
[-Encoding]

[Name]
[Version]
Expand Down
1 change: 1 addition & 0 deletions weaver.ini
@@ -1,4 +1,5 @@
[@CorePrep]
[-Encoding]

[Name]
[Version]
Expand Down

0 comments on commit 1bf9902

Please sign in to comment.