]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
Intuit the correct license from the DSLIP or the META file
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index 243253e227f33b9c6cc3c14b9bb64332a5d19134..51f23d10df4345ac507bf3cefca18a8cd05fd24b 100644 (file)
@@ -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<intuit_license>
+
+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<http://gentoo.org>).
 
-L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5).
+L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5), L<Parse::CPAN::Meta> (since 5.10.1).
 
 L<Cwd>, L<Carp> (since perl 5), L<File::Path> (5.001), L<File::Copy> (5.002), L<File::Spec> (5.00405).