File Coverage

blib/lib/Dist/Zilla/Plugin/EnsureLatestPerl.pm
Criterion Covered Total %
statement 36 36 100.0
branch 8 10 80.0
condition 2 3 66.6
subroutine 9 9 100.0
pod 0 1 0.0
total 55 59 93.2


line stmt bran cond sub pod time code
1 5     5   16286232 use strict;
  5         10  
  5         174  
2 5     5   25 use warnings;
  5         11  
  5         342  
3             # vim: set ts=8 sts=2 sw=2 tw=115 et :
4             # ABSTRACT: Ensure the author is releasing using the latest Perl
5             # KEYWORDS: plugin release develop author perl version latest
6              
7             our $VERSION = '0.009';
8              
9             use Moose;
10 5     5   34 with 'Dist::Zilla::Role::BeforeRelease';
  5         17  
  5         40  
11              
12             use Module::CoreList;
13 5     5   29672 use List::Util 'first';
  5         11  
  5         47  
14 5     5   148 use namespace::autoclean;
  5         10  
  5         364  
15 5     5   29  
  5         9  
  5         58  
16             around dump_config => sub
17             {
18             my ($orig, $self) = @_;
19             my $config = $self->$orig;
20              
21             $config->{+__PACKAGE__} = {
22             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
23             'Module::CoreList' => Module::CoreList->VERSION,
24             };
25              
26             return $config;
27             };
28              
29             {
30             my $self = shift;
31              
32 5     5 0 775311 $self->log('DZIL_ANY_PERL set: skipping perl version check'), return
33             if $ENV{DZIL_ANY_PERL};
34              
35 5 100       142 # we cannot know in advance the release schedule of Module::CoreList in order to check the latest perl
36             # releases, but we can make a guess -- development releases are made once a month. We'll assume that any
37             # Module::CoreList older than 3 months old is out of date, and lean on modules like [PromptIfStale] to confirm
38             # against the PAUSE index.
39              
40             my $delta = 3 * 30 * 24 * 60 * 60;
41             my @gmtime = gmtime(time() - $delta);
42 3         23 my $expected_version = sprintf('5.%04d%02d%02d', $gmtime[5] + 1900, $gmtime[4] + 1, $gmtime[3]);
43 3         62  
44 3         68 my $error_suffix = 'disable check with DZIL_ANY_PERL=1';
45              
46 3         25 if (not eval { Module::CoreList->VERSION($expected_version); 1 })
47             {
48 3 100       21 $self->log_fatal([ 'Module::CoreList is not new enough to check if this is the latest Perl (expected at least %s) -- %s',
  3         313  
  2         26  
49             $expected_version, $error_suffix ]);
50 1         23 }
51              
52             # sort perl releases in reverse order
53             my @all_perl_releases = reverse sort keys %Module::CoreList::released;
54              
55 2         907 my $latest_stable_perl = first { /^5\.(\d{3})/; defined $1 and $1 % 2 == 0 } @all_perl_releases;
56             my $latest_dev_perl = first { /^5\.(\d{3})/; defined $1 and $1 % 2 == 1 } @all_perl_releases;
57 2 50   16   124  
  16         255  
  16         99  
58 2 50   2   40 $self->log_fatal([ 'current perl (%s) is neither the latest stable nor development perl (%s, %s) -- %s',
  2         68  
  2         45  
59             $], $latest_stable_perl, $latest_dev_perl, $error_suffix ])
60 2 100 66     98 if "$]" ne $latest_stable_perl and "$]" ne $latest_dev_perl;
61             }
62              
63             __PACKAGE__->meta->make_immutable;
64              
65              
66             =pod
67              
68             =encoding UTF-8
69              
70             =head1 NAME
71              
72             Dist::Zilla::Plugin::EnsureLatestPerl - Ensure the author is releasing using the latest Perl
73              
74             =head1 VERSION
75              
76             version 0.009
77              
78             =head1 SYNOPSIS
79              
80             In your F<dist.ini>:
81              
82             [EnsureLatestPerl]
83              
84             =head1 DESCRIPTION
85              
86             =for Pod::Coverage before_release
87              
88             This is a L<Dist::Zilla> plugin that aborts the C<dzil release> process unless the latest perl is being used for
89             the release. "Latest" here is calculated as the latest point release in the latest stable or development Perl
90             lines -- for example, 5.24.1 (latest in the 5.24 series) or 5.25.12 (latest in the 5.25 series).
91              
92             =head1 CONFIGURATION OPTIONS
93              
94             =head2 C<DZIL_ANY_PERL>
95              
96             When this environment variable is true, the check is skipped. Therefore, it is safe to keep this plugin enabled in
97             your plugin bundle, and you can disable it temporarily as needed for a particular release without changing any
98             local files.
99              
100             =head1 SEE ALSO
101              
102             =over 4
103              
104             =item *
105              
106             L<Module::CoreList>
107              
108             =back
109              
110             =head1 SUPPORT
111              
112             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-EnsureLatestPerl>
113             (or L<bug-Dist-Zilla-Plugin-EnsureLatestPerl@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-EnsureLatestPerl@rt.cpan.org>).
114              
115             There is also a mailing list available for users of this distribution, at
116             L<http://dzil.org/#mailing-list>.
117              
118             There is also an irc channel available for users of this distribution, at
119             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
120              
121             I am also usually active on irc, as 'ether' at C<irc.perl.org> and C<irc.libera.chat>.
122              
123             =head1 AUTHOR
124              
125             Karen Etheridge <ether@cpan.org>
126              
127             =head1 COPYRIGHT AND LICENCE
128              
129             This software is copyright (c) 2017 by Karen Etheridge.
130              
131             This is free software; you can redistribute it and/or modify it under
132             the same terms as the Perl 5 programming language system itself.
133              
134             =cut