]> 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 use File::Spec;
7 use POSIX ();
8
9 =head1 NAME
10
11 CPANPLUS::Dist::Gentoo::Maps - Map CPAN distribution names, version numbers and license identifiers to their Gentoo counterparts.
12
13 =head1 VERSION
14
15 Version 0.12
16
17 =cut
18
19 our $VERSION = '0.12';
20
21 =head1 DESCRIPTION
22
23 This is an helper package to L<CPANPLUS::Dist::Gentoo>.
24
25 =cut
26
27 my %name_mismatch;
28
29 /^\s*([\w-]+)\s+([\w-]+)\s*$/ and $name_mismatch{$1} = $2 while <DATA>;
30
31 close DATA;
32
33 =head1 FUNCTIONS
34
35 =head2 C<name_c2g $name>
36
37 Maps a CPAN distribution name to the corresponding Gentoo package name.
38
39 =cut
40
41 sub name_c2g {
42  my ($name) = @_;
43  return $name_mismatch{$name} || $name;
44 }
45
46 =head2 C<license_c2g @licenses>
47
48 Maps F<META.yml> C<license> tag values to the corresponding list of Gentoo license identifiers.
49 Duplicates are stripped off.
50
51 The included data was gathered from L<Module::Install> and L<Software::License>.
52
53 =cut
54
55 my %licenses = (
56  apache     => [ 'Apache-2.0' ],
57  artistic   => [ 'Artistic' ],
58  artistic_2 => [ 'Artistic-2' ],
59  bsd        => [ 'BSD' ],
60  gpl        => [ 'GPL-1' ],
61  gpl2       => [ 'GPL-2' ],
62  gpl3       => [ 'GPL-3' ],
63  lgpl       => [ 'LGPL-2.1' ],
64  lgpl2      => [ 'LGPL-2.1' ],
65  lgpl3      => [ 'LGPL-3' ],
66  mit        => [ 'MIT' ],
67  mozilla    => [ 'MPL-1.1' ],
68  perl       => [ 'Artistic', 'GPL-2' ],
69 );
70
71 sub license_c2g {
72  my %seen;
73
74  grep !$seen{$_}++,
75   map @{$licenses{+lc} || []},
76    grep defined,
77     @_;
78 }
79
80 =head2 C<version_c2g $name, $version>
81
82 Converts the C<$version> of a CPAN distribution C<$name> to a Gentoo version number.
83
84 =cut
85
86 my $default_mapping = sub {
87  my ($version, @no_strip) = @_;
88
89  my $is_dev = $version =~ /_/;
90  my $has_v  = $version =~ s/^v//;
91
92  for ($version) {
93   y/_-//d;
94   s/^\.*//;
95   s/\.*\z//;
96   s/\.+/./g;
97  }
98
99  my $dots   = $version =~ y/\.//;
100
101  my @parts;
102  if ($has_v or $dots >= 2) {
103   @parts = split /\./, $version;
104  } else {
105   ($parts[0], my $subversion) = split /\./, $version, 2;
106   $subversion = '0' unless defined $subversion;
107   my $sublen = length $subversion;
108   if ($sublen < 6) {
109    $subversion .= '0' x (6 - $sublen);
110   } else {
111    my $pad = $sublen % 3;
112    $subversion .= '0' x (3 - $pad) if $pad;
113   }
114   push @parts, $subversion =~ /(...)/g;
115  }
116
117  for my $i (0 .. $#parts) {
118   next if $no_strip[$i];
119   $parts[$i] =~ s/^0+([^0]|0\z)/$1/;
120  }
121  $version  = join '.', @parts;
122
123  $version .= '_rc' if $is_dev;
124
125  return $version;
126 };
127
128 my $default_but_ignore_v = sub {
129  my ($version) = @_;
130
131  $version =~ s/^v//;
132
133  return $default_mapping->($version);
134 };
135
136 my $default_but_no_strip_1 = sub {
137  return $default_mapping->($_[0], 0, 1);
138 };
139
140 my $default_but_no_strip_2 = sub {
141  return $default_mapping->($_[0], 0, 1, 1);
142 };
143
144 my $insert_dot_every = sub {
145  my ($version, $step) = @_;
146
147  my $is_dev = $version =~ /_/;
148
149  for ($version) {
150   s/^v//;
151   y/_-//d;
152   s/^\.*//;
153   s/\.*\z//;
154   s/\.+/./g;
155  }
156
157  my @parts;
158  ($parts[0], my $subversion) = split /\./, $version, 2;
159  $subversion =~ s/\.//g;
160  my $pat = sprintf '.{1,%d}', $step || 1;
161  push @parts, $subversion =~ /($pat)/g;
162
163  s/^0+([^0]|0\z)/$1/ for @parts;
164  $version = join '.', @parts;
165
166  $version .= '_rc' if $is_dev;
167
168  return $version;
169 };
170
171 my $simple_cleanup = sub {
172  my ($version) = @_;
173
174  my $is_dev = $version =~ /_/;
175
176  for ($version) {
177   s/^v//;
178   y/_-//d;
179   s/^\.*//;
180   s/\.*\z//;
181   s/\.+/./g;
182  }
183
184  $version .= '_rc' if $is_dev;
185
186  return $version;
187 };
188
189 my $simple_and_correct_suffixes = sub {
190  my ($version) = @_;
191
192  $version = $simple_cleanup->($version);
193  $version =~ s/(?<!_)((?:alpha|beta|pre|rc|p)\d*)\b/_$1/g;
194
195  return $version;
196 };
197
198 my $simple_and_strip_letters = sub {
199  my ($version) = @_;
200
201  $version = $simple_cleanup->($version);
202  $version =~ s/(?<=\d)[a-z]+//g;
203
204  return $version;
205 };
206
207 my $simple_and_letters_as_suffix = sub {
208  my ($version) = @_;
209
210  $version = $simple_cleanup->($version);
211  $version =~ s/(?<=\d)b(?=\d)/_beta/g;
212
213  return $version;
214 };
215
216 my %version_mismatch;
217
218 $version_mismatch{$_} = $default_but_ignore_v for qw<
219  Net-DNS-Resolver-Programmable
220 >;
221
222 $version_mismatch{$_} = $default_but_no_strip_1 for qw<
223  Crypt-RC4
224  File-Grep
225  MogileFS-Client-Async
226  MogileFS-Network
227 >;
228
229 $version_mismatch{$_} = $default_but_no_strip_2 for qw<
230  Net-IMAP-Simple
231 >;
232
233 $version_mismatch{$_} = sub { $insert_dot_every->($_[0], 1) } for qw<
234  HTTP-Cookies
235  HTTP-Negotiate
236 >;
237
238 $version_mismatch{$_} = sub { $insert_dot_every->($_[0], 3) } for qw<
239  POE-Component-IKC
240 >;
241
242 $version_mismatch{$_} = $simple_cleanup for qw<
243  Alien-SDL
244  CGI-SpeedyCGI
245  Class-ISA
246  Data-Uniqid
247  ExtUtils-Install
248  File-Path
249  Getopt-GUI-Long
250  Gtk2-Notify
251  HTML-Table
252  I18N-LangTags
253  IO
254  IPC-System-Simple
255  Lab-Measurement
256  Log-TraceMessages
257  MusicBrainz-DiscID
258  Net-IRC
259  Net-Ping
260  SDL
261  SOAP-WSDL
262  TeX-Encode
263  Tie-Simple
264  Time-Piece
265  WattsUp-Daemon
266 >;
267
268 $version_mismatch{$_} = $simple_and_correct_suffixes for qw<
269  Gimp
270  XML-Grove
271 >;
272
273 $version_mismatch{$_} = $simple_and_strip_letters for qw<
274  DelimMatch
275  SGMLSpm
276 >;
277
278 $version_mismatch{$_} = $simple_and_letters_as_suffix for qw<
279  Frontier-RPC
280 >;
281
282 sub version_c2g {
283  my ($n, $v) = @_;
284
285  return unless defined $v;
286
287  my $handler;
288  $handler = $version_mismatch{$n} if defined $n;
289  $handler = $default_mapping  unless defined $handler;
290
291  return $handler->($v);
292 }
293
294 =head2 C<perl_version_c2g $version>
295
296 Converts a perl version number as you can find it in CPAN prerequisites to a Gentoo version number.
297
298 =cut
299
300 sub perl_version_c2g {
301  my ($v) = @_;
302
303  return unless defined $v and $v =~ /^[0-9\.]+$/;
304
305  my @parts;
306  if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) {
307   my $len = length $subversion;
308   if (my $pad = $len % 3) {
309    $subversion .= '0' x (3 - $pad);
310   }
311   @parts = ($version, $subversion =~ /(.{1,3})/g);
312  } else {
313   @parts = split /\./, $v;
314  }
315
316  return join '.', map int, @parts;
317 }
318
319 =head2 C<get_portage_timestamp $portage>
320
321 Get the numerical timestamp associated with the portage tree located at C<$portage>.
322 Requires L<POSIX::strptime>, and returns C<undef> if it is not available.
323
324 =cut
325
326 sub get_portage_timestamp {
327  my ($portage) = @_;
328
329  {
330   local $@;
331   eval { require POSIX::strptime } or return;
332  }
333
334  my $file = File::Spec->catfile($portage, 'metadata', 'timestamp.chk');
335  return unless -e $file;
336
337  my $timestamp = do {
338   open my $fh, '<', $file or return;
339   local $/;
340   <$fh>;
341  };
342  s/^\s*//, s/\s*$// for $timestamp;
343
344  my $shift = 0;
345  if ($timestamp =~ s/\s+([+-])([0-9]{2})([0-9]{2})$//) {
346   $shift = ($2 * 60 + $3) * 60;
347   $shift = -$shift if $1 eq '-';
348  }
349
350  my $old_lc_all = POSIX::setlocale(POSIX::LC_ALL());
351  POSIX::setlocale(POSIX::LC_ALL(), 'C');
352  $timestamp = POSIX::mktime(
353   POSIX::strptime($timestamp, '%a, %d %b %Y %H:%M:%S')
354  );
355  POSIX::setlocale(POSIX::LC_ALL(), $old_lc_all);
356  $timestamp += $shift;
357
358  return $timestamp;
359 }
360
361 =head2 C<TIMESTAMP>
362
363 Numerical timestamp associated with the revision of the portage tree that was used for generating the corrections to the natural cpan-to-gentoo mapping listed in this module.
364
365 =cut
366
367 sub TIMESTAMP () { 1343034901 }
368
369 =head1 SEE ALSO
370
371 L<CPANPLUS::Dist::Gentoo>.
372
373 =head1 AUTHOR
374
375 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
376
377 You can contact me by mail or on C<irc.perl.org> (vincent).
378
379 =head1 BUGS
380
381 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>.
382 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
383
384 =head1 SUPPORT
385
386 You can find documentation for this module with the perldoc command.
387
388     perldoc CPANPLUS::Dist::Gentoo
389
390 =head1 COPYRIGHT & LICENSE
391
392 Copyright 2009,2010,2011,2012 Vincent Pit, all rights reserved.
393
394 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
395
396 =cut
397
398 1; # End of CPANPLUS::Dist::Gentoo::Maps
399
400 __DATA__
401 AcePerl                 Ace
402 CGI-Simple              Cgi-Simple
403 CGI-SpeedyCGI           SpeedyCGI
404 Cache-Mmap              cache-mmap
405 Class-Loader            class-loader
406 Class-ReturnValue       class-returnvalue
407 Config-General          config-general
408 Convert-ASCII-Armour    convert-ascii-armour
409 Convert-PEM             convert-pem
410 Crypt-CBC               crypt-cbc
411 Crypt-DES_EDE3          crypt-des-ede3
412 Crypt-DH                crypt-dh
413 Crypt-DSA               crypt-dsa
414 Crypt-IDEA              crypt-idea
415 Crypt-Primes            crypt-primes
416 Crypt-RSA               crypt-rsa
417 Crypt-Random            crypt-random
418 DBIx-SearchBuilder      dbix-searchbuilder
419 Data-Buffer             data-buffer
420 Date-Manip              DateManip
421 Digest                  digest-base
422 Digest-BubbleBabble     digest-bubblebabble
423 Digest-MD2              digest-md2
424 ExtUtils-Depends        extutils-depends
425 ExtUtils-PkgConfig      extutils-pkgconfig
426 Frontier-RPC            frontier-rpc
427 Glib                    glib-perl
428 Gnome2                  gnome2-perl
429 Gnome2-Canvas           gnome2-canvas
430 Gnome2-GConf            gnome2-gconf
431 Gnome2-VFS              gnome2-vfs-perl
432 Gnome2-Wnck             gnome2-wnck
433 Gtk2                    gtk2-perl
434 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
435 Gtk2-GladeXML           gtk2-gladexml
436 Gtk2-Spell              gtk2-spell
437 Gtk2-TrayIcon           gtk2-trayicon
438 Gtk2-TrayManager        gtk2-traymanager
439 Gtk2Fu                  gtk2-fu
440 I18N-LangTags           i18n-langtags
441 Image-Info              ImageInfo
442 Image-Size              ImageSize
443 Inline-Files            inline-files
444 Locale-Maketext         locale-maketext
445 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
446 Locale-Maketext-Lexicon locale-maketext-lexicon
447 Log-Dispatch            log-dispatch
448 Math-Pari               math-pari
449 Module-Info             module-info
450 MogileFS-Server         mogilefs-server
451 NTLM                    Authen-NTLM
452 Net-Ping                net-ping
453 Net-SFTP                net-sftp
454 Net-SSH-Perl            net-ssh-perl
455 Net-Server              net-server
456 OLE-Storage_Lite        OLE-StorageLite
457 Ogg-Vorbis-Header       ogg-vorbis-header
458 PathTools               File-Spec
459 Perl-Tidy               perltidy
460 Pod-Parser              PodParser
461 Regexp-Common           regexp-common
462 Set-Scalar              set-scalar
463 String-CRC32            string-crc32
464 Template-Plugin-Latex   Template-Latex
465 Text-Autoformat         text-autoformat
466 Text-Reform             text-reform
467 Text-Template           text-template
468 Text-Wrapper            text-wrapper
469 Tie-EncryptedHash       tie-encryptedhash
470 Time-Period             Period
471 Tk                      perl-tk
472 Wx                      wxperl
473 YAML                    yaml
474 gettext                 Locale-gettext
475 txt2html                TextToHTML