]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Maps.pm
84ede042cb457ff12c42ed3572e594c42020b7d8
[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, $strip) = @_;
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  if ($strip) {
164   s/^0+([^0]|0\z)/$1/ for @parts;
165  }
166  $version = join '.', @parts;
167
168  $version .= '_rc' if $is_dev;
169
170  return $version;
171 };
172
173 my $simple_cleanup = sub {
174  my ($version) = @_;
175
176  my $is_dev = $version =~ /_/;
177
178  for ($version) {
179   s/^v//;
180   y/_-//d;
181   s/^\.*//;
182   s/\.*\z//;
183   s/\.+/./g;
184  }
185
186  $version .= '_rc' if $is_dev;
187
188  return $version;
189 };
190
191 my $simple_and_correct_suffixes = sub {
192  my ($version) = @_;
193
194  $version = $simple_cleanup->($version);
195  $version =~ s/(?<!_)((?:alpha|beta|pre|rc|p)\d*)\b/_$1/g;
196
197  return $version;
198 };
199
200 my $simple_and_strip_letters = sub {
201  my ($version) = @_;
202
203  $version = $simple_cleanup->($version);
204  $version =~ s/(?<=\d)[a-z]+//g;
205
206  return $version;
207 };
208
209 my $simple_and_letters_as_suffix = sub {
210  my ($version) = @_;
211
212  $version = $simple_cleanup->($version);
213  $version =~ s/(?<=\d)b(?=\d)/_beta/g;
214
215  return $version;
216 };
217
218 my %version_mismatch;
219
220 $version_mismatch{$_} = $default_but_ignore_v for qw<
221  Net-DNS-Resolver-Programmable
222 >;
223
224 $version_mismatch{$_} = $default_but_no_strip_1 for qw<
225  Crypt-RC4
226  FLV-AudioExtractor
227  File-Grep
228  MogileFS-Client-Async
229  MogileFS-Network
230  Test-Command-Simple
231  Unix-Getrusage
232 >;
233
234 $version_mismatch{$_} = sub { $insert_dot_every->($_[0], 1) } for qw<
235  HTTP-Cookies
236  HTTP-Negotiate
237 >;
238
239 $version_mismatch{$_} = sub { $insert_dot_every->($_[0], 3) } for qw<
240  Data-Diver
241 >;
242
243 $version_mismatch{$_} = $simple_cleanup for qw<
244  CGI-SpeedyCGI
245  Class-ISA
246  CryptX
247  Data-HexDump
248  Gtk2-Notify
249  HTML-Table
250  I18N-LangTags
251  IO
252  IPC-System-Simple
253  Lab-Measurement
254  Net-Ping
255  REST-Client
256  SDL
257  SOAP-WSDL
258  TAP-Parser-SourceHandler-pgTAP
259  TeX-Encode
260  Tie-Simple
261  Time-Piece
262  WattsUp-Daemon
263 >;
264
265 $version_mismatch{$_} = $simple_and_correct_suffixes for qw<
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 =head2 C<get_portage_timestamp $portage>
316
317 Get the numerical timestamp associated with the portage tree located at C<$portage>.
318 Requires L<POSIX::strptime>, and returns C<undef> if it is not available.
319
320 =cut
321
322 sub get_portage_timestamp {
323  my ($portage) = @_;
324
325  {
326   local $@;
327   eval { require POSIX::strptime } or return;
328  }
329
330  my $file = File::Spec->catfile($portage, 'metadata', 'timestamp.chk');
331  return unless -e $file;
332
333  my $timestamp = do {
334   open my $fh, '<', $file or return;
335   local $/;
336   <$fh>;
337  };
338  s/^\s*//, s/\s*$// for $timestamp;
339
340  my $shift = 0;
341  if ($timestamp =~ s/\s+([+-])([0-9]{2})([0-9]{2})$//) {
342   $shift = ($2 * 60 + $3) * 60;
343   $shift = -$shift if $1 eq '-';
344  }
345
346  my $old_lc_all = POSIX::setlocale(POSIX::LC_ALL());
347  POSIX::setlocale(POSIX::LC_ALL(), 'C');
348  $timestamp = POSIX::mktime(
349   POSIX::strptime($timestamp, '%a, %d %b %Y %H:%M:%S')
350  );
351  POSIX::setlocale(POSIX::LC_ALL(), $old_lc_all);
352  $timestamp += $shift;
353
354  return $timestamp;
355 }
356
357 =head2 C<TIMESTAMP>
358
359 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.
360
361 =cut
362
363 sub TIMESTAMP () { 1367759701 }
364
365 =head1 SEE ALSO
366
367 L<CPANPLUS::Dist::Gentoo>.
368
369 =head1 AUTHOR
370
371 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
372
373 You can contact me by mail or on C<irc.perl.org> (vincent).
374
375 =head1 BUGS
376
377 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>.
378 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
379
380 =head1 SUPPORT
381
382 You can find documentation for this module with the perldoc command.
383
384     perldoc CPANPLUS::Dist::Gentoo
385
386 =head1 COPYRIGHT & LICENSE
387
388 Copyright 2009,2010,2011,2012 Vincent Pit, all rights reserved.
389
390 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
391
392 =cut
393
394 1; # End of CPANPLUS::Dist::Gentoo::Maps
395
396 __DATA__
397 AcePerl                 Ace
398 CGI-Simple              Cgi-Simple
399 CGI-SpeedyCGI           SpeedyCGI
400 Cache-Mmap              cache-mmap
401 Class-Loader            class-loader
402 Class-ReturnValue       class-returnvalue
403 Config-General          config-general
404 Convert-ASCII-Armour    convert-ascii-armour
405 Convert-PEM             convert-pem
406 Crypt-CBC               crypt-cbc
407 Crypt-DES_EDE3          crypt-des-ede3
408 Crypt-DH                crypt-dh
409 Crypt-DSA               crypt-dsa
410 Crypt-IDEA              crypt-idea
411 Crypt-Primes            crypt-primes
412 Crypt-RSA               crypt-rsa
413 Crypt-Random            crypt-random
414 DBIx-SearchBuilder      dbix-searchbuilder
415 Data-Buffer             data-buffer
416 Date-Manip              DateManip
417 Digest                  digest-base
418 Digest-BubbleBabble     digest-bubblebabble
419 Digest-MD2              digest-md2
420 ExtUtils-Depends        extutils-depends
421 ExtUtils-PkgConfig      extutils-pkgconfig
422 Frontier-RPC            frontier-rpc
423 Glib                    glib-perl
424 Gnome2                  gnome2-perl
425 Gnome2-Canvas           gnome2-canvas
426 Gnome2-GConf            gnome2-gconf
427 Gnome2-VFS              gnome2-vfs-perl
428 Gnome2-Wnck             gnome2-wnck
429 Gtk2                    gtk2-perl
430 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
431 Gtk2-GladeXML           gtk2-gladexml
432 Gtk2-Spell              gtk2-spell
433 Gtk2-TrayIcon           gtk2-trayicon
434 Gtk2-TrayManager        gtk2-traymanager
435 Gtk2Fu                  gtk2-fu
436 I18N-LangTags           i18n-langtags
437 Image-Info              ImageInfo
438 Image-Size              ImageSize
439 Inline-Files            inline-files
440 Locale-Maketext         locale-maketext
441 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
442 Locale-Maketext-Lexicon locale-maketext-lexicon
443 Log-Dispatch            log-dispatch
444 Math-Pari               math-pari
445 Module-Info             module-info
446 MogileFS-Server         mogilefs-server
447 NTLM                    Authen-NTLM
448 Net-Ping                net-ping
449 Net-SFTP                net-sftp
450 Net-SSH-Perl            net-ssh-perl
451 Net-Server              net-server
452 OLE-Storage_Lite        OLE-StorageLite
453 Ogg-Vorbis-Header       ogg-vorbis-header
454 PathTools               File-Spec
455 Perl-Tidy               perltidy
456 Pod-Parser              PodParser
457 Regexp-Common           regexp-common
458 Set-Scalar              set-scalar
459 String-CRC32            string-crc32
460 Template-Plugin-Latex   Template-Latex
461 Text-Autoformat         text-autoformat
462 Text-Reform             text-reform
463 Text-Template           text-template
464 Text-Wrapper            text-wrapper
465 Tie-EncryptedHash       tie-encryptedhash
466 Time-Period             Period
467 Tk                      perl-tk
468 Wx                      wxperl
469 YAML                    yaml
470 gettext                 Locale-gettext
471 txt2html                TextToHTML