From f8d9075a9bc19be19e518ca3d390e24f2af1b6e1 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sat, 19 Mar 2016 19:53:55 +0000 Subject: [PATCH 1/3] refactor prereq keys into constant --- lib/ExtUtils/MakeMaker.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm index 19357e4d3..127328595 100644 --- a/lib/ExtUtils/MakeMaker.pm +++ b/lib/ExtUtils/MakeMaker.pm @@ -39,6 +39,8 @@ our @EXPORT_OK = qw($VERSION &neatvalue &mkbootstrap &mksymlists &WriteEmptyMakefile &open_for_writing &write_file_via_tmp &_sprintf562); +my @PREREQ_KEYS = qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES); + # These will go away once the last of the Win32 & VMS specific code is # purged. my $Is_VMS = $^O eq 'VMS'; @@ -444,7 +446,7 @@ sub new { # Cleanup all the module requirement bits my %key2cmr; - for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) { + for my $key (@PREREQ_KEYS) { $self->{$key} ||= {}; if (_has_cpan_meta_requirements) { my $cmr = CPAN::Meta::Requirements->from_string_hash( @@ -551,14 +553,14 @@ END my $cmr; if (_has_cpan_meta_requirements) { $cmr = CPAN::Meta::Requirements->new; - for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) { + for my $key (@PREREQ_KEYS) { $cmr->add_requirements($key2cmr{$key}) if $key2cmr{$key}; } foreach my $prereq ($cmr->required_modules) { $prereq2version{$prereq} = $cmr->requirements_for_module($prereq); } } else { - for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) { + for my $key (@PREREQ_KEYS) { next unless my $module2version = $self->{$key}; $prereq2version{$_} = $module2version->{$_} for keys %$module2version; } From b62ffb32b2e3548c68e279dadfd2071a98ad0d4a Mon Sep 17 00:00:00 2001 From: Ed J Date: Sat, 19 Mar 2016 20:08:55 +0000 Subject: [PATCH 2/3] only call CMR check once --- lib/ExtUtils/MakeMaker.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm index 127328595..ff45fde73 100644 --- a/lib/ExtUtils/MakeMaker.pm +++ b/lib/ExtUtils/MakeMaker.pm @@ -446,9 +446,10 @@ sub new { # Cleanup all the module requirement bits my %key2cmr; + my $has_cpan_meta_requirements = _has_cpan_meta_requirements; for my $key (@PREREQ_KEYS) { $self->{$key} ||= {}; - if (_has_cpan_meta_requirements) { + if ($has_cpan_meta_requirements) { my $cmr = CPAN::Meta::Requirements->from_string_hash( $self->{$key}, { From ffdfb8761d2cbecc744d178fb3caf11abf717e09 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sat, 19 Mar 2016 20:28:46 +0000 Subject: [PATCH 3/3] test, doc, make warning if version range and not req EUMM >= 7.11_01 --- Changes | 5 ++++ lib/ExtUtils/MakeMaker.pm | 28 ++++++++++++++++++++++- t/prereq.t | 48 +++++++++++++++++++++++++++++++++++---- t/vstrings.t | 3 ++- 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 19c52fc06..209d6d263 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,8 @@ +7.11_06 + + Enhancements: + - Warn if use version range but no specify minimum EUMM >= 7.11_01 + 7.11_05 Sat Mar 19 09:41:02 GMT 2016 Bug fixes: diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm index ff45fde73..457129693 100644 --- a/lib/ExtUtils/MakeMaker.pm +++ b/lib/ExtUtils/MakeMaker.pm @@ -427,6 +427,28 @@ sub _has_cpan_meta_requirements { }; } +sub _min_EUMM { + my ($self) = @_; + my $cr = ($self->{CONFIGURE_REQUIRES} && $self->{CONFIGURE_REQUIRES}{'ExtUtils::MakeMaker'}); + return $cr if $cr; + my @meta_versions = sort grep defined, map { + (exists $_->{prereqs} and + exists $_->{prereqs}{configure} and + exists $_->{prereqs}{configure}{requires}) + ? $_->{prereqs}{configure}{requires}{'ExtUtils::MakeMaker'} + : () + } grep $_, @{$self}{qw(META_ADD META_MERGE)}; + return 0 unless @meta_versions; + $meta_versions[0] || 0; +} + +sub _got_version_ranges { + my ($self) = @_; + my @all_versions = map values %$_, grep defined, @{$self}{@PREREQ_KEYS}; + return 0 unless @all_versions; + grep /[^v\d\._]/, @all_versions; +} + sub new { my($class,$self) = @_; my($key); @@ -447,6 +469,9 @@ sub new { # Cleanup all the module requirement bits my %key2cmr; my $has_cpan_meta_requirements = _has_cpan_meta_requirements; + warn "Warning: version range without prerequisite of EUMM >= 7.11_01" + if $has_cpan_meta_requirements and $self->_min_EUMM < 7.1101 + and $self->_got_version_ranges; for my $key (@PREREQ_KEYS) { $self->{$key} ||= {}; if ($has_cpan_meta_requirements) { @@ -2684,7 +2709,8 @@ A hash of modules that are needed to run your module. The keys are the module names ie. Test::More, and the minimum version is the value. If the required version number is 0 any version will do. The versions given may be a Perl v-string (see L) or a range -(see L). +(see L). If you give a range, you need to +specify a minimum EUMM of at least C<7.11_01> in C. This will go into the C field of your F and the C of the C field of your F. diff --git a/t/prereq.t b/t/prereq.t index a01ff2bba..35521f70a 100644 --- a/t/prereq.t +++ b/t/prereq.t @@ -9,7 +9,7 @@ BEGIN { use strict; use Config; -use Test::More tests => 21; +use Test::More tests => 24; use File::Temp qw[tempdir]; use TieOut; @@ -57,7 +57,7 @@ ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || is $warnings, '', 'basic prereq'; SKIP: { - skip 'No CMR, no version ranges', 1 + skip 'No CMR, no version ranges', 4 unless ExtUtils::MakeMaker::_has_cpan_meta_requirements; $warnings = ''; WriteMakefile( @@ -66,7 +66,47 @@ ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || strict => '>= 0, <= 99999', } ); - is $warnings, '', 'version range'; + isnt $warnings, '', 'version range, no min EUMM specified'; + + $warnings = ''; + WriteMakefile( + NAME => 'Big::Dummy', + PREREQ_PM => { + strict => '>= 0, <= 99999', + }, + CONFIGURE_REQUIRES => { + 'ExtUtils::MakeMaker' => '7.04', + }, + ); + isnt $warnings, '', 'version range and insufficient EUMM specified'; + + $warnings = ''; + WriteMakefile( + NAME => 'Big::Dummy', + PREREQ_PM => { + strict => '>= 0, <= 99999', + }, + CONFIGURE_REQUIRES => { + 'ExtUtils::MakeMaker' => 7.11_01, + }, + ); + is $warnings, '', 'version range and sufficient EUMM specified'; + + $warnings = ''; + WriteMakefile( + NAME => 'Big::Dummy', + PREREQ_PM => { + strict => '>= 0, <= 99999', + }, + META_MERGE => { + prereqs => { + configure => { + requires => { 'ExtUtils::MakeMaker' => 7.1101 }, + }, + }, + }, + ); + is $warnings, '', 'version range and sufficient EUMM specified meta'; } $warnings = ''; @@ -74,7 +114,7 @@ ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) || NAME => 'Big::Dummy', PREREQ_PM => { strict => 99999 - } + }, ); is $warnings, sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n", diff --git a/t/vstrings.t b/t/vstrings.t index 808893687..4be56fb62 100644 --- a/t/vstrings.t +++ b/t/vstrings.t @@ -75,7 +75,8 @@ sub capture_make { WriteMakefile( NAME => 'VString::Test', - PREREQ_PM => { $package , $version } + PREREQ_PM => { $package , $version }, + CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => 7.1101 }, ); return $warnings;