]> Dogcows Code - chaz/p5-Dist-Zilla-PluginBundle-Author-CCM/blobdiff - lib/Dist/Zilla/PluginBundle/Author/CCM.pm
automatically figure out perl_versions for Travis
[chaz/p5-Dist-Zilla-PluginBundle-Author-CCM] / lib / Dist / Zilla / PluginBundle / Author / CCM.pm
index a64c1a590303e9a91ce9b9233c496ebe9a7a4726..177b79b26989386930f31d419fedf0a46c13e8af 100644 (file)
@@ -13,7 +13,6 @@ You probably don't want to use this.
 
     ; VERSION
     [Git::NextVersion]
-    [NextRelease]
     [ReversionOnRelease]
     prompt              = 1
 
@@ -41,6 +40,8 @@ You probably don't want to use this.
     [PodSyntaxTests]
     [Test::Pod::No404s]
     [Test::Compile]
+    [Test::MinimumVersion]
+    max_target_perl     = 5.10.1
     [Test::EOL]
     [Test::NoTabs]
     [Test::Perl::Critic]
@@ -83,12 +84,14 @@ You probably don't want to use this.
     location            = build
     type                = text
     [TravisYML]
+    build_branch        = /^(dist|build\/.*)$/
     [Manifest]
     [ManifestSkip]
 
     [MakeMaker]                 ; override with the "installer" attribute
 
     ; RELEASE
+    [NextRelease]
     [CheckChangesHasContent]
     [Git::Check]
     [RunExtraTests]
@@ -115,6 +118,7 @@ You probably don't want to use this.
 
 =cut
 
+use 5.014;
 use warnings;
 use strict;
 
@@ -122,8 +126,25 @@ our $VERSION = '999.999'; # VERSION
 
 use Dist::Zilla::Util;
 use Moose;
+use Perl::Version;
 use namespace::autoclean;
 
+=attr max_target_perl
+
+Specify the minimum perl version. Defaults to C<5.10.1>.
+
+=cut
+
+has max_target_perl => (
+    is      => 'ro',
+    isa     => 'Str',
+    lazy    => 1,
+    default => sub {
+        my $self = shift;
+        $self->payload->{'Test::MinimumVersion.max_target_perl'} // $self->payload->{max_target_perl} // '5.10.1';
+    },
+);
+
 =attr authority
 
 Specify the release authority. Defaults to C<cpan:CCM>.
@@ -154,7 +175,7 @@ has installer => (
     is      => 'ro',
     isa     => 'Str',
     lazy    => 1,
-    default => sub { shift->payload->{installer} || 'MakeMaker' },
+    default => sub { shift->payload->{installer} // 'MakeMaker' },
 );
 
 =attr airplane
@@ -192,24 +213,46 @@ Required by L<Dist::Zilla::Role::PluginBundle::Easy>.
 sub configure {
     my $self = shift;
 
+    my @copy_from_build     = qw(LICENSE);
+    my @network_plugins     = qw(Git::Push Test::Pod::No404s UploadToCPAN);
+    my @gather_exclude      = (@copy_from_build, qw(README.md));
+    my @gather_prune        = qw(dist.ini);
+    my @no_index            = qw(eg share shares t xt);
+    my @allow_dirty         = (@copy_from_build, qw(.travis.yml Changes LICENSE README.md));
+    my @git_remotes         = qw(github origin);
+    my @check_files         = qw(:InstallModules :ExecFiles :TestFiles :ExtraTestFiles);
+    my $perl_version_target = $self->max_target_perl;
+    my ($perl_version, $perl_version_build) = $self->_travis_perl_versions($perl_version_target);
+
     if ($self->no_upload) {
-        print '[@Author::CCM] WARNING! WARNING! WARNING! *** You are in no_upload mode!! ***', "\n";
+        say '[@Author::CCM] WARNING! WARNING! WARNING! *** You are in no_upload mode!! ***';
     }
 
-    my @copy_from_build = qw(LICENSE);
-    my @network_plugins = qw(Git::Push Test::Pod::No404s UploadToCPAN);
-    my @gather_exclude  = (@copy_from_build, qw(README.md));
-    my @gather_prune    = qw(dist.ini);
-    my @no_index        = qw(eg share shares t xt);
-    my @allow_dirty     = (@copy_from_build, qw(.travis.yml Changes LICENSE README.md));
-    my @git_remotes     = qw(github origin);
-    my @check_files     = qw(:InstallModules :ExecFiles :TestFiles :ExtraTestFiles);
+    if (!$self->payload->{'TravisYML.support_builddir'}) {
+        # swap perl_version and perl_version_build because DZP::TravisYML got it backwards!
+        # https://github.com/SineSwiper/Dist-Zilla-TravisCI/pull/40
+
+        my $tmp = $self->payload->{'TravisYML.perl_version_build'};
+        if (defined $self->payload->{'TravisYML.perl_version'}) {
+            $self->payload->{'TravisYML.perl_version_build'} = $self->payload->{'TravisYML.perl_version'}
+        }
+        else {
+            delete $self->payload->{'TravisYML.perl_version_build'};
+        }
+        if (defined $tmp) {
+            $self->payload->{'TravisYML.perl_version'} = $tmp;
+        }
+        else {
+            delete $self->payload->{'TravisYML.perl_version'};
+        }
+
+        ($perl_version, $perl_version_build) = ($perl_version_build, $perl_version);
+    }
 
     my @plugins = (
 
         # VERSION
         ['Git::NextVersion'],
-        ['NextRelease'],
         ['ReversionOnRelease' => {prompt => 1}],
 
         # GATHER
@@ -232,6 +275,7 @@ sub configure {
         ['PodSyntaxTests'],
         ['Test::Pod::No404s'],
         ['Test::Compile'],
+        ['Test::MinimumVersion' => {max_target_perl => $perl_version_target}],
         ['Test::EOL' => {finder => [@check_files]}],
         ['Test::NoTabs' => {finder => [@check_files]}],
         ['Test::Perl::Critic'],
@@ -255,15 +299,16 @@ sub configure {
 
         # GENERATE FILES
         ['License'],
-        ['ReadmeAnyFromPod' => 'repo readme' => {filename => 'README.md', location => 'root', type => 'markdown', phase => 'release'}],
-        ['ReadmeAnyFromPod' => 'dist readme' => {filename => 'README', location => 'build', type => 'text'}],
-        ['TravisYML'],
+        ['ReadmeAnyFromPod' => 'RepoReadme' => {filename => 'README.md', location => 'root', type => 'markdown', phase => 'release'}],
+        ['ReadmeAnyFromPod' => 'DistReadme' => {filename => 'README', location => 'build', type => 'text'}],
+        ['TravisYML' => {build_branch => '/^(dist|build\/.*)$/', perl_version => $perl_version, perl_version_build => $perl_version_build}],
         ['Manifest'],
         ['ManifestSkip'],
 
         $self->installer,     # e.g. MakeMaker
 
         # RELEASE
+        ['NextRelease'],
         ['CheckChangesHasContent'],
         ['Git::Check' => {allow_dirty => [@allow_dirty], untracked_files => 'ignore'}],
         ['RunExtraTests'],
@@ -289,6 +334,29 @@ sub configure {
     $self->add_plugins(@plugins);
 }
 
+sub _travis_perl_versions {
+    my $self = shift;
+
+    my $perl_version_target = Perl::Version->new(shift or die 'Missing target version');
+    my $min_version         = Perl::Version->new('5.14');
+    my $min_version_build   = Perl::Version->new($perl_version_target);
+    $min_version_build->subversion(0);
+
+    my @versions;
+    my @versions_build;
+
+    for my $v (qw{5.26 5.24 5.22 5.20 5.18 5.16 5.14 5.12 5.10 5.8}) {
+        my $version = Perl::Version->new($v);
+        push @versions,       "$version" if $version >= $min_version_build && $version >= $min_version;
+        push @versions_build, "$version" if $version >= $min_version_build;
+    }
+
+    my $perl_version       = join(' ', @versions);
+    my $perl_version_build = join(' ', @versions_build);
+
+    return ($perl_version, $perl_version_build);
+}
+
 with 'Dist::Zilla::Role::PluginBundle::Easy';
 with 'Dist::Zilla::Role::PluginBundle::PluginRemover';
 with 'Dist::Zilla::Role::PluginBundle::Config::Slicer';
This page took 0.021988 seconds and 4 git commands to generate.