Skip to content

Commit

Permalink
Translate perl versions like $] into dotted-decimal versions.
Browse files Browse the repository at this point in the history
ArchLinux uses dotted decimal versions like: 5.12.2 while some
packages use decimal versions like: 5.012002. This confuses
pacman.

Adds some tests to 01-translate.t as well.
  • Loading branch information
juster committed Feb 2, 2011
1 parent dcae978 commit 3ec9385
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
*** Emacs local variables
Because I am tired of adding them in manually. You will see them
at the end of the PKGBUILD. I forget what the vim equivalent is.
** Perl Version Conversion :BUGFIX:
When some modules depend on perl they use the decimal notation for
the version string (i.e. 5.006001) whereas ArchLinux uses the
dotted-decimal notation for versions (i.e. 5.6.1). Pacman was
confused by the decimal notation so we now convert any explicit
dependencies on perl into dotted-decimal format.
*Reported by: Xenoterracide*

* 1.10 [2010-12-10 Fri]
** Cowardly Reverting
Expand Down
12 changes: 11 additions & 1 deletion lib/CPANPLUS/Dist/Arch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,16 @@ sub _extract_makedepends
return \%makedeps;
}

#---HELPER FUNCTION---
# Converts a decimal perl version (like $]) into the dotted decimal
# form that the official ArchLinux perl package uses.
sub _translate_perl_ver
{
my ($perlver) = @_;
return $perlver unless $perlver =~ / \A (\d+) [.] (\d{3}) (\d{3}) \z /xms;
return sprintf '%d.%d.%d', $1, $2, $3;
}

#---PRIVATE METHOD---
# Translates CPAN module dependencies into ArchLinux package dependencies.
sub _translate_cpan_deps
Expand All @@ -855,7 +865,7 @@ sub _translate_cpan_deps

# Sometimes a perl version is given as a prerequisite
if ( $modname eq 'perl' ) {
$pkgdeps{perl} = $depver;
$pkgdeps{perl} = _translate_perl_ver( $depver );
next CPAN_DEP_LOOP;
}

Expand Down
20 changes: 19 additions & 1 deletion t/01-translate.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Tests CPAN version to package version translation.
use warnings;
use strict;

use Test::More tests => 28;
use Test::More tests => 34;

BEGIN {
use_ok( 'CPANPLUS::Dist::Arch', qw(:all) );
Expand Down Expand Up @@ -70,3 +70,21 @@ for my $cpan_ver ( keys %pkgver_of ) {
$pkgver_of{$cpan_ver},
"CPAN to pacman version translation of $cpan_ver" );
}

# Also test conversion of decimal perl version strings.

my %perlpkgver_of =
( '5.006001' => '5.6.1',
'5.6.1' => '5.6.1',
'5.012001' => '5.12.1',
'5.0123456789' => 5.0123456789, # not 6 decimals? pass through
'5.01234' => 5.01234,
'.012345' => '.012345', # must have a major ver number
);

*_perl_ver = *CPANPLUS::Dist::Arch::_translate_perl_ver;

while ( my ($decimal, $dotdecimal) = each %perlpkgver_of ) {
is( _perl_ver( $decimal ), $dotdecimal,
"Conversion of perl version $decimal" );
}

0 comments on commit 3ec9385

Please sign in to comment.