]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Maps.pm
b9b96119745a2bcd698ae1ec8813f09701ce8acb
[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  Exception-Base
201  ExtUtils-CBuilder
202  ExtUtils-ParseXS
203  FileHandle-Unget
204  FreezeThaw
205  Lexical-Persistence
206  Lingua-EN-Inflect
207  Mail-Mbox-MessageParser
208  Module-Build
209  SQL-Abstract-Limit
210  Term-ReadLine-Perl
211  Test-Differences
212  Time-HiRes
213  Time-Local
214  perl-ldap
215 /;
216
217 $version_mismatch{$_} = $insert_dot_at_all_3 for qw/
218  Parse-RecDescent
219  Return-Value
220 /;
221
222 $version_mismatch{$_} = $pad_decimals_to_2 for qw/
223  Nmap-Parser
224  XML-AutoWriter
225 /;
226
227 $version_mismatch{$_} = $pad_decimals_to_4 for qw/
228  Convert-BER
229 /;
230
231 $version_mismatch{$_} = $correct_suffixes for qw/
232  Gimp
233  XML-Grove
234 /;
235
236 $version_mismatch{$_} = $strip_letters for qw/
237  DelimMatch
238  SGMLSpm
239 /;
240
241 $version_mismatch{$_} = $letters_as_suffix for qw/
242  Frontier-RPC
243 /;
244
245 sub version_c2g {
246  my ($n, $v) = @_;
247
248  return unless defined $v;
249
250  my $handler;
251  $handler = $version_mismatch{$n} if defined $n;
252  $handler = $default_mapping  unless defined $handler;
253
254  return $handler->($v);
255 }
256
257 =head2 C<perl_version_c2g $version>
258
259 Converts a perl version as you can find it in prerequisites to a Gentoo version number.
260
261 =cut
262
263 sub perl_version_c2g {
264  my ($v) = @_;
265
266  return unless defined $v and $v =~ /^[0-9\.]+$/;
267
268  my @parts;
269  if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) {
270   my $len = length $subversion;
271   if (my $pad = $len % 3) {
272    $subversion .= '0' x (3 - $pad);
273   }
274   @parts = ($version, $subversion =~ /(.{1,3})/g);
275  } else {
276   @parts = split /\./, $v;
277  }
278
279  return join '.', map int, @parts;
280 }
281
282 =head1 SEE ALSO
283
284 L<CPANPLUS::Dist::Gentoo>.
285
286 =head1 AUTHOR
287
288 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
289
290 You can contact me by mail or on C<irc.perl.org> (vincent).
291
292 =head1 BUGS
293
294 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>.
295 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
296
297 =head1 SUPPORT
298
299 You can find documentation for this module with the perldoc command.
300
301     perldoc CPANPLUS::Dist::Gentoo
302
303 =head1 COPYRIGHT & LICENSE
304
305 Copyright 2009,2010 Vincent Pit, all rights reserved.
306
307 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
308
309 =cut
310
311 1; # End of CPANPLUS::Dist::Gentoo::Maps
312
313 __DATA__
314 ANSIColor               Term-ANSIColor
315 AcePerl                 Ace
316 CGI-Simple              Cgi-Simple
317 CGI-SpeedyCGI           SpeedyCGI
318 CPAN-Mini-Phalanx100    CPAN-Mini-Phalanx
319 Cache-Mmap              cache-mmap
320 Class-Loader            class-loader
321 Class-ReturnValue       class-returnvalue
322 Config-General          config-general
323 Convert-ASCII-Armour    convert-ascii-armour
324 Convert-PEM             convert-pem
325 Crypt-CBC               crypt-cbc
326 Crypt-DES_EDE3          crypt-des-ede3
327 Crypt-DH                crypt-dh
328 Crypt-DSA               crypt-dsa
329 Crypt-IDEA              crypt-idea
330 Crypt-Primes            crypt-primes
331 Crypt-RSA               crypt-rsa
332 Crypt-Random            crypt-random
333 DBIx-SearchBuilder      dbix-searchbuilder
334 Data-Buffer             data-buffer
335 Date-Manip              DateManip
336 Digest                  digest-base
337 Digest-BubbleBabble     digest-bubblebabble
338 Digest-MD2              digest-md2
339 ExtUtils-Depends        extutils-depends
340 ExtUtils-PkgConfig      extutils-pkgconfig
341 Frontier-RPC            frontier-rpc
342 Gimp                    gimp-perl
343 Glib                    glib-perl
344 Gnome2                  gnome2-perl
345 Gnome2-Canvas           gnome2-canvas
346 Gnome2-GConf            gnome2-gconf
347 Gnome2-Print            gnome2-print
348 Gnome2-VFS              gnome2-vfs-perl
349 Gnome2-Wnck             gnome2-wnck
350 Gtk2                    gtk2-perl
351 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
352 Gtk2-GladeXML           gtk2-gladexml
353 Gtk2-Spell              gtk2-spell
354 Gtk2-TrayIcon           gtk2-trayicon
355 Gtk2-TrayManager        gtk2-traymanager
356 Gtk2Fu                  gtk2-fu
357 I18N-LangTags           i18n-langtags
358 Image-Info              ImageInfo
359 Image-Size              ImageSize
360 Inline-Files            inline-files
361 Locale-Maketext         locale-maketext
362 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
363 Locale-Maketext-Lexicon locale-maketext-lexicon
364 Log-Dispatch            log-dispatch
365 Math-Pari               math-pari
366 Module-Info             module-info
367 MogileFS-Server         mogilefs-server
368 NTLM                    Authen-NTLM
369 Net-Ping                net-ping
370 Net-SFTP                net-sftp
371 Net-SSH-Perl            net-ssh-perl
372 Net-Server              net-server
373 OLE-Storage_Lite        OLE-StorageLite
374 Ogg-Vorbis-Header       ogg-vorbis-header
375 PathTools               File-Spec
376 Perl-Tidy               perltidy
377 Pod-Parser              PodParser
378 Regexp-Common           regexp-common
379 SDL_Perl                sdl-perl
380 Set-Scalar              set-scalar
381 String-CRC32            string-crc32
382 Text-Autoformat         text-autoformat
383 Text-Reform             text-reform
384 Text-Template           text-template
385 Text-Wrapper            text-wrapper
386 Tie-EncryptedHash       tie-encryptedhash
387 Tk                      perl-tk
388 Wx                      wxperl
389 XML-Sablotron           XML-Sablot
390 YAML                    yaml
391 gettext                 Locale-gettext
392 txt2html                TextToHTML