From: Vincent Pit Date: Sun, 16 Aug 2009 19:01:44 +0000 (+0200) Subject: Intuit the correct license from the DSLIP or the META file X-Git-Tag: v0.08~10 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=69b45a423d8ce50cc9c3cc8cb22a8822e698fb4f Intuit the correct license from the DSLIP or the META file --- diff --git a/MANIFEST b/MANIFEST index 7e6be1b..64b73d6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,6 +10,7 @@ samples/gengentooisms t/00-load.t t/11-maps-name.t t/12-maps-version.t +t/13-maps-license.t t/91-pod.t t/92-pod-coverage.t t/95-portability-files.t diff --git a/Makefile.PL b/Makefile.PL index 1803ce3..9cb62fc 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -30,14 +30,15 @@ WriteMakefile( ABSTRACT_FROM => 'lib/CPANPLUS/Dist/Gentoo.pm', PL_FILES => {}, PREREQ_PM => { - 'Carp' => 0, - 'CPANPLUS' => 0, - 'Cwd' => 0, - 'File::Copy' => 0, - 'File::Path' => 0, - 'File::Spec' => 0, - 'IPC::Cmd' => 0, - 'base' => 0, + 'Carp' => 0, + 'CPANPLUS' => 0, + 'Cwd' => 0, + 'File::Copy' => 0, + 'File::Path' => 0, + 'File::Spec' => 0, + 'IPC::Cmd' => 0, + 'Parse::CPAN::Meta' => 0, + 'base' => 0, }, MIN_PERL_VERSION => 5.006, META_MERGE => \%META, diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 243253e..51f23d1 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -9,6 +9,7 @@ use File::Path (); use File::Spec; use IPC::Cmd qw/run can_run/; +use Parse::CPAN::Meta (); use CPANPLUS::Error (); @@ -264,7 +265,7 @@ sub prepare { $stat->src("mirror://cpan/modules/by-authors/id/$1/$1$2/$author/" . $mod->package); - $stat->license([ qw/Artistic GPL-2/ ]); + $stat->license($self->intuit_license); my $prereqs = $mod->status->prereqs; my @depends; @@ -290,6 +291,49 @@ sub prepare { return $OK->(); } +=head2 C + +Returns an array reference to a list of Gentoo licences identifiers under which the current distribution is released. + +=cut + +my %dslip_license = ( + p => 'perl', + g => 'gpl', + l => 'lgpl', + b => 'bsd', + a => 'artistic', + 2 => 'artistic_2', +); + +sub intuit_license { + my $self = shift; + my $mod = $self->parent; + + my $dslip = $mod->dslip; + if (defined $dslip and $dslip =~ /\S{4}(\S)/) { + my @licenses = CPANPLUS::Dist::Gentoo::Maps::license_c2g($dslip_license{$1}); + return \@licenses if @licenses; + } + my $extract_dir = $mod->status->extract; + + for my $meta_file (qw/META.json META.yml/) { + my $meta = eval { + Parse::CPAN::Meta::LoadFile(File::Spec->catdir( + $extract_dir, + $meta_file, + )); + } or next; + my $license = $meta->{license}; + if (defined $license) { + my @licenses = CPANPLUS::Dist::Gentoo::Maps::license_c2g($license); + return \@licenses if @licenses; + } + } + + return [ CPANPLUS::Dist::Gentoo::Maps::license_c2g('perl') ]; +} + sub create { my $self = shift; my $stat = $self->status; @@ -508,7 +552,7 @@ sub _skip { shift->_notify(@_, '-- skipping') } Gentoo (L). -L, L (core modules since 5.9.5). +L, L (core modules since 5.9.5), L (since 5.10.1). L, L (since perl 5), L (5.001), L (5.002), L (5.00405). diff --git a/lib/CPANPLUS/Dist/Gentoo/Maps.pm b/lib/CPANPLUS/Dist/Gentoo/Maps.pm index 94d2e16..5ce9f7a 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Maps.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Maps.pm @@ -40,6 +40,36 @@ sub name_c2g { return $gentooisms{$name} || $name; } +=head2 C + +Maps F C tag values to the corresponding list of Gentoo licenses identifiers. +Duplicates are stripped off. + +The included data was gathered from L and L. + +=cut + +my %licenses = ( + apache => [ 'Apache-2.0' ], + artistic => [ 'Artistic' ], + artistic_2 => [ 'Artistic-2' ], + bsd => [ 'BSD' ], + gpl => [ 'GPL-1' ], + gpl2 => [ 'GPL-2' ], + gpl3 => [ 'GPL-3' ], + lgpl => [ 'LGPL-2.1' ], + lgpl2 => [ 'LGPL-2.1' ], + lgpl3 => [ 'LGPL-3' ], + mit => [ 'MIT' ], + mozilla => [ 'MPL-1.1' ], + perl => [ 'Artistic', 'GPL-2' ], +); + +sub license_c2g { + my %seen; + grep !$seen{$_}++, map @{$licenses{+lc} || []}, @_; +} + =head2 C Converts a CPAN version to a Gentoo version. diff --git a/t/13-maps-license.t b/t/13-maps-license.t new file mode 100644 index 0000000..0a19d00 --- /dev/null +++ b/t/13-maps-license.t @@ -0,0 +1,18 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 4; + +use CPANPLUS::Dist::Gentoo::Maps; + +sub check_licenses { + my @licenses = CPANPLUS::Dist::Gentoo::Maps::license_c2g(@{$_[0]}); + is_deeply \@licenses, $_[1], $_[2]; +} + +check_licenses [ 'woo' ], [ ], 'nonexistent'; +check_licenses [ 'perl' ], [ qw/Artistic GPL-2/ ], 'perl'; +check_licenses [ qw/perl gpl2/ ], [ qw/Artistic GPL-2/ ], 'perl + gpl2'; +check_licenses [ qw/perl bsd/ ], [ qw/Artistic GPL-2 BSD/ ], 'perl + bsd';