| 1 | 1 | ▶ | use 5.006; # our | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Dist::Zilla::Plugin::Author::KENTNL::MinimumPerl; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: The MinimumPerl Plugin with a few hacks | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '2.025021'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Moose qw( has extends override around ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Dist::Zilla::Plugin::MinimumPerl 1.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | extends 'Dist::Zilla::Plugin::MinimumPerl'; | |||||||||||||||||||||||||||
| 28 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | around dump_config => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 31 | 0 | my ( $orig, $self, @args ) = @_; | |||||||||||||||||||||||||||
| 32 | 0 | my $config = $self->$orig(@args); | |||||||||||||||||||||||||||
| 33 | 0 | my $localconf = $config->{ +__PACKAGE__ } = {}; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( $self->meta->find_attribute_by_name('detected_perl')->has_value($self) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | $localconf->{detected_perl} = $self->detected_perl; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( $self->meta->find_attribute_by_name('fiveten')->has_value($self) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | $localconf->{fiveten} = $self->fiveten; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | unless __PACKAGE__ eq ref $self; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | return $config; | |||||||||||||||||||||||||||
| 46 | 1 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | has 'detected_perl' => ( | |||||||||||||||||||||||||||
| 49 | is => 'rw', | ||||||||||||||||||||||||||||
| 50 | isa => 'Object', | ||||||||||||||||||||||||||||
| 51 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | has 'fiveten' => ( | ||||||||||||||||||||||||||||
| 55 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | default => sub { undef }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 1 | ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | override register_prereqs => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 61 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my $minperl = $self->minperl; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | $self->log_debug( [ 'Minimum Perl is v%s', $minperl ] ); | |||||||||||||||||||||||||||
| 66 | 0 | $self->zilla->register_prereqs( { phase => 'runtime' }, perl => $minperl->stringify, ); | |||||||||||||||||||||||||||
| 67 | 1 | }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _3part_check { | ||||||||||||||||||||||||||
|
Subroutine
_3part_check: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 73 | 0 | my ( $self, $file, $pmv, $minver ) = @_; | |||||||||||||||||||||||||||
| 74 | 0 | my $perl_required = version->parse('5.10.0'); | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | return $minver if $minver >= $perl_required; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | my $document = $pmv->Document; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $version_declaration = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $_[1]->isa('PPI::Token::Symbol') and $_[1]->content =~ /::VERSION\z/msx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | }; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $version_match = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | 'PPI::Token::Quote::Single' eq $_[1]->class and $_[1]->parent->find_any($version_declaration); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | }; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | my (@versions) = @{ $document->find($version_match) || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$document->find($version_match) || []
MC/DC0%0/1
$document->find($version_match) || []
$document->find($version_match)
Truth table0%0/2
A
A= $document->find($version_match)
| |||||||||||||||||||||||||||||
| 84 | 0 | for my $versiondecl (@versions) { | |||||||||||||||||||||||||||
| 85 | next | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if $minver >= $perl_required; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | ## no critic (ProhibitStringyEval) | ||||||||||||||||||||||||||||
| 88 | 0 | my $v = eval $versiondecl; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( $v =~ /\A\d+[.]\d+[.]/msx ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $minver = $perl_required; | |||||||||||||||||||||||||||
| 91 | 0 | $self->log_debug( [ 'Upgraded to %s due to %s having x.y.z', $minver, $file->name ] ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 0 | return $minver; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub _build_detected_perl { | ||||||||||||||||||||||||||
|
Subroutine
_build_detected_perl: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 98 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | my $minver; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | foreach my $file ( @{ $self->found_files } ) { | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # TODO should we scan the content for the perl shebang? | ||||||||||||||||||||||||||||
| 104 | # Only check .t and .pm/pl files, thanks RT#67355 and DOHERTY | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | next unless $file->name =~ /[.](?:t|p[ml])\z/imsx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # TODO skip "bad" files and not die, just warn? | ||||||||||||||||||||||||||||
| 108 | 0 | my $pmv = Perl::MinimumVersion->new( \$file->content ); | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( not defined $pmv ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $self->log_fatal( [ 'Unable to parse \'%s\'', $file->name ] ); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 0 | my $ver = $pmv->minimum_version; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( not defined $ver ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | $self->log_fatal( [ 'Unable to extract MinimumPerl from \'%s\'', $file->name ] ); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( ( not defined $minver ) or $ver > $minver ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $minver or $ver > $minver
MC/DC0%0/2
not defined $minver or $ver > $minver
not defined $minver
$ver > $minver
Truth table0%0/3
not(A) or B
A= not defined $minverB= $ver > $minver
| |||||||||||||||||||||||||||||
| 117 | 0 | $self->log_debug( [ 'Increasing perl dep to %s due to %s', $ver, $file->name ] ); | |||||||||||||||||||||||||||
| 118 | 0 | $minver = $ver; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( $self->fiveten ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | $ver = $self->_3part_check( $file, $pmv, $minver ); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( "$ver" ne "$minver" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->log_debug( [ 'Increasing perl dep to %s due to 3-part in %s', $ver, $file->name ] ); | |||||||||||||||||||||||||||
| 124 | 0 | $minver = $ver; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # Write out the minimum perl found | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ( defined $minver ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | return $minver; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | return $self->log_fatal('Found no perl files, check your dist?'); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub minperl { | ||||||||||||||||||||||||||
|
Subroutine
minperl: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | 0 | require version; | |||||||||||||||||||||||||||
| 144 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ( not $self->_has_perl ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | return $self->detected_perl; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | my ($x) = version->parse( $self->perl ); | |||||||||||||||||||||||||||
| 149 | 0 | my ($y) = $self->detected_perl; | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ( $x > $y ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | return $x; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 0 | return $y; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | 1; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||