use File::Spec;
use IPC::Cmd qw/run can_run/;
+use Parse::CPAN::Meta ();
use CPANPLUS::Error ();
my $OK = sub { $stat->prepared(1); 1 };
my $FAIL = sub { $stat->prepared(0); $self->_abort(@_) if @_; 0 };
- my $keywords = delete $opts{'keywords'};
+ my $keywords = delete $opts{keywords};
if (defined $keywords) {
$keywords = [ split ' ', $keywords ];
} else {
}
$stat->keywords($keywords);
- my $manifest = delete $opts{'manifest'};
+ my $manifest = delete $opts{manifest};
$manifest = 1 unless defined $manifest;
$manifest = 0 if $manifest =~ /^\s*no?\s*$/i;
$stat->do_manifest($manifest);
- my $header = delete $opts{'header'};
+ my $header = delete $opts{header};
if (defined $header) {
1 while chomp $header;
$header .= "\n\n";
}
$stat->header($header);
- my $footer = delete $opts{'footer'};
+ my $footer = delete $opts{footer};
if (defined $footer) {
$footer = "\n" . $footer;
} else {
}
$stat->footer($footer);
- my $overlay = delete $opts{'overlay'};
+ my $overlay = delete $opts{overlay};
$overlay = (defined $overlay) ? abs_path $overlay : '/usr/local/portage';
$stat->overlay($overlay);
- my $distdir = delete $opts{'distdir'};
+ my $distdir = delete $opts{distdir};
$distdir = (defined $distdir) ? abs_path $distdir : $default_distdir;
$stat->distdir($distdir);
- if ($stat->do_manifest && !-w $stat->distdir) {
- return $FAIL->('distdir isn\'t writable');
- }
+ return $FAIL->("distdir isn't writable") if $stat->do_manifest && !-w $distdir;
+
$stat->fetched_arch($mod->status->fetch);
my $cur = File::Spec->curdir();
}
}
+ $stat->prepared(0);
+
$self->SUPER::prepare(%opts);
- $stat->prepared(0);
+ return $FAIL->() unless $stat->prepared;
my $desc = $mod->description;
($desc = $name) =~ s/-+/::/g unless $desc;
$stat->uri('http://search.cpan.org/dist/' . $name);
- unless ($author =~ /^(.)(.)/) {
- return $FAIL->('Wrong author name');
- }
- $stat->src("mirror://cpan/modules/by-authors/id/$1/$1$2/$author/"
- . $mod->package);
+ $author =~ /^(.)(.)/ or return $FAIL->('Wrong author name');
+ $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;
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;
$self->SUPER::create(@_);
+ unless ($stat->created) {
+ 1 while unlink $file;
+ return $FAIL->();
+ }
+
if ($stat->do_manifest and not $self->update_manifest) {
1 while unlink $file;
return $FAIL->();
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).