]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Maps.pm
Switch to <> for qw delimiters
[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
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.
80
81 =cut
82
83 my $default_mapping = sub {
84  my ($v) = @_;
85
86  $v =~ s/^v//;
87  $v =~ y/-/_/;
88
89  $v =~ s/^[._]*//;
90  $v =~ s/[._]*$//;
91  $v =~ s/([._])[._]*/$1/g;
92
93  ($v, my $patch) = split /_/, $v, 2;
94  if (defined $patch) {
95   $patch =~ s/_//g;
96   $v .= "_p$patch";
97  }
98
99  return $v;
100 };
101
102 my $insert_dot_at = sub {
103  my ($v, $pos, $all) = @_;
104
105  my ($int, $frac) = split /\./, $v, 2;
106  return $v unless defined $frac;
107
108  my @p;
109  push @p, $-[0] while $frac =~ /[0-9]/g;
110  my %digit = map { $_ => 1 } @p;
111
112  my $shift = 0;
113  for (my $i = $pos; $i < @p; $i += $pos) {
114   if ($digit{$i}) {
115    substr($frac, $i + $shift, 0) = '.';
116    ++$shift;
117   }
118   last unless $all;
119  }
120
121  "$int.$frac";
122 };
123
124 my $insert_dot_at_1     = sub { $insert_dot_at->($_[0], 1, 0) },
125 my $insert_dot_at_all_1 = sub { $insert_dot_at->($_[0], 1, 1) },
126 my $insert_dot_at_2     = sub { $insert_dot_at->($_[0], 2, 0) },
127 my $insert_dot_at_all_2 = sub { $insert_dot_at->($_[0], 2, 1) },
128 my $insert_dot_at_all_3 = sub { $insert_dot_at->($_[0], 3, 1) },
129
130 my $pad_decimals_to = sub {
131  my ($v, $n) = @_;
132
133  my ($int, $frac) = split /\./, $v, 2;
134  return $v unless defined $v;
135
136  my $l = length $frac;
137  if ($l < $n) {
138   $frac .= '0' x ($n - $l);
139  }
140
141  "$int.$frac";
142 };
143
144 my $pad_decimals_to_2 = sub { $pad_decimals_to->($_[0], 2) };
145 my $pad_decimals_to_4 = sub { $pad_decimals_to->($_[0], 4) };
146
147 my $correct_suffixes = sub {
148  my ($v) = @_;
149
150  $v = $default_mapping->($v);
151  $v =~ s/(?<!_)((?:alpha|beta|pre|rc|p)\d*)\b/_$1/g;
152
153  return $v;
154 };
155
156 my $strip_letters = sub {
157  my ($v) = @_;
158
159  $v = $default_mapping->($v);
160  $v =~ s/(?<=\d)[a-z]+//g;
161
162  return $v;
163 };
164
165 my $letters_as_suffix = sub {
166  my ($v) = @_;
167
168  $v = $default_mapping->($v);
169  $v =~ s/(?<=\d)b(?=\d)/_beta/g;
170
171  return $v;
172 };
173
174 my %version_mismatch;
175
176 $version_mismatch{$_} = $insert_dot_at_1 for qw<
177  CGI-Simple
178 >;
179
180 $version_mismatch{$_} = $insert_dot_at_all_1 for qw<
181  AnyEvent
182  Archive-Rar
183  IO-AIO
184  Image-Size
185  Linux-Inotify2
186  PadWalker
187  Tie-Array-Sorted
188  Tk-TableMatrix
189  XML-RSS-Feed
190 >;
191
192 $version_mismatch{$_} = $insert_dot_at_2 for qw<
193  Error
194 >;
195
196 $version_mismatch{$_} = $insert_dot_at_all_2 for qw<
197  Authen-Htpasswd
198  BSD-Resource
199  CDDB
200  Cairo
201  Curses-UI
202  DBD-mysql
203  Email-MessageID
204  Exception-Base
205  ExtUtils-CBuilder
206  ExtUtils-ParseXS
207  FileHandle-Unget
208  FreezeThaw
209  Lexical-Persistence
210  Lingua-EN-Inflect
211  Mail-Mbox-MessageParser
212  Module-Build
213  SQL-Abstract-Limit
214  Term-ReadLine-Perl
215  Test-Differences
216  Time-HiRes
217  Time-Local
218  perl-ldap
219 >;
220
221 $version_mismatch{$_} = $insert_dot_at_all_3 for qw<
222  Parse-RecDescent
223  Return-Value
224 >;
225
226 $version_mismatch{$_} = $pad_decimals_to_2 for qw<
227  Nmap-Parser
228  XML-AutoWriter
229 >;
230
231 $version_mismatch{$_} = $pad_decimals_to_4 for qw<
232  Convert-BER
233 >;
234
235 $version_mismatch{$_} = $correct_suffixes for qw<
236  Gimp
237  XML-Grove
238 >;
239
240 $version_mismatch{$_} = $strip_letters for qw<
241  DelimMatch
242  SGMLSpm
243 >;
244
245 $version_mismatch{$_} = $letters_as_suffix for qw<
246  Frontier-RPC
247 >;
248
249 sub version_c2g {
250  my ($n, $v) = @_;
251
252  return unless defined $v;
253
254  my $handler;
255  $handler = $version_mismatch{$n} if defined $n;
256  $handler = $default_mapping  unless defined $handler;
257
258  return $handler->($v);
259 }
260
261 =head2 C<perl_version_c2g $version>
262
263 Converts a perl version as you can find it in prerequisites to a Gentoo version number.
264
265 =cut
266
267 sub perl_version_c2g {
268  my ($v) = @_;
269
270  return unless defined $v and $v =~ /^[0-9\.]+$/;
271
272  my @parts;
273  if (my ($version, $subversion) = $v =~ /^([0-9]+)\.(0[^\.]+)$/) {
274   my $len = length $subversion;
275   if (my $pad = $len % 3) {
276    $subversion .= '0' x (3 - $pad);
277   }
278   @parts = ($version, $subversion =~ /(.{1,3})/g);
279  } else {
280   @parts = split /\./, $v;
281  }
282
283  return join '.', map int, @parts;
284 }
285
286 =head1 SEE ALSO
287
288 L<CPANPLUS::Dist::Gentoo>.
289
290 =head1 AUTHOR
291
292 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
293
294 You can contact me by mail or on C<irc.perl.org> (vincent).
295
296 =head1 BUGS
297
298 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>.
299 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
300
301 =head1 SUPPORT
302
303 You can find documentation for this module with the perldoc command.
304
305     perldoc CPANPLUS::Dist::Gentoo
306
307 =head1 COPYRIGHT & LICENSE
308
309 Copyright 2009,2010 Vincent Pit, all rights reserved.
310
311 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
312
313 =cut
314
315 1; # End of CPANPLUS::Dist::Gentoo::Maps
316
317 __DATA__
318 ANSIColor               Term-ANSIColor
319 AcePerl                 Ace
320 CGI-Simple              Cgi-Simple
321 CGI-SpeedyCGI           SpeedyCGI
322 CPAN-Mini-Phalanx100    CPAN-Mini-Phalanx
323 Cache-Mmap              cache-mmap
324 Class-Loader            class-loader
325 Class-ReturnValue       class-returnvalue
326 Config-General          config-general
327 Convert-ASCII-Armour    convert-ascii-armour
328 Convert-PEM             convert-pem
329 Crypt-CBC               crypt-cbc
330 Crypt-DES_EDE3          crypt-des-ede3
331 Crypt-DH                crypt-dh
332 Crypt-DSA               crypt-dsa
333 Crypt-IDEA              crypt-idea
334 Crypt-Primes            crypt-primes
335 Crypt-RSA               crypt-rsa
336 Crypt-Random            crypt-random
337 DBIx-SearchBuilder      dbix-searchbuilder
338 Data-Buffer             data-buffer
339 Date-Manip              DateManip
340 Digest                  digest-base
341 Digest-BubbleBabble     digest-bubblebabble
342 Digest-MD2              digest-md2
343 ExtUtils-Depends        extutils-depends
344 ExtUtils-PkgConfig      extutils-pkgconfig
345 Frontier-RPC            frontier-rpc
346 Gimp                    gimp-perl
347 Glib                    glib-perl
348 Gnome2                  gnome2-perl
349 Gnome2-Canvas           gnome2-canvas
350 Gnome2-GConf            gnome2-gconf
351 Gnome2-Print            gnome2-print
352 Gnome2-VFS              gnome2-vfs-perl
353 Gnome2-Wnck             gnome2-wnck
354 Gtk2                    gtk2-perl
355 Gtk2-Ex-FormFactory     gtk2-ex-formfactory
356 Gtk2-GladeXML           gtk2-gladexml
357 Gtk2-Spell              gtk2-spell
358 Gtk2-TrayIcon           gtk2-trayicon
359 Gtk2-TrayManager        gtk2-traymanager
360 Gtk2Fu                  gtk2-fu
361 I18N-LangTags           i18n-langtags
362 Image-Info              ImageInfo
363 Image-Size              ImageSize
364 Inline-Files            inline-files
365 Locale-Maketext         locale-maketext
366 Locale-Maketext-Fuzzy   locale-maketext-fuzzy
367 Locale-Maketext-Lexicon locale-maketext-lexicon
368 Log-Dispatch            log-dispatch
369 Math-Pari               math-pari
370 Module-Info             module-info
371 MogileFS-Server         mogilefs-server
372 NTLM                    Authen-NTLM
373 Net-Ping                net-ping
374 Net-SFTP                net-sftp
375 Net-SSH-Perl            net-ssh-perl
376 Net-Server              net-server
377 OLE-Storage_Lite        OLE-StorageLite
378 Ogg-Vorbis-Header       ogg-vorbis-header
379 PathTools               File-Spec
380 Perl-Tidy               perltidy
381 Pod-Parser              PodParser
382 Regexp-Common           regexp-common
383 SDL_Perl                sdl-perl
384 Set-Scalar              set-scalar
385 String-CRC32            string-crc32
386 Text-Autoformat         text-autoformat
387 Text-Reform             text-reform
388 Text-Template           text-template
389 Text-Wrapper            text-wrapper
390 Tie-EncryptedHash       tie-encryptedhash
391 Tk                      perl-tk
392 Wx                      wxperl
393 XML-Sablotron           XML-Sablot
394 YAML                    yaml
395 gettext                 Locale-gettext
396 txt2html                TextToHTML