]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
Reduce namespace pollution
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index dc35d0bb52eabe2c42402c4437755f83b770cdae..5c4dd8e752bdf458bab49b21f85b7c10ceff46d7 100644 (file)
@@ -4,9 +4,9 @@ use strict;
 use warnings;
 
 use Cwd qw/abs_path/;
-use File::Copy qw/copy/;
-use File::Path qw/mkpath/;
-use File::Spec::Functions qw/catdir catfile/;
+use File::Copy ();
+use File::Path ();
+use File::Spec;
 
 use IPC::Cmd qw/run can_run/;
 
@@ -22,11 +22,11 @@ CPANPLUS::Dist::Gentoo - CPANPLUS backend generating Gentoo ebuilds.
 
 =head1 VERSION
 
-Version 0.05
+Version 0.07
 
 =cut
 
-our $VERSION = '0.05';
+our $VERSION = '0.07';
 
 =head1 SYNOPSIS
 
@@ -64,12 +64,12 @@ my $main_portdir;
 
 my %forced;
 
-sub _unquote {
+my $unquote = sub {
  my $s = shift;
  $s =~ s/^["']*//;
  $s =~ s/["']*$//;
  return $s;
-}
+};
 
 my $format_available;
 
@@ -84,22 +84,22 @@ sub format_available {
  }
 
  if (IPC::Cmd->can_capture_buffer) {
-  my ($success, $errmsg, $output) = run command => [ qw/emerge --info/ ],
-                                        verbose => 0;
+  my $buffers;
+  my ($success, $errmsg) = run command => [ qw/emerge --info/ ],
+                               verbose => 0,
+                               buffer  => \$buffers;
   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));
-    }
-    if (/^PORTDIR=(.*)$/m) {
-     $main_portdir = abs_path(_unquote($1));
-    }
+   if ($buffers =~ /^PORTDIR_OVERLAY=(.*)$/m) {
+    $overlays = [ map abs_path($_), split ' ', $unquote->($1) ];
+   }
+   if ($buffers =~ /^ACCEPT_KEYWORDS=(.*)$/m) {
+    $default_keywords = [ split ' ', $unquote->($1) ];
+   }
+   if ($buffers =~ /^DISTDIR=(.*)$/m) {
+    $default_distdir = abs_path($unquote->($1));
+   }
+   if ($buffers =~ /^PORTDIR=(.*)$/m) {
+    $main_portdir = abs_path($unquote->($1));
    }
   } else {
    error $errmsg;
@@ -184,10 +184,10 @@ sub prepare {
  }
  $stat->fetched_arch($mod->status->fetch);
 
- my $cur = File::Spec::Functions::curdir();
+ my $cur = File::Spec->curdir();
  my $portdir_overlay;
  for (@$overlays) {
-  if ($_ eq $overlay or File::Spec::Functions::abs2rel($overlay, $_) eq $cur) {
+  if ($_ eq $overlay or File::Spec->abs2rel($overlay, $_) eq $cur) {
    $portdir_overlay = [ @$overlays ];
    last;
   }
@@ -210,10 +210,16 @@ sub prepare {
 
  $stat->eb_name(CPANPLUS::Dist::Gentoo::Maps::name_c2g($name));
 
- $stat->eb_dir(catdir($stat->overlay, CATEGORY, $stat->eb_name));
+ $stat->eb_dir(File::Spec->catdir(
+  $stat->overlay,
+  CATEGORY,
+  $stat->eb_name,
+ ));
 
- my $file = catfile($stat->eb_dir,
-                    $stat->eb_name . '-' . $stat->eb_version . '.ebuild');
+ my $file = File::Spec->catfile(
+  $stat->eb_dir,
+  $stat->eb_name . '-' . $stat->eb_version . '.ebuild',
+ );
  $stat->eb_file($file);
 
  if (-e $file) {
@@ -303,7 +309,7 @@ sub create {
 
  my $dir = $stat->eb_dir;
  unless (-d $dir) {
-  eval { mkpath $dir };
+  eval { File::Path::mkpath($dir) };
   if ($@) {
    error "mkpath($dir): $@";
    return 0;
@@ -346,7 +352,7 @@ sub create {
  $stat->dist(undef);
 
  if ($stat->do_manifest) {
-  unless (copy $stat->fetched_arch, $stat->distdir) {
+  unless (File::Copy::copy($stat->fetched_arch => $stat->distdir)) {
    error "Couldn\'t copy the distribution file to distdir ($!) -- aborting";
    1 while unlink $file;
    return 0;
@@ -365,10 +371,11 @@ sub create {
 }
 
 sub _cpan2portage {
- my ($self, $name, $ver) = @_;
+ my ($self, $name, $version) = @_;
 
  $name = CPANPLUS::Dist::Gentoo::Maps::name_c2g($name);
- $ver  = CPANPLUS::Dist::Gentoo::Maps::version_c2g($ver);
+ my $ver;
+ $ver = CPANPLUS::Dist::Gentoo::Maps::version_c2g($version) if defined $version;
 
  my @portdirs = ($main_portdir, @{$self->status->portdir_overlay});
 
@@ -376,8 +383,12 @@ sub _cpan2portage {
   my $atom = ($category eq 'virtual' ? 'perl-' : '') . $name;
 
   for my $portdir (@portdirs) {
-   my @ebuilds = glob catfile($portdir, $category, $atom,"$atom-*.ebuild");
-   next unless @ebuilds;
+   my @ebuilds = glob File::Spec->catfile(
+    $portdir,
+    $category,
+    $atom,
+    "$atom-*.ebuild",
+   ) or next;
 
    if (defined $ver) { # implies that $version is defined
     for (@ebuilds) {
@@ -440,7 +451,7 @@ sub _run {
 
  unless ($success) {
   error "$errmsg -- aborting";
-  if (not $verbose and defined $output and $self->status->verbose) {
+  if (not $verbose and defined $output and $stat->verbose) {
    my $msg = join '', @$output;
    1 while chomp $msg;
    error $msg;
@@ -456,7 +467,7 @@ Gentoo (L<http://gentoo.org>).
 
 L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5).
 
-L<Cwd>, L<Carp> (since perl 5), L<File::Path> (5.001), L<File::Copy> (5.002), L<File::Spec::Functions> (5.00504).
+L<Cwd>, L<Carp> (since perl 5), L<File::Path> (5.001), L<File::Copy> (5.002), L<File::Spec> (5.00405).
 
 =head1 SEE ALSO