]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Maps.pm
957450dd6621206e832dde99186d5705b4223eae
[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 distribution names, version numbers and license identifiers to their Gentoo counterparts.
9
10 =head1 VERSION
11
12 Version 0.11
13
14 =cut
15
16 our $VERSION = '0.11';
17
18 =head1 DESCRIPTION
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 the corresponding Gentoo package name.
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 license 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
71  grep !$seen{$_}++,
72   map @{$licenses{+lc} || []},
73    grep defined,
74     @_;
75 }
76
77 =head2 C<version_c2g $name, $version>
78
79 Converts the C<$version> of a CPAN distribution C<$name> to a Gentoo version number.
80
81 =cut
82
83 my $default_mapping = sub {
84  my ($version, @no_strip) = @_;
85
86  my $is_dev = $version =~ /_/;
87  my $has_v  = $version =~ s/^v//;
88
89  for ($version) {
90   y/_-//d;
91   s/^\.*//;
92   s/\.*\z//;
93   s/\.+/./g;
94  }
95
96  my $dots   = $version =~ y/\.//;
97
98  my @parts;
99  if ($has_v or $dots >= 2) {
100   @parts = split /\./, $version;
101  } else {
102   ($parts[0], my $subversion) = split /\./, $version, 2;
103   $subversion = '0' unless defined $subversion;
104   my $sublen = length $subversion;
105   if ($sublen < 6) {
106    $subversion .= '0' x (6 - $sublen);
107   } else {
108    my $pad = $sublen % 3;
109    $subversion .= '0' x (3 - $pad) if $pad;
110   }
111   push @parts, $subversion =~ /(...)/g;
112  }
113
114  for my $i (0 .. $#parts) {
115   next if $no_strip[$i];
116   $parts[$i] =~ s/^0+([^0]|0\z)/$1/;
117  }
118  $version  = join '.', @parts;
119
120  $version .= '_rc' if $is_dev;
121
122  return $version;
123 };
124
125 my $default_but_ignore_v = sub {
126  my ($version) = @_;
127
128  $version =~ s/^v//;
129
130  return $default_mapping->($version);
131 };
132
133 my $default_but_no_strip_1 = sub {
134  return $default_mapping->($_[0], 0, 1);
135 };
136
137 my $default_but_no_strip_2 = sub {
138  return $default_mapping->($_[0], 0, 1, 1);
139 };
140
141 my $insert_dot_every = sub {
142  my ($version, $step) = @_;
143
144  my $is_dev = $version =~ /_/;
145
146  for ($version) {
147   s/^v//;
148   y/_-//d;
149   s/^\.*//;
150   s/\.*\z//;
151   s/\.+/./g;
152  }
153
154  my @parts;
155  ($parts[0], my $subversion) = split /\./, $version, 2;
156  $subversion =~ s/\.//g;
157  my $pat = sprintf '.{1,%d}', $step || 1;
158  push @parts, $subversion =~ /($pat)/g;
159
160  s/^0+([^0]|0\z)/$1/ for @parts;
161  $version = join '.', @parts;
162
163  $version .= '_rc' if $is_dev;
164
165  return $version;
166 };
167
168 my $simple_cleanup = sub {
169  my ($version) = @_;
170
171  my $is_dev = $version =~ /_/;
172
173  for ($version) {
174   s/^v//;
175   y/_-//d;
176   s/^\.*//;
177   s/\.*\z//;
178   s/\.+/./g;
179  }
180
181  $version .= '_rc' if $is_dev;
182
183  return $version;
184 };
185
186 my $simple_and_correct_suffixes = sub {
187  my ($version) = @_;
188
189  $version = $simple_cleanup->($version);
190  $version =~ s/(?<!_)((?:alpha|beta|pre|rc|p)\d*)\b/_$1/g;
191
192  return $version;
193 };
194
195 my $simple_and_strip_letters = sub {
196  my ($version) = @_;
197
198  $version = $simple_cleanup->($version);
199  $version =~ s/(?<=\d)[a-z]+//g;
200
201  return $version;
202 };
203
204 my $simple_and_letters_as_suffix = sub {
205  my ($version) = @_;
206
207  $version = $simple_cleanup->($version);
208  $version =~ s/(?<=\d)b(?=\d)/_beta/g;
209
210  return $version;
211 };
212
213 my %version_mismatch;
214
215 $version_mismatch{$_} = $default_but_ignore_v for qw<
216  Net-DNS-Resolver-Programmable
217 >;
218
219 $version_mismatch{$_} = $default_but_no_strip_1 for qw<
220  Crypt-RC4
221  File-Grep
222  MogileFS-Client-Async
223  MogileFS-Network
224 >;
225
226 $version_mismatch{$_} = $default_but_no_strip_2 for qw<
227  Net-IMAP-Simple
228 >;
229
230 $version_mismatch{$_} = sub { $insert_dot_every->($_[0], 1) } for qw<
231  HTTP-Cookies
232  HTTP-Negotiate
233 >;
234
235 $version_mismatch{$_} = sub { $insert_dot_every->($_[0], 3) } for qw<
236  POE-Component-IKC
237 >;
238
239 $version_mismatch{$_} = $simple_cleanup for qw<
240  Alien-SDL
241  CGI-SpeedyCGI
242  Class-ISA
243  Data-Uniqid
244  ExtUtils-Install
245  File-Path
246  Getopt-GUI-Long
247  Gtk2-Notify
248  HTML-Table
249  I18N-LangTags
250  IO
251  IPC-System-Simple
252  Lab-Measurement
253  Log-TraceMessages
254  MusicBrainz-DiscID
255  Net-IRC
256  Net-Ping
257  SDL
258  SOAP-WSDL
259  TeX-Encode
260  Tie-Simple
261  Time-Piece
262  WattsUp-Daemon
263 >;
264
265 $version_mismatch{$_} = $simple_and_correct_suffixes for qw<
266  Gimp
267  XML-Grove
268 >;
269
270 $version_mismatch{$_} = $simple_and_strip_letters for qw<
271  DelimMatch
272  SGMLSpm
273 >;
274
275 $version_mismatch{$_} = $simple_and_letters_as_suffix for qw<
276  Frontier-RPC
277 >;
278
279 sub version_c2g {
280  my ($n, $v) = @_;
281
282  return unless defined $v;
283
284  my $handler;
285  $handler = $version_mismatch{$n} if defined $n;
286  $handler = $default_mapping  unless defined $handler;
287
288  return $handler->($v);
289 }
290
291 =head2 C<perl_version_c2g $version>
292
293 Converts a perl version number as you can find it in CPAN prerequisites to a Gentoo version number.
294
295 =cut
296
297 sub perl_version_c2g {
298  my ($v) = @_;
299
300  return unless defined $v and $v =~ /^[0-9\.]+$/;
301
302  my @parts;
303  if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) {
304   my $len = length $subversion;
305   if (my $pad = $len % 3) {
306    $subversion .= '0' x (3 - $pad);
307   }
308   @parts = ($version, $subversion =~ /(.{1,3})/g);
309  } else {
310   @parts = split /\./, $v;
311  }
312
313  return join '.', map int, @parts;
314 }
315
316 =head1 SEE ALSO
317
318 L<CPANPLUS::Dist::Gentoo>.
319
320 =head1 AUTHOR
321
322 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
323
324 You can contact me by mail or on C<irc.perl.org> (vincent).
325
326 =head1 BUGS
327
328 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>.
329 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
330
331 =head1 SUPPORT
332
333 You can find documentation for this module with the perldoc command.
334
335     perldoc CPANPLUS::Dist::Gentoo
336
337 =head1 COPYRIGHT & LICENSE
338
339 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
340
341 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
342
343 =cut
344
345 1; # End of CPANPLUS::Dist::Gentoo::Maps
346
347 __DATA__
348 AcePerl                 Ace
349 CGI-Simple              Cgi-Simple
350 CGI-SpeedyCGI           SpeedyCGI
351 CPAN-Mini-Phalanx100    CPAN-Mini-Phalanx
352 Cache-Mmap              cache-mmap
353 Class-Loader            class-loader
354 Class-ReturnValue       class-returnvalue
355 Config-General          config-general
356 Convert-ASCII-Armour    convert-ascii-armour
357 Convert-PEM             convert-pem
358 Crypt-CBC               crypt-cbc
359 Crypt-DES_EDE3          crypt-des-ede3
360 Crypt-DH                crypt-dh
361 Crypt-DSA               crypt-dsa
362 Crypt-IDEA              crypt-idea
363 Crypt-Primes            crypt-primes
364 Crypt-RSA               crypt-rsa
365 Crypt-Random            crypt-random
366 DBIx-SearchBuilder      dbix-searchbuilder
367 Data-Buffer             data-buffer
368 Date-Manip              DateManip
369 Digest                  digest-base
370 Digest-BubbleBabble     digest-bubblebabble
371 Digest-MD2              digest-md2
372 ExtUtils-Depends        extutils-depends
373 ExtUtils-PkgConfig      extutils-pkgconfig
374 Frontier-RPC            frontier-rpc
375 Gimp                    gimp-perl
376 Glib                    glib-perl
377 Gnome2                  gnome2-perl
378 Gnome2-Canvas           gnome2-canvas
379 Gnome2-GConf            gnome2-gconf
380 Gnome2-VFS              gnome2-vfs-perl
381 Gnome2-Wnck             gnome2-wnck
382 Gtk2                    gtk2-perl
383 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
384 Gtk2-GladeXML           gtk2-gladexml
385 Gtk2-Spell              gtk2-spell
386 Gtk2-TrayIcon           gtk2-trayicon
387 Gtk2-TrayManager        gtk2-traymanager
388 Gtk2Fu                  gtk2-fu
389 I18N-LangTags           i18n-langtags
390 Image-Info              ImageInfo
391 Image-Size              ImageSize
392 Inline-Files            inline-files
393 Locale-Maketext         locale-maketext
394 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
395 Locale-Maketext-Lexicon locale-maketext-lexicon
396 Log-Dispatch            log-dispatch
397 Math-Pari               math-pari
398 Module-Info             module-info
399 MogileFS-Server         mogilefs-server
400 NTLM                    Authen-NTLM
401 Net-Ping                net-ping
402 Net-SFTP                net-sftp
403 Net-SSH-Perl            net-ssh-perl
404 Net-Server              net-server
405 OLE-Storage_Lite        OLE-StorageLite
406 Ogg-Vorbis-Header       ogg-vorbis-header
407 PathTools               File-Spec
408 Perl-Tidy               perltidy
409 Pod-Parser              PodParser
410 Regexp-Common           regexp-common
411 Set-Scalar              set-scalar
412 String-CRC32            string-crc32
413 Template-Plugin-Latex   Template-Latex
414 Text-Autoformat         text-autoformat
415 Text-Reform             text-reform
416 Text-Template           text-template
417 Text-Wrapper            text-wrapper
418 Tie-EncryptedHash       tie-encryptedhash
419 Time-Period             Period
420 Tk                      perl-tk
421 Wx                      wxperl
422 XML-Sablotron           XML-Sablot
423 YAML                    yaml
424 gettext                 Locale-gettext
425 txt2html                TextToHTML