Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-perl
Navigation:
Lists: gentoo-perl: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-perl@g.o
From: antoine.raillon@...
Subject: r9 - code
Date: Thu, 12 May 2005 23:56:22 +0200 (CEST)
Author: sniper
Date: 2005-05-11 04:53:30 +0200 (Wed, 11 May 2005)
New Revision: 9

Modified:
   code/g-cpan.pl
Log:
sub cpan_stub {} cleaned
- constants added at the top
- get rid of if(){}else{} army, replaced by ternary operator ?:
  because scopes (blocks) are costly
- bad usage of $| in error message replaced by $!
- clean file/folder name usage



Modified: code/g-cpan.pl
===================================================================
--- code/g-cpan.pl	2005-05-11 01:52:29 UTC (rev 8)
+++ code/g-cpan.pl	2005-05-11 02:53:30 UTC (rev 9)
@@ -12,8 +12,28 @@
 use File::Path;
 use List::Util qw(first);
 
+use constant MAKE_CONF         => '/etc/make.conf';
+use constant PATH_PKG_DEV_PERL => '/var/db/pkg/dev-perl';
+##### CPAN CONFIG #####
+use constant CPAN_CFG_DIR      => '.cpan/CPAN';
+use constant CPAN_CFG_NAME     => 'MyConfig.pm';
+# defaults tools for CPAN Config
+use constant DEF_FTP_PROG      => '/usr/bin/ftp';
+use constant DEF_GPG_PROG      => '/usr/bin/gpg';
+use constant DEF_GZIP_PROG     => '/bin/gzip';
+use constant DEF_LYNX_PROG     => '/usr/bin/lynx';
+use constant DEF_MAKE_PROG     => '/usr/bin/make';
+use constant DEF_NCFTPGET_PROG => '/usr/bin/ncftpget';
+use constant DEF_LESS_PROG     => '/usr/bin/less';
+use constant DEF_TAR_PROG      => '/bin/tar';
+use constant DEF_UNZIP_PROG    => '/usr/bin/unzip';
+use constant DEF_WGET_PROG     => '/usr/bin/wget';
+use constant DEF_BASH_PROG     => '/bin/bash';
+
+# predeclared subs
 sub printbig;
 
+
 # Do we need to generate a config ?
 eval 'use CPAN::Config;';
 my $needs_cpan_stub = $@ ? 1 : 0;
@@ -132,7 +152,7 @@
         my $otmp = File::Spec->catdir( $odir, $pdir );
         push @OVERLAY_PERLS, $otmp;
     }
-    my $vtmp_dir = File::Spec->catdir( '/var/db/pkg/dev-perl', $pdir );
+    my $vtmp_dir = File::Spec->catdir(PATH_PKG_DEV_PERL, $pdir );
     push @TMP_DEV_PERL_DIRS, $vtmp_dir;
 }
 
@@ -698,52 +718,30 @@
 }
 
 sub cpan_stub {
-    printbig
-"No CPAN Config found, auto-generating a basic one in $ENV{HOME}/.cpan/CPAN\n";
-    unless ( -d "$ENV{HOME}/.cpan" ) {
-        mkpath( "$ENV{HOME}/.cpan", 1, 0755 )
-          or die "Couldn't create $ENV{HOME}/.cpan: $|";
+    my $cpan_cfg_dir  = File::Spec->catfile($ENV{HOME},    CPAN_CFG_DIR);
+    my $cpan_cfg_file = File::Spec->catfile($cpan_cfg_dir, CPAN_CFG_NAME);
+
+    printbig "No CPAN Config found, auto-generating a basic one in $cpan_cfg_dir\n";
+    if(not -d $cpan_cfg_dir) {
+        mkpath($cpan_cfg_dir, 1, 0755 ) or die "Couldn't create folder '$cpan_cfg_dir' : $!";
     }
-    unless ( -d "$ENV{HOME}/.cpan/CPAN" ) {
-        mkpath( "$ENV{HOME}/.cpan/CPAN", 1, 0755 )
-          or die "Couldn't create $ENV{HOME}/.cpan/CPAN: $|";
-    }
 
-    my (
-        $tmp_dir,    $ftp_prog,   $gpg_prog,      $gzip_prog,
-        $lynx_prog,  $make_prog,  $ncftpget_prog, $less_prog,
-        $tar_prog,   $unzip_prog, $wget_prog,     $ftp_proxy,
-        $http_proxy, $user_shell
-    );
-    if ( $ENV{TMPDIR} ) { $tmp_dir = $ENV{TMPDIR} }
-    else { $tmp_dir = "$ENV{HOME}" }
-    if ( -f "/usr/bin/ftp" ) { $ftp_prog = "/usr/bin/ftp" }
-    else { $ftp_prog = "" }
-    if ( -f "/usr/bin/gpg" ) { $gpg_prog = "/usr/bin/gpg" }
-    else { $gpg_prog = "" }
-    if ( -f "/bin/gzip" ) { $gzip_prog = "/bin/gzip" }
-    else { $gzip_prog = "" }
-    if ( -f "/usr/bin/lynx" ) { $lynx_prog = "/usr/bin/lynx" }
-    else { $lynx_prog = "" }
-    if ( -f "/usr/bin/make" ) { $make_prog = "/usr/bin/make" }
-    else { $make_prog = "" }
-    if ( -f "/usr/bin/ncftpget" ) { $ncftpget_prog = "/usr/bin/ncftpget" }
-    else { $ncftpget_prog = "" }
-    if ( -f "/usr/bin/less" ) { $less_prog = "/usr/bin/less" }
-    else { $less_prog = "" }
-    if ( -f "/bin/tar" ) { $tar_prog = "/bin/tar" }
-    else { $tar_prog = "" }
-    if ( -f "/usr/bin/unzip" ) { $unzip_prog = "/usr/bin/unzip" }
-    else { $unzip_prog = "" }
-    if ( -f "/usr/bin/wget" ) { $wget_prog = "/usr/bin/wget" }
-    else { $wget_prog = "" }
-    if ( $ENV{ftp_proxy} ) { $ftp_proxy = $ENV{ftp_proxy} }
-    else { $ftp_proxy = "" }
-    if ( $ENV{http_proxy} ) { $http_proxy = $ENV{http_proxy} }
-    else { $http_proxy = "" }
-    if ( $ENV{SHELL} ) { $user_shell = $ENV{SHELL} }
-    else { $user_shell = "/bin/bash" }
-    open( CPANCONF, ">$ENV{HOME}/.cpan/CPAN/MyConfig.pm" );
+    my $tmp_dir       = -d $ENV{TMPDIR}      ? $ENV{TMPDIR}      : $ENV{HOME};
+    my $ftp_proxy     =    $ENV{ftp_proxy}   ? $ENV{ftp_proxy}   : '';
+    my $http_proxy    =    $ENV{http_proxy}  ? $ENV{http_proxy}  : '';
+    my $user_shell    = -x $ENV{SHELL}       ? $ENV{SHELL}       : DEF_BASH_PROG;
+    my $ftp_prog      = -x DEF_FTP_PROG      ? DEF_FTP_PROG      : '';
+    my $gpg_prog      = -x DEF_GPG_PROG      ? DEF_GPG_PROG      : '';
+    my $gzip_prog     = -x DEF_GZIP_PROG     ? DEF_GZIP_PROG     : '';
+    my $lynx_prog     = -x DEF_LYNX_PROG     ? DEF_LYNX_PROG     : '';
+    my $make_prog     = -x DEF_MAKE_PROG     ? DEF_MAKE_PROG     : '';
+    my $ncftpget_prog = -x DEF_NCFTPGET_PROG ? DEF_NCFTPGET_PROG : '';
+    my $less_prog     = -x DEF_LESS_PROG     ? DEF_LESS_PROG     : '';
+    my $tar_prog      = -x DEF_TAR_PROG      ? DEF_TAR_PROG      : '';
+    my $unzip_prog    = -x DEF_UNZIP_PROG    ? DEF_UNZIP_PROG    : '';
+    my $wget_prog     = -x DEF_WGET_PROG     ? DEF_WGET_PROG     : '';
+
+    open CPANCONF, ">$cpan_cfg_file" or die "Couldn't create file '$cpan_cfg_file' : $!";
     print CPANCONF <<"SHERE";
 
 # This is CPAN.pm's systemwide configuration file. This file provides
@@ -789,28 +787,26 @@
 1;
 __END__
 
-
 SHERE
 
-    close(CPANCONF);
-
+    close CPANCONF;
 }
 
 # Simple useful sub. returns md5 hexdigest of the given argument
 # awaits a file name.
 sub file_md5sum {
-	
-	my $file = $_[0];
-	
-	if ($verbose) {
-		print "Computing MD5 Sum of $file\n";
-	}
-	
+
+    my $file = $_[0];
+
+    if ($verbose) {
+        print "Computing MD5 Sum of $file\n";
+    }
+
     open(DIGIFILE, $file ) or die "Can't open '$file': $!";
     my $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest;
     close(DIGIFILE);
-	
-	return $md5digest;
+
+    return $md5digest;
 }
 
 # Takes care of system's sanity
@@ -836,14 +832,14 @@
 
 --list,-l       This command generates a list of the Perl modules and ebuilds
                 handled by $0.
-	
+
 --search,-s     Search CPAN for the given expression (similar to
                 the "m /EXPR/" from the CPAN Shell). Searches are
                 case insensitive.
 
 --upgrade,-u    Try to list and upgrade all Perl modules managed by $0.
                 It generate up-to-date ebuilds, then emerge then.
-	
+
 --verbose,-v    Enable (some) verbose output.
 
 USAGE


-- 
gentoo-perl@g.o mailing list

Navigation:
Lists: gentoo-perl: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
r8 - code
Next by thread:
r10 - code
Previous by date:
r8 - code
Next by date:
r10 - code


Updated Jun 17, 2009

Summary: Archive of the gentoo-perl mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.