]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
Make $stat->portdir_overlay an array reference
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index 2cd8ddf2c32894656bf92ca2b452ee6b10d9296c..8e1809ccfe7f2598e014cc510374aa6cb1f7fa75 100644 (file)
@@ -39,7 +39,7 @@ our $VERSION = '0.04';
 
 =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>). You also need to specify the correct keyword for your architecture if it differs from the default C<x86>.
+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 C<perl-core>, C<dev-perl> or C<perl-gcpan> (in that order) rather than C<perl-gcpanp>.
 
@@ -56,6 +56,15 @@ All the methods are inherited from L<CPANPLUS::Dist::Base>. Please refer to its
 use constant CATEGORY => 'perl-gcpanp';
 
 my $overlays;
+my $default_keywords;
+my $default_distdir;
+
+sub _unquote {
+ my $s = shift;
+ $s =~ s/^["']*//;
+ $s =~ s/["']*$//;
+ return $s;
+}
 
 sub format_available {
  for my $prog (qw/emerge ebuild/) {
@@ -66,20 +75,28 @@ sub format_available {
  }
 
  if (IPC::Cmd->can_capture_buffer) {
-  my $output = '';
-  my $success = run command => [ qw/emerge --info/ ],
-                    verbose => 0,
-                    buffer  => \$output;
-  if ($success and $output) {
-   if ($output =~ /^PORTDIR_OVERLAY=(.*)$/m) {
-    my $o = $1;
-    $o =~ s/^["']*//;
-    $o =~ s/["']*$//;
-    $overlays = [ map abs_path($_), grep length, split /:/, $o ];
+  my ($success, $errmsg, $output) = run command => [ qw/emerge --info/ ],
+                                        verbose => 0;
+  if ($success) {
+   for (@{$output || []}) {
+    if (/^PORTDIR_OVERLAY=(.*)$/m) {
+     $overlays = [ map abs_path($_), split ' ', _unquote($1) ];
+    }
+    if (/^ACCEPT_KEYWORDS=(.*)$/m) {
+     $default_keywords = [ split ' ', _unquote($1) ];
+    }
+    if (/^DISTDIR=(.*)$/m) {
+     $default_distdir = abs_path(_unquote($1));
+    }
    }
+  } else {
+   error $errmsg;
   }
  }
 
+ $default_keywords = [ 'x86' ] unless defined $default_keywords;
+ $default_distdir  = '/usr/portage/distfiles' unless defined $default_distdir;
+
  return 1;
 }
 
@@ -88,7 +105,7 @@ sub init {
  my $stat = $self->status;
  my $conf = $self->parent->parent->configure_object;
 
- $stat->mk_accessors(qw/name version author distribution desc uri src license
+ $stat->mk_accessors(qw/name version author distribution desc uri license
                         deps eb_name eb_version eb_dir eb_file fetched_arch
                         portdir_overlay
                         overlay distdir keywords do_manifest header footer
@@ -100,7 +117,7 @@ sub init {
  return 1;
 }
 
-my %gentooism = (
+our %gentooism = (
  'ANSIColor'               => 'Term-ANSIColor',
  'Audio-CD'                => 'Audio-CD-disc-cover',
  'CGI-Simple'              => 'Cgi-Simple',
@@ -186,8 +203,11 @@ sub prepare {
  $stat->prepared(0);
 
  my $keywords = delete $opts{'keywords'};
- $keywords = 'x86' unless defined $keywords;
- $keywords = [ split ' ', $keywords ];
+ if (defined $keywords) {
+  $keywords = [ split ' ', $keywords ];
+ } else {
+  $keywords = $default_keywords;
+ }
  $stat->keywords($keywords);
 
  my $manifest = delete $opts{'manifest'};
@@ -217,7 +237,7 @@ sub prepare {
  $stat->overlay($overlay);
 
  my $distdir = delete $opts{'distdir'};
- $distdir = (defined $distdir) ? abs_path $distdir : '/usr/portage/distfiles';
+ $distdir = (defined $distdir) ? abs_path $distdir : $default_distdir;
  $stat->distdir($distdir);
 
  if ($stat->do_manifest && !-w $stat->distdir) {
@@ -230,12 +250,11 @@ sub prepare {
  my $portdir_overlay;
  for (@$overlays) {
   if ($_ eq $overlay or File::Spec::Functions::abs2rel($overlay, $_) eq $cur) {
-   $portdir_overlay = join ':', @$overlays;
+   $portdir_overlay = [ @$overlays ];
    last;
   }
  }
- $portdir_overlay = join ':', @$overlays, $overlay
-                                                unless defined $portdir_overlay;
+ $portdir_overlay = [ @$overlays, $overlay ] unless $portdir_overlay;
  $stat->portdir_overlay($portdir_overlay);
 
  my $name = $mod->package_name;
@@ -266,6 +285,8 @@ sub prepare {
 
  my $file = catfile($stat->eb_dir,
                     $stat->eb_name . '-' . $stat->eb_version . '.ebuild');
+ $stat->eb_file($file);
+
  if (-e $file) {
   my $skip = 1;
   if ($stat->force) {
@@ -285,7 +306,6 @@ sub prepare {
    return 1;
   }
  }
- $stat->eb_file($file);
 
  $self->SUPER::prepare(%opts);
 
@@ -297,13 +317,6 @@ sub prepare {
 
  $stat->uri('http://search.cpan.org/dist/' . $name);
 
- unless ($author =~ /^(.)(.)/) {
-  error 'Wrong author name -- aborting';
-  return 0;
- }
- $stat->src("mirror://cpan/modules/by-authors/id/$1/$1$2/$author/"
-            . $mod->package);
-
  $stat->license([ qw/Artistic GPL-2/ ]);
 
  my $prereqs = $mod->status->prereqs;
@@ -371,10 +384,8 @@ sub create {
  my $d = $stat->header;
  $d   .= "# Generated by CPANPLUS::Dist::Gentoo version $VERSION\n\n";
  $d   .= 'MODULE_AUTHOR="' . $stat->author . "\"\ninherit perl-module\n\n";
- $d   .= 'S="${WORKDIR}/' . $stat->distribution . "\"\n";
  $d   .= 'DESCRIPTION="' . $stat->desc . "\"\n";
- $d   .= 'HOMEPAGE="' . $stat->uri . "\"\n";
- $d   .= 'SRC_URI="' . $stat->src . "\"\n";
+ $d   .= 'HOMEPAGE="' . $stat->uri . "\"\n\n";
  $d   .= "SLOT=\"0\"\n";
  $d   .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n";
  $d   .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n";
@@ -458,7 +469,7 @@ sub _run {
  my $stat = $self->status;
 
  my ($success, $errmsg, $output) = do {
-  local $ENV{PORTDIR_OVERLAY}     = $stat->portdir_overlay;
+  local $ENV{PORTDIR_OVERLAY}     = join ' ', @{$stat->portdir_overlay};
   local $ENV{PORTAGE_RO_DISTDIRS} = $stat->distdir;
   run command => $cmd, verbose => $verbose;
  };