From: Vincent Pit Date: Sat, 17 Apr 2010 13:18:49 +0000 (+0200) Subject: Enforce the right version of the perl dependency whenever possible X-Git-Tag: v0.10~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=ac86d926fe1f232054032ab4f36c301b8e5eccaa Enforce the right version of the perl dependency whenever possible --- diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 5f7545f..1616449 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -193,7 +193,7 @@ sub init { my $conf = $self->parent->parent->configure_object; $stat->mk_accessors(qw/name version author distribution desc uri src license - meta + meta min_perl fetched_arch requires ebuild_name ebuild_version ebuild_dir ebuild_file portdir_overlay @@ -363,6 +363,10 @@ sub prepare { } $stat->requires(\@requires); + $stat->min_perl(CPANPLUS::Dist::Gentoo::Maps::perl_version_c2g( + eval { $self->meta->{requires}->{perl} } + )); + return $OK->(); } @@ -546,10 +550,13 @@ sub ebuild_source { push @requires, $atom; } + my $min_perl = $stat->min_perl; my $perl = CPANPLUS::Dist::Gentoo::Atom->new( category => 'dev-lang', name => 'perl', + (defined $min_perl ? (version => $min_perl, range => '>=') : ()), ); + @requires = CPANPLUS::Dist::Gentoo::Atom->fold($perl, @requires); my $d = $stat->header; diff --git a/lib/CPANPLUS/Dist/Gentoo/Maps.pm b/lib/CPANPLUS/Dist/Gentoo/Maps.pm index fa87c8a..fb42999 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Maps.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Maps.pm @@ -95,6 +95,31 @@ sub version_c2g { return $v; } +=head2 C + +Converts a perl version as you can find it in prerequisites to a Gentoo version number. + +=cut + +sub perl_version_c2g { + my ($v) = @_; + + return unless defined $v and $v =~ /^[0-9\.]+$/; + + my @parts; + if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) { + my $len = length $subversion; + if (my $pad = $len % 3) { + $subversion .= '0' x (3 - $pad); + } + @parts = ($version, $subversion =~ /(.{1,3})/g); + } else { + @parts = split /\./, $v; + } + + return join '.', map int, @parts; +} + =head1 SEE ALSO L. diff --git a/t/12-maps-version.t b/t/12-maps-version.t index ea53f9b..13586ce 100644 --- a/t/12-maps-version.t +++ b/t/12-maps-version.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 10 + 7; use CPANPLUS::Dist::Gentoo::Maps; @@ -19,3 +19,13 @@ is vc2g('1_.1'), '1_p1', "version_c2g('1_.1')"; is vc2g('1_.1._2'), '1_p1.2', "version_c2g('1_.1._2')"; is vc2g('1_.1_2'), '1_p1.2', "version_c2g('1_.1_2')"; is vc2g('1_.1_.2'), '1_p1.2', "version_c2g('1_.1_.2')"; + +*pvc2g = \&CPANPLUS::Dist::Gentoo::Maps::perl_version_c2g; + +is pvc2g('5'), '5', "perl_version_c2g('5')"; +is pvc2g('5.1'), '5.1', "perl_version_c2g('5.1')"; +is pvc2g('5.01'), '5.10', "perl_version_c2g('5.01')"; +is pvc2g('5.10'), '5.10', "perl_version_c2g('5.10')"; +is pvc2g('5.1.2'), '5.1.2', "perl_version_c2g('5.1.2')"; +is pvc2g('5.01.2'), '5.1.2', "perl_version_c2g('5.01.2')"; +is pvc2g('5.01002'), '5.10.20', "perl_version_c2g('5.01002')";