Gentoo Archives: gentoo-perl

From: antoine.raillon@××××××.net
To: gentoo-perl@l.g.o
Subject: [gentoo-perl] r9 - code
Date: Thu, 12 May 2005 21:57:14
Message-Id: 20050512215622.BA60C8280F2@gredin.dragou.net
1 Author: sniper
2 Date: 2005-05-11 04:53:30 +0200 (Wed, 11 May 2005)
3 New Revision: 9
4
5 Modified:
6 code/g-cpan.pl
7 Log:
8 sub cpan_stub {} cleaned
9 - constants added at the top
10 - get rid of if(){}else{} army, replaced by ternary operator ?:
11 because scopes (blocks) are costly
12 - bad usage of $| in error message replaced by $!
13 - clean file/folder name usage
14
15
16
17 Modified: code/g-cpan.pl
18 ===================================================================
19 --- code/g-cpan.pl 2005-05-11 01:52:29 UTC (rev 8)
20 +++ code/g-cpan.pl 2005-05-11 02:53:30 UTC (rev 9)
21 @@ -12,8 +12,28 @@
22 use File::Path;
23 use List::Util qw(first);
24
25 +use constant MAKE_CONF => '/etc/make.conf';
26 +use constant PATH_PKG_DEV_PERL => '/var/db/pkg/dev-perl';
27 +##### CPAN CONFIG #####
28 +use constant CPAN_CFG_DIR => '.cpan/CPAN';
29 +use constant CPAN_CFG_NAME => 'MyConfig.pm';
30 +# defaults tools for CPAN Config
31 +use constant DEF_FTP_PROG => '/usr/bin/ftp';
32 +use constant DEF_GPG_PROG => '/usr/bin/gpg';
33 +use constant DEF_GZIP_PROG => '/bin/gzip';
34 +use constant DEF_LYNX_PROG => '/usr/bin/lynx';
35 +use constant DEF_MAKE_PROG => '/usr/bin/make';
36 +use constant DEF_NCFTPGET_PROG => '/usr/bin/ncftpget';
37 +use constant DEF_LESS_PROG => '/usr/bin/less';
38 +use constant DEF_TAR_PROG => '/bin/tar';
39 +use constant DEF_UNZIP_PROG => '/usr/bin/unzip';
40 +use constant DEF_WGET_PROG => '/usr/bin/wget';
41 +use constant DEF_BASH_PROG => '/bin/bash';
42 +
43 +# predeclared subs
44 sub printbig;
45
46 +
47 # Do we need to generate a config ?
48 eval 'use CPAN::Config;';
49 my $needs_cpan_stub = $@ ? 1 : 0;
50 @@ -132,7 +152,7 @@
51 my $otmp = File::Spec->catdir( $odir, $pdir );
52 push @OVERLAY_PERLS, $otmp;
53 }
54 - my $vtmp_dir = File::Spec->catdir( '/var/db/pkg/dev-perl', $pdir );
55 + my $vtmp_dir = File::Spec->catdir(PATH_PKG_DEV_PERL, $pdir );
56 push @TMP_DEV_PERL_DIRS, $vtmp_dir;
57 }
58
59 @@ -698,52 +718,30 @@
60 }
61
62 sub cpan_stub {
63 - printbig
64 -"No CPAN Config found, auto-generating a basic one in $ENV{HOME}/.cpan/CPAN\n";
65 - unless ( -d "$ENV{HOME}/.cpan" ) {
66 - mkpath( "$ENV{HOME}/.cpan", 1, 0755 )
67 - or die "Couldn't create $ENV{HOME}/.cpan: $|";
68 + my $cpan_cfg_dir = File::Spec->catfile($ENV{HOME}, CPAN_CFG_DIR);
69 + my $cpan_cfg_file = File::Spec->catfile($cpan_cfg_dir, CPAN_CFG_NAME);
70 +
71 + printbig "No CPAN Config found, auto-generating a basic one in $cpan_cfg_dir\n";
72 + if(not -d $cpan_cfg_dir) {
73 + mkpath($cpan_cfg_dir, 1, 0755 ) or die "Couldn't create folder '$cpan_cfg_dir' : $!";
74 }
75 - unless ( -d "$ENV{HOME}/.cpan/CPAN" ) {
76 - mkpath( "$ENV{HOME}/.cpan/CPAN", 1, 0755 )
77 - or die "Couldn't create $ENV{HOME}/.cpan/CPAN: $|";
78 - }
79
80 - my (
81 - $tmp_dir, $ftp_prog, $gpg_prog, $gzip_prog,
82 - $lynx_prog, $make_prog, $ncftpget_prog, $less_prog,
83 - $tar_prog, $unzip_prog, $wget_prog, $ftp_proxy,
84 - $http_proxy, $user_shell
85 - );
86 - if ( $ENV{TMPDIR} ) { $tmp_dir = $ENV{TMPDIR} }
87 - else { $tmp_dir = "$ENV{HOME}" }
88 - if ( -f "/usr/bin/ftp" ) { $ftp_prog = "/usr/bin/ftp" }
89 - else { $ftp_prog = "" }
90 - if ( -f "/usr/bin/gpg" ) { $gpg_prog = "/usr/bin/gpg" }
91 - else { $gpg_prog = "" }
92 - if ( -f "/bin/gzip" ) { $gzip_prog = "/bin/gzip" }
93 - else { $gzip_prog = "" }
94 - if ( -f "/usr/bin/lynx" ) { $lynx_prog = "/usr/bin/lynx" }
95 - else { $lynx_prog = "" }
96 - if ( -f "/usr/bin/make" ) { $make_prog = "/usr/bin/make" }
97 - else { $make_prog = "" }
98 - if ( -f "/usr/bin/ncftpget" ) { $ncftpget_prog = "/usr/bin/ncftpget" }
99 - else { $ncftpget_prog = "" }
100 - if ( -f "/usr/bin/less" ) { $less_prog = "/usr/bin/less" }
101 - else { $less_prog = "" }
102 - if ( -f "/bin/tar" ) { $tar_prog = "/bin/tar" }
103 - else { $tar_prog = "" }
104 - if ( -f "/usr/bin/unzip" ) { $unzip_prog = "/usr/bin/unzip" }
105 - else { $unzip_prog = "" }
106 - if ( -f "/usr/bin/wget" ) { $wget_prog = "/usr/bin/wget" }
107 - else { $wget_prog = "" }
108 - if ( $ENV{ftp_proxy} ) { $ftp_proxy = $ENV{ftp_proxy} }
109 - else { $ftp_proxy = "" }
110 - if ( $ENV{http_proxy} ) { $http_proxy = $ENV{http_proxy} }
111 - else { $http_proxy = "" }
112 - if ( $ENV{SHELL} ) { $user_shell = $ENV{SHELL} }
113 - else { $user_shell = "/bin/bash" }
114 - open( CPANCONF, ">$ENV{HOME}/.cpan/CPAN/MyConfig.pm" );
115 + my $tmp_dir = -d $ENV{TMPDIR} ? $ENV{TMPDIR} : $ENV{HOME};
116 + my $ftp_proxy = $ENV{ftp_proxy} ? $ENV{ftp_proxy} : '';
117 + my $http_proxy = $ENV{http_proxy} ? $ENV{http_proxy} : '';
118 + my $user_shell = -x $ENV{SHELL} ? $ENV{SHELL} : DEF_BASH_PROG;
119 + my $ftp_prog = -x DEF_FTP_PROG ? DEF_FTP_PROG : '';
120 + my $gpg_prog = -x DEF_GPG_PROG ? DEF_GPG_PROG : '';
121 + my $gzip_prog = -x DEF_GZIP_PROG ? DEF_GZIP_PROG : '';
122 + my $lynx_prog = -x DEF_LYNX_PROG ? DEF_LYNX_PROG : '';
123 + my $make_prog = -x DEF_MAKE_PROG ? DEF_MAKE_PROG : '';
124 + my $ncftpget_prog = -x DEF_NCFTPGET_PROG ? DEF_NCFTPGET_PROG : '';
125 + my $less_prog = -x DEF_LESS_PROG ? DEF_LESS_PROG : '';
126 + my $tar_prog = -x DEF_TAR_PROG ? DEF_TAR_PROG : '';
127 + my $unzip_prog = -x DEF_UNZIP_PROG ? DEF_UNZIP_PROG : '';
128 + my $wget_prog = -x DEF_WGET_PROG ? DEF_WGET_PROG : '';
129 +
130 + open CPANCONF, ">$cpan_cfg_file" or die "Couldn't create file '$cpan_cfg_file' : $!";
131 print CPANCONF <<"SHERE";
132
133 # This is CPAN.pm's systemwide configuration file. This file provides
134 @@ -789,28 +787,26 @@
135 1;
136 __END__
137
138 -
139 SHERE
140
141 - close(CPANCONF);
142 -
143 + close CPANCONF;
144 }
145
146 # Simple useful sub. returns md5 hexdigest of the given argument
147 # awaits a file name.
148 sub file_md5sum {
149 -
150 - my $file = $_[0];
151 -
152 - if ($verbose) {
153 - print "Computing MD5 Sum of $file\n";
154 - }
155 -
156 +
157 + my $file = $_[0];
158 +
159 + if ($verbose) {
160 + print "Computing MD5 Sum of $file\n";
161 + }
162 +
163 open(DIGIFILE, $file ) or die "Can't open '$file': $!";
164 my $md5digest = Digest::MD5->new->addfile(*DIGIFILE)->hexdigest;
165 close(DIGIFILE);
166 -
167 - return $md5digest;
168 +
169 + return $md5digest;
170 }
171
172 # Takes care of system's sanity
173 @@ -836,14 +832,14 @@
174
175 --list,-l This command generates a list of the Perl modules and ebuilds
176 handled by $0.
177 -
178 +
179 --search,-s Search CPAN for the given expression (similar to
180 the "m /EXPR/" from the CPAN Shell). Searches are
181 case insensitive.
182
183 --upgrade,-u Try to list and upgrade all Perl modules managed by $0.
184 It generate up-to-date ebuilds, then emerge then.
185 -
186 +
187 --verbose,-v Enable (some) verbose output.
188
189 USAGE
190
191
192 --
193 gentoo-perl@g.o mailing list