From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.gentoo.org (smtp.gentoo.org [134.68.220.30]) by robin.gentoo.org (8.13.4/8.13.4) with ESMTP id j4CLvEs2002434 for ; Thu, 12 May 2005 21:57:14 GMT Received: from ik63066.ikexpress.com ([213.246.63.66] helo=gredin.dragou.net) by smtp.gentoo.org with esmtp (Exim 4.43) id 1DWLgA-0006lQ-5L for gentoo-perl@lists.gentoo.org; Thu, 12 May 2005 21:57:14 +0000 Received: from localhost (localhost [127.0.0.1]) by gredin.dragou.net (Postfix) with ESMTP id C6C5C8280EE for ; Thu, 12 May 2005 23:56:36 +0200 (CEST) Received: from gredin.dragou.net ([127.0.0.1]) by localhost (gredin [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 28409-04 for ; Thu, 12 May 2005 23:56:34 +0200 (CEST) Received: by gredin.dragou.net (Postfix, from userid 0) id BA60C8280F2; Thu, 12 May 2005 23:56:22 +0200 (CEST) To: gentoo-perl@lists.gentoo.org From: antoine.raillon@dragou.net Subject: [gentoo-perl] r9 - code Content-Type: text/plain; charset=UTF-8 Message-Id: <20050512215622.BA60C8280F2@gredin.dragou.net> Date: Thu, 12 May 2005 23:56:22 +0200 (CEST) X-Virus-Scanned: by amavisd-new at dragou.net Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by robin.gentoo.org id j4CLvEs2002434 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-perl@gentoo.org Reply-To: gentoo-perl@gentoo.org X-Archives-Salt: b255b349-dd39-4316-8270-bd5ed16c9ac3 X-Archives-Hash: 33696846fa308da39ff293598c69bcf4 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@gentoo.org mailing list