]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Maps.pm
Update gentooisms
[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  Log-TraceMessages
253  MusicBrainz-DiscID
254  Net-IRC
255  Net-Ping
256  SDL
257  SOAP-WSDL
258  TeX-Encode
259  Tie-Simple
260  Time-Piece
261  WattsUp-Daemon
262 >;
263
264 $version_mismatch{$_} = $simple_and_correct_suffixes for qw<
265  Gimp
266  XML-Grove
267 >;
268
269 $version_mismatch{$_} = $simple_and_strip_letters for qw<
270  DelimMatch
271  SGMLSpm
272 >;
273
274 $version_mismatch{$_} = $simple_and_letters_as_suffix for qw<
275  Frontier-RPC
276 >;
277
278 sub version_c2g {
279  my ($n, $v) = @_;
280
281  return unless defined $v;
282
283  my $handler;
284  $handler = $version_mismatch{$n} if defined $n;
285  $handler = $default_mapping  unless defined $handler;
286
287  return $handler->($v);
288 }
289
290 =head2 C<perl_version_c2g $version>
291
292 Converts a perl version number as you can find it in CPAN prerequisites to a Gentoo version number.
293
294 =cut
295
296 sub perl_version_c2g {
297  my ($v) = @_;
298
299  return unless defined $v and $v =~ /^[0-9\.]+$/;
300
301  my @parts;
302  if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) {
303   my $len = length $subversion;
304   if (my $pad = $len % 3) {
305    $subversion .= '0' x (3 - $pad);
306   }
307   @parts = ($version, $subversion =~ /(.{1,3})/g);
308  } else {
309   @parts = split /\./, $v;
310  }
311
312  return join '.', map int, @parts;
313 }
314
315 =head1 SEE ALSO
316
317 L<CPANPLUS::Dist::Gentoo>.
318
319 =head1 AUTHOR
320
321 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
322
323 You can contact me by mail or on C<irc.perl.org> (vincent).
324
325 =head1 BUGS
326
327 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>.
328 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
329
330 =head1 SUPPORT
331
332 You can find documentation for this module with the perldoc command.
333
334     perldoc CPANPLUS::Dist::Gentoo
335
336 =head1 COPYRIGHT & LICENSE
337
338 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
339
340 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
341
342 =cut
343
344 1; # End of CPANPLUS::Dist::Gentoo::Maps
345
346 __DATA__
347 AcePerl                 Ace
348 CGI-Simple              Cgi-Simple
349 CGI-SpeedyCGI           SpeedyCGI
350 CPAN-Mini-Phalanx100    CPAN-Mini-Phalanx
351 Cache-Mmap              cache-mmap
352 Class-Loader            class-loader
353 Class-ReturnValue       class-returnvalue
354 Config-General          config-general
355 Convert-ASCII-Armour    convert-ascii-armour
356 Convert-PEM             convert-pem
357 Crypt-CBC               crypt-cbc
358 Crypt-DES_EDE3          crypt-des-ede3
359 Crypt-DH                crypt-dh
360 Crypt-DSA               crypt-dsa
361 Crypt-IDEA              crypt-idea
362 Crypt-Primes            crypt-primes
363 Crypt-RSA               crypt-rsa
364 Crypt-Random            crypt-random
365 DBIx-SearchBuilder      dbix-searchbuilder
366 Data-Buffer             data-buffer
367 Date-Manip              DateManip
368 Digest                  digest-base
369 Digest-BubbleBabble     digest-bubblebabble
370 Digest-MD2              digest-md2
371 ExtUtils-Depends        extutils-depends
372 ExtUtils-PkgConfig      extutils-pkgconfig
373 Frontier-RPC            frontier-rpc
374 Gimp                    gimp-perl
375 Glib                    glib-perl
376 Gnome2                  gnome2-perl
377 Gnome2-Canvas           gnome2-canvas
378 Gnome2-GConf            gnome2-gconf
379 Gnome2-VFS              gnome2-vfs-perl
380 Gnome2-Wnck             gnome2-wnck
381 Gtk2                    gtk2-perl
382 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
383 Gtk2-GladeXML           gtk2-gladexml
384 Gtk2-Spell              gtk2-spell
385 Gtk2-TrayIcon           gtk2-trayicon
386 Gtk2-TrayManager        gtk2-traymanager
387 Gtk2Fu                  gtk2-fu
388 I18N-LangTags           i18n-langtags
389 Image-Info              ImageInfo
390 Image-Size              ImageSize
391 Inline-Files            inline-files
392 Locale-Maketext         locale-maketext
393 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
394 Locale-Maketext-Lexicon locale-maketext-lexicon
395 Log-Dispatch            log-dispatch
396 Math-Pari               math-pari
397 Module-Info             module-info
398 MogileFS-Server         mogilefs-server
399 NTLM                    Authen-NTLM
400 Net-Ping                net-ping
401 Net-SFTP                net-sftp
402 Net-SSH-Perl            net-ssh-perl
403 Net-Server              net-server
404 OLE-Storage_Lite        OLE-StorageLite
405 Ogg-Vorbis-Header       ogg-vorbis-header
406 PathTools               File-Spec
407 Perl-Tidy               perltidy
408 Pod-Parser              PodParser
409 Regexp-Common           regexp-common
410 Set-Scalar              set-scalar
411 String-CRC32            string-crc32
412 Text-Autoformat         text-autoformat
413 Text-Reform             text-reform
414 Text-Template           text-template
415 Text-Wrapper            text-wrapper
416 Tie-EncryptedHash       tie-encryptedhash
417 Time-Period             Period
418 Tk                      perl-tk
419 Wx                      wxperl
420 XML-Sablotron           XML-Sablot
421 YAML                    yaml
422 gettext                 Locale-gettext
423 txt2html                TextToHTML