diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2014-12-24 10:00:02 +0000 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2014-12-24 10:00:02 +0000 |
commit | 2427f8385ab2076bc9679cbfc494e30f95d13e90 (patch) | |
tree | 3c510f81354a100572e76da3dce921996770148f /cpan/CPAN-Meta-Requirements | |
parent | 1b6c6743385984747851a6b7f2158cca8828efa4 (diff) | |
download | perl-2427f8385ab2076bc9679cbfc494e30f95d13e90.tar.gz |
Update CPAN-Meta-Requirements to CPAN version 2.131
[DELTA]
2.131 2014-12-23 15:04:19-05:00 America/New_York
[ENHANCEMENTS]
- Merging Module => 0 into requirements is now optimized
[PREREQS]
- Scalar::Utils removed as a prerequisite
Diffstat (limited to 'cpan/CPAN-Meta-Requirements')
-rw-r--r-- | cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm | 56 | ||||
-rw-r--r-- | cpan/CPAN-Meta-Requirements/t/accepts.t | 10 | ||||
-rw-r--r-- | cpan/CPAN-Meta-Requirements/t/strings.t | 63 |
3 files changed, 119 insertions, 10 deletions
diff --git a/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm b/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm index 05df504692..e86dd561d4 100644 --- a/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm +++ b/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm @@ -3,7 +3,7 @@ use warnings; package CPAN::Meta::Requirements; # ABSTRACT: a set of version requirements for a CPAN dist -our $VERSION = '2.130'; +our $VERSION = '2.131'; #pod =head1 SYNOPSIS #pod @@ -33,7 +33,6 @@ our $VERSION = '2.130'; #pod =cut use Carp (); -use Scalar::Util (); # To help ExtUtils::MakeMaker bootstrap CPAN::Meta::Requirements on perls # before 5.10, we fall back to the EUMM bundled compatibility version module if @@ -51,6 +50,9 @@ BEGIN { # Perl 5.10.0 didn't have "is_qv" in version.pm *_is_qv = version->can('is_qv') ? sub { $_[0]->is_qv } : sub { exists $_[0]->{qv} }; +# construct once, reuse many times +my $V0 = version->new(0); + #pod =method new #pod #pod my $req = CPAN::Meta::Requirements->new; @@ -100,6 +102,11 @@ sub _find_magic_vstring { return $tvalue; } +# safe if given an unblessed reference +sub _isa_version { + UNIVERSAL::isa( $_[0], 'UNIVERSAL' ) && $_[0]->isa('version') +} + sub _version_object { my ($self, $module, $version) = @_; @@ -112,17 +119,23 @@ sub _version_object { } eval { - local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" }; - $vobj = (! defined $version) ? version->new(0) - : (! Scalar::Util::blessed($version)) ? version->new($version) - : $version; + if (not defined $version or $version eq '0') { + $vobj = $V0; + } + elsif ( ref($version) eq 'version' || _isa_version($version) ) { + $vobj = $version; + } + else { + local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" }; + $vobj = version->new($version); + } }; if ( my $err = $@ ) { my $hook = $self->{bad_version_hook}; $vobj = eval { $hook->($version, $module) } if ref $hook eq 'CODE'; - unless (Scalar::Util::blessed($vobj) && $vobj->isa("version")) { + unless (eval { $vobj->isa("version") }) { $err =~ s{ at .* line \d+.*$}{}; die "Can't convert '$version': $err"; } @@ -194,7 +207,7 @@ sub _version_object { #pod =cut BEGIN { - for my $type (qw(minimum maximum exclusion exact_version)) { + for my $type (qw(maximum exclusion exact_version)) { my $method = "with_$type"; my $to_add = $type eq 'exact_version' ? $type : "add_$type"; @@ -213,6 +226,25 @@ BEGIN { } } +sub add_minimum { + my ($self, $name, $version) = @_; + + if (not defined $version or $version eq '0') { + return $self if $self->__entry_for($name); + Carp::confess("can't add new requirements to finalized requirements") + if $self->is_finalized; + + $self->{requirements}{ $name } = + CPAN::Meta::Requirements::_Range::Range->with_minimum($V0); + } + else { + $version = $self->_version_object( $name, $version ); + + $self->__modify_entry_for($name, 'with_minimum', $version); + } + return $self; +} + #pod =method add_requirements #pod #pod $req->add_requirements( $another_req_object ); @@ -755,7 +787,7 @@ CPAN::Meta::Requirements - a set of version requirements for a CPAN dist =head1 VERSION -version 2.130 +version 2.131 =head1 SYNOPSIS @@ -1037,7 +1069,7 @@ Ricardo Signes <rjbs@cpan.org> =head1 CONTRIBUTORS -=for stopwords Ed J Karen Etheridge robario +=for stopwords Ed J Karen Etheridge Leon Timmermans robario =over 4 @@ -1051,6 +1083,10 @@ Karen Etheridge <ether@cpan.org> =item * +Leon Timmermans <fawaka@gmail.com> + +=item * + robario <webmaster@robario.com> =back diff --git a/cpan/CPAN-Meta-Requirements/t/accepts.t b/cpan/CPAN-Meta-Requirements/t/accepts.t index 3456394873..75bc22f7ad 100644 --- a/cpan/CPAN-Meta-Requirements/t/accepts.t +++ b/cpan/CPAN-Meta-Requirements/t/accepts.t @@ -13,6 +13,16 @@ use Test::More 0.88; } { + my $req = CPAN::Meta::Requirements->new->add_minimum(Foo => 0); + + ok( $req->accepts_module(Foo => 1)); + ok( $req->accepts_module(Foo => undef)); + ok( $req->accepts_module(Foo => "v0")); + ok( $req->accepts_module(Foo => v1.2.3)); + ok( $req->accepts_module(Foo => "v1.2.3")); +} + +{ my $req = CPAN::Meta::Requirements->new->add_maximum(Foo => 1); ok( $req->accepts_module(Foo => 1)); diff --git a/cpan/CPAN-Meta-Requirements/t/strings.t b/cpan/CPAN-Meta-Requirements/t/strings.t new file mode 100644 index 0000000000..94a52367a4 --- /dev/null +++ b/cpan/CPAN-Meta-Requirements/t/strings.t @@ -0,0 +1,63 @@ +use strict; +use warnings; +use Test::More 0.88; + +sub dies_ok (&@) { + my ($code, $qr, $comment) = @_; + + my $lived = eval { $code->(); 1 }; + + if ($lived) { + fail("$comment: did not die"); + } else { + like($@, $qr, $comment); + } +} + +use CPAN::Meta::Requirements; + +my $req = CPAN::Meta::Requirements->new; + +# Test == +$req->add_string_requirement('Foo::Bar', '== 1.3'); +ok($req->accepts_module('Foo::Bar' => '1.3'), 'exact version (==)'); +ok(!$req->accepts_module('Foo::Bar' => '1.2'), 'lower version (==)'); +ok(!$req->accepts_module('Foo::Bar' => '1.4'), 'higher version (==)'); + +# Test != +$req->add_string_requirement('Foo::Baz', '!= 1.3'); +ok(!$req->accepts_module('Foo::Baz' => '1.3'), 'exact version (!=)'); +ok($req->accepts_module('Foo::Baz' => '1.2'), 'lower version (!=)'); +ok($req->accepts_module('Foo::Baz' => '1.4'), 'higher version (!=)'); + +# Test >= +$req->add_string_requirement('Foo::Gorch', '>= 1.3'); +ok($req->accepts_module('Foo::Gorch' => '1.3'), 'exact version (>=)'); +ok(!$req->accepts_module('Foo::Gorch' => '1.2'), 'lower version (>=)'); +ok($req->accepts_module('Foo::Gorch' => '1.4'), 'higher version (>=)'); + +# Test <= +$req->add_string_requirement('Foo::Graz', '<= 1.3'); +ok($req->accepts_module('Foo::Graz' => '1.3'), 'exact version (<=)'); +ok($req->accepts_module('Foo::Graz' => '1.2'), 'lower version (<=)'); +ok(!$req->accepts_module('Foo::Graz' => '1.4'), 'higher version (<=)'); + +# Test "" +$req->add_string_requirement('Foo::Blurb', '>= 1.3'); +ok($req->accepts_module('Foo::Blurb' => '1.3'), 'exact version (>=)'); +ok(!$req->accepts_module('Foo::Blurb' => '1.2'), 'lower version (>=)'); +ok($req->accepts_module('Foo::Blurb' => '1.4'), 'higher version (>=)'); + +# Test multiple requirements +$req->add_string_requirement('A::Tribe::Called', '>= 1.3, <= 2.0, != 1.6'); +ok($req->accepts_module('A::Tribe::Called' => '1.5'), 'middle version (>=, <=, !)'); +ok(!$req->accepts_module('A::Tribe::Called' => '1.2'), 'lower version (>=, <=, !)'); +ok(!$req->accepts_module('A::Tribe::Called' => '2.1'), 'higher version (>=, <=, !)'); +ok(!$req->accepts_module('A::Tribe::Called' => '1.6'), 'excluded version (>=, <=, !)'); + +# Test fatal errors +dies_ok { $req->add_string_requirement('Foo::Bar', "not really a version") } + qr/Can't convert/, + "conversion failure caught"; + +done_testing; |