]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Maps.pm
Correctly map exotic Gentoo versions from CPAN versions
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo / Maps.pm
1 package CPANPLUS::Dist::Gentoo::Maps;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 CPANPLUS::Dist::Gentoo::Maps - Map CPAN objects to Gentoo and vice versa.
9
10 =head1 VERSION
11
12 Version 0.10
13
14 =cut
15
16 our $VERSION = '0.10';
17
18 =head1 DESCRPITON
19
20 This is an helper package to L<CPANPLUS::Dist::Gentoo>.
21
22 =cut
23
24 my %name_mismatch;
25
26 /^\s*([\w-]+)\s+([\w-]+)\s*$/ and $name_mismatch{$1} = $2 while <DATA>;
27
28 close DATA;
29
30 =head1 FUNCTIONS
31
32 =head2 C<name_c2g $name>
33
34 Maps a CPAN distribution name to its Gentoo counterpart.
35
36 =cut
37
38 sub name_c2g {
39  my ($name) = @_;
40  return $name_mismatch{$name} || $name;
41 }
42
43 =head2 C<license_c2g @licenses>
44
45 Maps F<META.yml> C<license> tag values to the corresponding list of Gentoo licenses identifiers.
46 Duplicates are stripped off.
47
48 The included data was gathered from L<Module::Install> and L<Software::License>.
49
50 =cut
51
52 my %licenses = (
53  apache     => [ 'Apache-2.0' ],
54  artistic   => [ 'Artistic' ],
55  artistic_2 => [ 'Artistic-2' ],
56  bsd        => [ 'BSD' ],
57  gpl        => [ 'GPL-1' ],
58  gpl2       => [ 'GPL-2' ],
59  gpl3       => [ 'GPL-3' ],
60  lgpl       => [ 'LGPL-2.1' ],
61  lgpl2      => [ 'LGPL-2.1' ],
62  lgpl3      => [ 'LGPL-3' ],
63  mit        => [ 'MIT' ],
64  mozilla    => [ 'MPL-1.1' ],
65  perl       => [ 'Artistic', 'GPL-2' ],
66 );
67
68 sub license_c2g {
69  my %seen;
70  grep !$seen{$_}++, map @{$licenses{+lc} || []}, @_;
71 }
72
73 =head2 C<version_c2g $name, $version>
74
75 Converts the C<$version> of a CPAN distribution C<$name> to a Gentoo version.
76
77 =cut
78
79 my $default_mapping = sub {
80  my ($v) = @_;
81
82  $v =~ s/^v//;
83  $v =~ y/-/_/;
84
85  $v =~ s/^[._]*//;
86  $v =~ s/[._]*$//;
87  $v =~ s/([._])[._]*/$1/g;
88
89  ($v, my $patch) = split /_/, $v, 2;
90  if (defined $patch) {
91   $patch =~ s/_//g;
92   $v .= "_p$patch";
93  }
94
95  return $v;
96 };
97
98 my $insert_dot_at = sub {
99  my ($v, $pos, $all) = @_;
100
101  my ($int, $frac) = split /\./, $v, 2;
102  return $v unless defined $frac;
103
104  my @p;
105  push @p, $-[0] while $frac =~ /[0-9]/g;
106  my %digit = map { $_ => 1 } @p;
107
108  my $shift = 0;
109  for (my $i = $pos; $i < @p; $i += $pos) {
110   if ($digit{$i}) {
111    substr($frac, $i + $shift, 0) = '.';
112    ++$shift;
113   }
114   last unless $all;
115  }
116
117  "$int.$frac";
118 };
119
120 my $insert_dot_at_1     = sub { $insert_dot_at->($_[0], 1, 0) },
121 my $insert_dot_at_all_1 = sub { $insert_dot_at->($_[0], 1, 1) },
122 my $insert_dot_at_2     = sub { $insert_dot_at->($_[0], 2, 0) },
123 my $insert_dot_at_all_2 = sub { $insert_dot_at->($_[0], 2, 1) },
124 my $insert_dot_at_all_3 = sub { $insert_dot_at->($_[0], 3, 1) },
125
126 my $pad_decimals_to = sub {
127  my ($v, $n) = @_;
128
129  my ($int, $frac) = split /\./, $v, 2;
130  return $v unless defined $v;
131
132  my $l = length $frac;
133  if ($l < $n) {
134   $frac .= '0' x ($n - $l);
135  }
136
137  "$int.$frac";
138 };
139
140 my $pad_decimals_to_2 = sub { $pad_decimals_to->($_[0], 2) };
141 my $pad_decimals_to_4 = sub { $pad_decimals_to->($_[0], 4) };
142
143 my $correct_suffixes = sub {
144  my ($v) = @_;
145
146  $v = $default_mapping->($v);
147  $v =~ s/(?<!_)((?:alpha|beta|pre|rc|p)\d*)\b/_$1/g;
148
149  return $v;
150 };
151
152 my $strip_letters = sub {
153  my ($v) = @_;
154
155  $v = $default_mapping->($v);
156  $v =~ s/(?<=\d)[a-z]+//g;
157
158  return $v;
159 };
160
161 my $letters_as_suffix = sub {
162  my ($v) = @_;
163
164  $v = $default_mapping->($v);
165  $v =~ s/(?<=\d)b(?=\d)/_beta/g;
166
167  return $v;
168 };
169
170 my %version_mismatch;
171
172 $version_mismatch{$_} = $insert_dot_at_1 for qw/
173  CGI-Simple
174 /;
175
176 $version_mismatch{$_} = $insert_dot_at_all_1 for qw/
177  AnyEvent
178  Archive-Rar
179  IO-AIO
180  Image-Size
181  Linux-Inotify2
182  PadWalker
183  Tie-Array-Sorted
184  Tk-TableMatrix
185  XML-RSS-Feed
186 /;
187
188 $version_mismatch{$_} = $insert_dot_at_2 for qw/
189  Error
190 /;
191
192 $version_mismatch{$_} = $insert_dot_at_all_2 for qw/
193  Authen-Htpasswd
194  BSD-Resource
195  CDDB
196  Cairo
197  Curses-UI
198  DBD-mysql
199  Email-MessageID
200  ExtUtils-CBuilder
201  ExtUtils-ParseXS
202  FileHandle-Unget
203  FreezeThaw
204  Lexical-Persistence
205  Lingua-EN-Inflect
206  Mail-Mbox-MessageParser
207  Module-Build
208  SQL-Abstract-Limit
209  Term-ReadLine-Perl
210  Test-Differences
211  Time-HiRes
212  Time-Local
213  perl-ldap
214 /;
215
216 $version_mismatch{$_} = $insert_dot_at_all_3 for qw/
217  Parse-RecDescent
218  Return-Value
219 /;
220
221 $version_mismatch{$_} = $pad_decimals_to_2 for qw/
222  Nmap-Parser
223  XML-AutoWriter
224 /;
225
226 $version_mismatch{$_} = $pad_decimals_to_4 for qw/
227  Convert-BER
228 /;
229
230 $version_mismatch{$_} = $correct_suffixes for qw/
231  Gimp
232  XML-Grove
233 /;
234
235 $version_mismatch{$_} = $strip_letters for qw/
236  DelimMatch
237  SGMLSpm
238 /;
239
240 $version_mismatch{$_} = $letters_as_suffix for qw/
241  Frontier-RPC
242 /;
243
244 sub version_c2g {
245  my ($n, $v) = @_;
246
247  return unless defined $v;
248
249  my $handler;
250  $handler = $version_mismatch{$n} if defined $n;
251  $handler = $default_mapping  unless defined $handler;
252
253  return $handler->($v);
254 }
255
256 =head2 C<perl_version_c2g $version>
257
258 Converts a perl version as you can find it in prerequisites to a Gentoo version number.
259
260 =cut
261
262 sub perl_version_c2g {
263  my ($v) = @_;
264
265  return unless defined $v and $v =~ /^[0-9\.]+$/;
266
267  my @parts;
268  if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) {
269   my $len = length $subversion;
270   if (my $pad = $len % 3) {
271    $subversion .= '0' x (3 - $pad);
272   }
273   @parts = ($version, $subversion =~ /(.{1,3})/g);
274  } else {
275   @parts = split /\./, $v;
276  }
277
278  return join '.', map int, @parts;
279 }
280
281 =head1 SEE ALSO
282
283 L<CPANPLUS::Dist::Gentoo>.
284
285 =head1 AUTHOR
286
287 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
288
289 You can contact me by mail or on C<irc.perl.org> (vincent).
290
291 =head1 BUGS
292
293 Please report any bugs or feature requests to C<bug-cpanplus-dist-gentoo at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPANPLUS-Dist-Gentoo>.
294 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
295
296 =head1 SUPPORT
297
298 You can find documentation for this module with the perldoc command.
299
300     perldoc CPANPLUS::Dist::Gentoo
301
302 =head1 COPYRIGHT & LICENSE
303
304 Copyright 2009,2010 Vincent Pit, all rights reserved.
305
306 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
307
308 =cut
309
310 1; # End of CPANPLUS::Dist::Gentoo::Maps
311
312 __DATA__
313 ANSIColor               Term-ANSIColor
314 AcePerl                 Ace
315 CGI-Simple              Cgi-Simple
316 CGI-SpeedyCGI           SpeedyCGI
317 CPAN-Mini-Phalanx100    CPAN-Mini-Phalanx
318 Cache-Mmap              cache-mmap
319 Class-Loader            class-loader
320 Class-ReturnValue       class-returnvalue
321 Config-General          config-general
322 Convert-ASCII-Armour    convert-ascii-armour
323 Convert-PEM             convert-pem
324 Crypt-CBC               crypt-cbc
325 Crypt-DES_EDE3          crypt-des-ede3
326 Crypt-DH                crypt-dh
327 Crypt-DSA               crypt-dsa
328 Crypt-IDEA              crypt-idea
329 Crypt-Primes            crypt-primes
330 Crypt-RSA               crypt-rsa
331 Crypt-Random            crypt-random
332 DBIx-SearchBuilder      dbix-searchbuilder
333 Data-Buffer             data-buffer
334 Date-Manip              DateManip
335 Digest                  digest-base
336 Digest-BubbleBabble     digest-bubblebabble
337 Digest-MD2              digest-md2
338 ExtUtils-Depends        extutils-depends
339 ExtUtils-PkgConfig      extutils-pkgconfig
340 Frontier-RPC            frontier-rpc
341 Gimp                    gimp-perl
342 Glib                    glib-perl
343 Gnome2                  gnome2-perl
344 Gnome2-Canvas           gnome2-canvas
345 Gnome2-GConf            gnome2-gconf
346 Gnome2-Print            gnome2-print
347 Gnome2-VFS              gnome2-vfs-perl
348 Gnome2-Wnck             gnome2-wnck
349 Gtk2                    gtk2-perl
350 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
351 Gtk2-GladeXML           gtk2-gladexml
352 Gtk2-Spell              gtk2-spell
353 Gtk2-TrayIcon           gtk2-trayicon
354 Gtk2-TrayManager        gtk2-traymanager
355 Gtk2Fu                  gtk2-fu
356 I18N-LangTags           i18n-langtags
357 Image-Info              ImageInfo
358 Image-Size              ImageSize
359 Inline-Files            inline-files
360 Locale-Maketext         locale-maketext
361 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
362 Locale-Maketext-Lexicon locale-maketext-lexicon
363 Log-Dispatch            log-dispatch
364 Math-Pari               math-pari
365 Module-Info             module-info
366 NTLM                    Authen-NTLM
367 Net-Ping                net-ping
368 Net-SFTP                net-sftp
369 Net-SSH-Perl            net-ssh-perl
370 Net-Server              net-server
371 OLE-Storage_Lite        OLE-StorageLite
372 Ogg-Vorbis-Header       ogg-vorbis-header
373 PathTools               File-Spec
374 Perl-Tidy               perltidy
375 Pod-Parser              PodParser
376 Regexp-Common           regexp-common
377 SDL_Perl                sdl-perl
378 Set-Scalar              set-scalar
379 String-CRC32            string-crc32
380 Text-Autoformat         text-autoformat
381 Text-Reform             text-reform
382 Text-Template           text-template
383 Text-Wrapper            text-wrapper
384 Tie-EncryptedHash       tie-encryptedhash
385 Tk                      perl-tk
386 Wx                      wxperl
387 XML-Sablotron           XML-Sablot
388 YAML                    yaml
389 gettext                 Locale-gettext
390 txt2html                TextToHTML