]> 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 5b113d812609dbe06ce28532a1e0ce0281d0279b..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 ();
 
@@ -41,9 +42,12 @@ our $VERSION = '0.07';
 
 =head1 DESCRPITON
 
-This module is a CPANPLUS backend that recursively generates Gentoo ebuilds for a given package in the specified overlay (defaults to F</usr/local/portage>), updates the manifest, and even emerges it (together with its dependencies) if the user requires it. You need write permissions on the directory where Gentoo fetches its source files (usually F</usr/portage/distfiles>). The valid C<KEYWORDS> for the generated ebuilds are by default those given in C<ACCEPT_KEYWORDS>, but you can specify your own with the C<keywords> dist-option.
+This module is a CPANPLUS backend that recursively generates Gentoo ebuilds for a given package in the specified overlay (defaults to F</usr/local/portage>), updates the manifest, and even emerges it (together with its dependencies) if the user requires it.
+You need write permissions on the directory where Gentoo fetches its source files (usually F</usr/portage/distfiles>).
+The valid C<KEYWORDS> for the generated ebuilds are by default those given in C<ACCEPT_KEYWORDS>, but you can specify your own with the C<keywords> dist-option.
 
-The generated ebuilds are placed into the C<perl-gcpanp> category. They favour depending on a C<virtual>, on C<perl-core>, C<dev-perl> or C<perl-gcpan> (in that order) rather than C<perl-gcpanp>.
+The generated ebuilds are placed into the C<perl-gcpanp> category.
+They favour depending on a C<virtual>, on C<perl-core>, C<dev-perl> or C<perl-gcpan> (in that order) rather than C<perl-gcpanp>.
 
 =head1 INSTALLATION
 
@@ -51,7 +55,8 @@ After installing this module, you should append C<perl-gcpanp> to your F</etc/po
 
 =head1 METHODS
 
-All the methods are inherited from L<CPANPLUS::Dist::Base>. Please refer to its documentation for precise information on what's done at each step.
+This module inherits all the methods from L<CPANPLUS::Dist::Base>.
+Please refer to its documentation for precise information on what's done at each step.
 
 =cut
 
@@ -260,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;
@@ -286,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;
@@ -330,7 +378,7 @@ sub create {
 
 =head2 C<update_manifest>
 
-Update the F<Manifest> file for the ebuild associated to the current dist object.
+Updates the F<Manifest> file for the ebuild associated to the current dist object.
 
 =cut
 
@@ -504,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).
 
@@ -522,7 +570,8 @@ You can contact me by mail or on C<irc.perl.org> (vincent).
 
 =head1 BUGS
 
-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>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
+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>.
+I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
 
 =head1 SUPPORT
 
@@ -532,7 +581,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 ACKNOWLEDGEMENTS
 
-The module is to some extend cargo-culted from L<CPANPLUS::Dist::Deb> and L<CPANPLUS::Dist::Mdv>.
+The module was inspired by L<CPANPLUS::Dist::Deb> and L<CPANPLUS::Dist::Mdv>.
 
 Kent Fredric, for testing and suggesting improvements.