From: Vincent Pit Date: Thu, 14 Jun 2012 21:46:31 +0000 (+0200) Subject: Update gentooisms X-Git-Tag: v0.12~6 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=761b2973c70ba26f3442b701a2d4e8d28c083f11;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git Update gentooisms Since most of the distributions in the portage tree have seen their version numbering scheme being migrated to a new (more consistent) one, the default mapping has been changed. --- diff --git a/lib/CPANPLUS/Dist/Gentoo/Maps.pm b/lib/CPANPLUS/Dist/Gentoo/Maps.pm index 787dc89..fd1cd8a 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Maps.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Maps.pm @@ -81,168 +81,197 @@ Converts the C<$version> of a CPAN distribution C<$name> to a Gentoo version num =cut my $default_mapping = sub { - my ($v) = @_; + my ($version, @no_strip) = @_; + + my $is_dev = $version =~ /_/; + my $has_v = $version =~ s/^v//; - $v =~ s/^v//; - $v =~ y/-/_/; + for ($version) { + y/_-//d; + s/^\.*//; + s/\.*\z//; + s/\.+/./g; + } - $v =~ s/^[._]*//; - $v =~ s/[._]*$//; - $v =~ s/([._])[._]*/$1/g; + my $dots = $version =~ y/\.//; - ($v, my $patch) = split /_/, $v, 2; - if (defined $patch) { - $patch =~ s/_//g; - $v .= "_p$patch"; + my @parts; + if ($has_v or $dots >= 2) { + @parts = split /\./, $version; + } else { + ($parts[0], my $subversion) = split /\./, $version, 2; + $subversion = '0' unless defined $subversion; + my $sublen = length $subversion; + if ($sublen < 6) { + $subversion .= '0' x (6 - $sublen); + } else { + my $pad = $sublen % 3; + $subversion .= '0' x (3 - $pad) if $pad; + } + push @parts, $subversion =~ /(...)/g; } - return $v; -}; + for my $i (0 .. $#parts) { + next if $no_strip[$i]; + $parts[$i] =~ s/^0+([^0]|0\z)/$1/; + } + $version = join '.', @parts; -my $insert_dot_at = sub { - my ($v, $pos, $all) = @_; + $version .= '_rc' if $is_dev; - my ($int, $frac) = split /\./, $v, 2; - return $v unless defined $frac; + return $version; +}; - my @p; - push @p, $-[0] while $frac =~ /[0-9]/g; - my %digit = map { $_ => 1 } @p; +my $default_but_ignore_v = sub { + my ($version) = @_; - my $shift = 0; - for (my $i = $pos; $i < @p; $i += $pos) { - if ($digit{$i}) { - substr($frac, $i + $shift, 0) = '.'; - ++$shift; - } - last unless $all; - } + $version =~ s/^v//; - "$int.$frac"; + return $default_mapping->($version); }; -my $insert_dot_at_1 = sub { $insert_dot_at->($_[0], 1, 0) }, -my $insert_dot_at_all_1 = sub { $insert_dot_at->($_[0], 1, 1) }, -my $insert_dot_at_2 = sub { $insert_dot_at->($_[0], 2, 0) }, -my $insert_dot_at_all_2 = sub { $insert_dot_at->($_[0], 2, 1) }, -my $insert_dot_at_all_3 = sub { $insert_dot_at->($_[0], 3, 1) }, +my $default_but_no_strip_1 = sub { + return $default_mapping->($_[0], 0, 1); +}; -my $pad_decimals_to = sub { - my ($v, $n) = @_; +my $default_but_no_strip_2 = sub { + return $default_mapping->($_[0], 0, 1, 1); +}; + +my $insert_dot_every = sub { + my ($version, $step) = @_; - my ($int, $frac) = split /\./, $v, 2; - return $v unless defined $v; + my $is_dev = $version =~ /_/; - my $l = length $frac; - if ($l < $n) { - $frac .= '0' x ($n - $l); + for ($version) { + s/^v//; + y/_-//d; + s/^\.*//; + s/\.*\z//; + s/\.+/./g; } - "$int.$frac"; + my @parts; + ($parts[0], my $subversion) = split /\./, $version, 2; + $subversion =~ s/\.//g; + my $pat = sprintf '.{1,%d}', $step || 1; + push @parts, $subversion =~ /($pat)/g; + + s/^0+([^0]|0\z)/$1/ for @parts; + $version = join '.', @parts; + + $version .= '_rc' if $is_dev; + + return $version; }; -my $pad_decimals_to_2 = sub { $pad_decimals_to->($_[0], 2) }; -my $pad_decimals_to_4 = sub { $pad_decimals_to->($_[0], 4) }; +my $simple_cleanup = sub { + my ($version) = @_; -my $correct_suffixes = sub { - my ($v) = @_; + my $is_dev = $version =~ /_/; - $v = $default_mapping->($v); - $v =~ s/(?($v); - $v =~ s/(?<=\d)[a-z]+//g; + $version = $simple_cleanup->($version); + $version =~ s/(?($v); - $v =~ s/(?<=\d)b(?=\d)/_beta/g; + $version = $simple_cleanup->($version); + $version =~ s/(?<=\d)[a-z]+//g; - return $v; + return $version; }; -my %version_mismatch; +my $simple_and_letters_as_suffix = sub { + my ($version) = @_; -$version_mismatch{$_} = $insert_dot_at_1 for qw< - CGI-Simple ->; + $version = $simple_cleanup->($version); + $version =~ s/(?<=\d)b(?=\d)/_beta/g; + + return $version; +}; + +my %version_mismatch; -$version_mismatch{$_} = $insert_dot_at_all_1 for qw< - AnyEvent - Archive-Rar - IO-AIO - Image-Size - Linux-Inotify2 - PadWalker - Tie-Array-Sorted - Tk-TableMatrix - XML-RSS-Feed +$version_mismatch{$_} = $default_but_ignore_v for qw< + Net-DNS-Resolver-Programmable >; -$version_mismatch{$_} = $insert_dot_at_2 for qw< - Error +$version_mismatch{$_} = $default_but_no_strip_1 for qw< + Crypt-RC4 + File-Grep + MogileFS-Client-Async + MogileFS-Network >; -$version_mismatch{$_} = $insert_dot_at_all_2 for qw< - Authen-Htpasswd - BSD-Resource - CDDB - Cairo - Curses-UI - DBD-mysql - Email-MessageID - Exception-Base - ExtUtils-CBuilder - ExtUtils-ParseXS - FileHandle-Unget - FreezeThaw - Lexical-Persistence - Lingua-EN-Inflect - Mail-Mbox-MessageParser - Module-Build - SQL-Abstract-Limit - Term-ReadLine-Perl - Test-Differences - Time-HiRes - Time-Local - perl-ldap +$version_mismatch{$_} = $default_but_no_strip_2 for qw< + Net-IMAP-Simple >; -$version_mismatch{$_} = $insert_dot_at_all_3 for qw< - Parse-RecDescent - Return-Value +$version_mismatch{$_} = sub { $insert_dot_every->($_[0], 1) } for qw< + HTTP-Cookies + HTTP-Negotiate >; -$version_mismatch{$_} = $pad_decimals_to_2 for qw< - Nmap-Parser - XML-AutoWriter +$version_mismatch{$_} = sub { $insert_dot_every->($_[0], 3) } for qw< + POE-Component-IKC >; -$version_mismatch{$_} = $pad_decimals_to_4 for qw< - Convert-BER +$version_mismatch{$_} = $simple_cleanup for qw< + Alien-SDL + CGI-SpeedyCGI + Class-ISA + Data-Uniqid + ExtUtils-Install + File-Path + Getopt-GUI-Long + Gtk2-Notify + HTML-Table + I18N-LangTags + IO + IPC-System-Simple + Log-TraceMessages + MusicBrainz-DiscID + Net-IRC + Net-Ping + SDL + SOAP-WSDL + TeX-Encode + Tie-Simple + Time-Piece + WattsUp-Daemon >; -$version_mismatch{$_} = $correct_suffixes for qw< +$version_mismatch{$_} = $simple_and_correct_suffixes for qw< Gimp XML-Grove >; -$version_mismatch{$_} = $strip_letters for qw< +$version_mismatch{$_} = $simple_and_strip_letters for qw< DelimMatch SGMLSpm >; -$version_mismatch{$_} = $letters_as_suffix for qw< +$version_mismatch{$_} = $simple_and_letters_as_suffix for qw< Frontier-RPC >; @@ -315,7 +344,6 @@ This program is free software; you can redistribute it and/or modify it under th 1; # End of CPANPLUS::Dist::Gentoo::Maps __DATA__ -ANSIColor Term-ANSIColor AcePerl Ace CGI-Simple Cgi-Simple CGI-SpeedyCGI SpeedyCGI @@ -348,7 +376,6 @@ Glib glib-perl Gnome2 gnome2-perl Gnome2-Canvas gnome2-canvas Gnome2-GConf gnome2-gconf -Gnome2-Print gnome2-print Gnome2-VFS gnome2-vfs-perl Gnome2-Wnck gnome2-wnck Gtk2 gtk2-perl @@ -380,7 +407,6 @@ PathTools File-Spec Perl-Tidy perltidy Pod-Parser PodParser Regexp-Common regexp-common -SDL_Perl sdl-perl Set-Scalar set-scalar String-CRC32 string-crc32 Text-Autoformat text-autoformat @@ -388,6 +414,7 @@ Text-Reform text-reform Text-Template text-template Text-Wrapper text-wrapper Tie-EncryptedHash tie-encryptedhash +Time-Period Period Tk perl-tk Wx wxperl XML-Sablotron XML-Sablot diff --git a/t/11-maps-name.t b/t/11-maps-name.t index ca48370..acc58f1 100644 --- a/t/11-maps-name.t +++ b/t/11-maps-name.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 1 + 7 + 9; +use Test::More tests => 1 + 6 + 10; use CPANPLUS::Dist::Gentoo::Maps; @@ -12,7 +12,6 @@ use CPANPLUS::Dist::Gentoo::Maps; is nc2g('CPANPLUS-Dist-Gentoo'), 'CPANPLUS-Dist-Gentoo', 'name_c2g returns non gentooisms correctly'; my %core_gentooisms = ( - 'ANSIColor' => 'Term-ANSIColor', 'Digest' => 'digest-base', 'I18N-LangTags' => 'i18n-langtags', 'Locale-Maketext' => 'locale-maketext', @@ -32,6 +31,7 @@ my %cpan_gentooisms = ( 'Log-Dispatch' => 'log-dispatch', 'Math-Pari' => 'math-pari', 'Regexp-Common' => 'regexp-common', + 'Time-Period' => 'Period', 'Tk' => 'perl-tk', 'Wx' => 'wxperl', 'YAML' => 'yaml', diff --git a/t/12-maps-version.t b/t/12-maps-version.t index 823e98c..8bb8c9d 100644 --- a/t/12-maps-version.t +++ b/t/12-maps-version.t @@ -12,25 +12,25 @@ use CPANPLUS::Dist::Gentoo::Maps; goto &CPANPLUS::Dist::Gentoo::Maps::version_c2g }; -is vc2g('1'), '1', "version_c2g('1')"; -is vc2g('v1'), '1', "version_c2g('v1')"; -is vc2g('..1'), '1', "version_c2g('..1')"; -is vc2g('1.0'), '1.0', "version_c2g('1.0')"; -is vc2g('v1.0'), '1.0', "version_c2g('v1.0')"; -is vc2g('1._0'), '1.0', "version_c2g('1._0')"; -is vc2g('1_1'), '1_p1', "version_c2g('1_1')"; -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_p12', "version_c2g('1_.1_2')"; -is vc2g('1_.1_.2'), '1_p12', "version_c2g('1_.1_.2')"; - -for my $test ([ '0.12' => '0.12' ], [ '0.1234' => '0.12.34' ]) { +is vc2g('1'), '1.0.0', "version_c2g('1')"; +is vc2g('v1'), '1', "version_c2g('v1')"; +is vc2g('..1'), '1.0.0', "version_c2g('..1')"; +is vc2g('1.0'), '1.0.0', "version_c2g('1.0')"; +is vc2g('v1.0'), '1.0', "version_c2g('v1.0')"; +is vc2g('1._0'), '1.0.0_rc', "version_c2g('1._0')"; +is vc2g('1_1'), '11.0.0_rc', "version_c2g('1_1')"; +is vc2g('1_.1'), '1.100.0_rc', "version_c2g('1_.1')"; +is vc2g('1_.1._2'), '1.1.2_rc', "version_c2g('1_.1._2')"; +is vc2g('1_.1_2'), '1.120.0_rc', "version_c2g('1_.1_2')"; +is vc2g('1_.1_.2'), '1.1.2_rc', "version_c2g('1_.1_.2')"; + +for my $test ([ '0.12' => '0.12' ], [ '0.1234' => '0.1234' ]) { my @dists = qw< - ExtUtils-CBuilder - ExtUtils-ParseXS - Module-Build - Time-HiRes - Time-Local + ExtUtils-Install + File-Path + I18N-LangTags + IO + Time-Piece >; for my $dist (@dists) { is vc2g($dist, $test->[0]), $test->[1], "'version_c2g('$dist', '$test->[0]')";