1 package CPANPLUS::Config;
6 use base 'Object::Accessor';
8 use base 'CPANPLUS::Internals::Utils';
15 use CPANPLUS::Internals::Constants;
17 use File::Basename qw[dirname];
18 use IPC::Cmd qw[can_run];
19 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
20 use Module::Load::Conditional qw[check_install];
24 'blacklist' => [ 'ftp' ],
31 'path' => '/pub/CPAN/',
32 'host' => 'ftp.cpan.org'
37 'host' => 'www.cpan.org'
41 'path' => '/pub/CPAN/',
42 'host' => 'ftp.nl.uu.net'
46 'path' => '/pub/CPAN/',
47 'host' => 'cpan.valueclick.com'
51 'path' => '/pub/languages/perl/CPAN/',
52 'host' => 'ftp.funet.fi'
55 'allow_build_interactivity' => 1,
56 'base' => File::Spec->catdir(
57 __PACKAGE__->_home_dir, DOT_CPANPLUS ),
63 'email' => DEFAULT_EMAIL,
70 'makemakerflags' => '',
72 check_install( module => 'Digest::MD5' ) ? 1 : 0 ),
75 ### if we dont have c::zlib, we'll need to use /bin/tar or we
76 ### can not extract any files. Good time to change the default
77 'prefer_bin' => (eval {require Compress::Zlib; 1}?0:1),
78 'prefer_makefile' => 1,
79 'prereqs' => PREREQ_ASK,
80 'shell' => 'CPANPLUS::Shell::Default',
81 'show_startup_tip' => 1,
82 'signature' => ( (can_run( 'gpg' ) ||
83 check_install( module => 'Crypt::OpenPGP' ))?1:0 ),
86 check_install( module => 'Storable' ) ? 1 : 0 ),
88 'verbose' => $ENV{PERL5_CPANPLUS_VERBOSE} || 0,
89 'write_install_logs' => 1,
91 ### Paths get stripped of whitespace on win32 in the constructor
92 ### sudo gets emptied if there's no need for it in the constructor
94 'editor' => ( $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
95 can_run('vi') || can_run('pico')
97 'make' => ( can_run($Config{'make'}) || can_run('make') ),
98 'pager' => ( $ENV{'PAGER'} || can_run('less') || can_run('more') ),
99 ### no one uses this feature anyway, and it's only working for EU::MM
100 ### and not for module::build
102 'shell' => ( $^O eq 'MSWin32' ? $ENV{COMSPEC} : $ENV{SHELL} ),
103 'sudo' => ( $> # check for all install dirs!
104 # installsiteman3dir is a 5.8'ism.. don't check
106 ? ( -w $Config{'installsitelib'} &&
107 ( defined $Config{'installsiteman3dir'} &&
108 -w $Config{'installsiteman3dir'}
110 -w $Config{'installsitebin'}
116 ### perlwrapper that allows us to turn on autoflushing
117 'perlwrapper' => sub{
118 my $name = 'cpanp-run-perl';
122 my $ver = $Config::Config{version};
124 ### if we are running with 'versiononly' enabled,
125 ### all binaries will have the perlversion appended
126 ### ie, cpanp will become cpanp5.9.5
127 ### so prefer the versioned binary in that case
128 $Config::Config{versiononly}
129 ? ($name.$ver, $name)
130 : ($name, $name.$ver);
134 BIN: for my $bin (@bins) {
136 ### parallel to your cpanp/cpanp-boxed
137 my $maybe = File::Spec->rel2abs(
138 File::Spec->catdir( dirname($0), $bin )
140 $path = $maybe and last BIN if -f $maybe;
142 ### parallel to your CPANPLUS.pm:
143 ### $INC{cpanplus}/../bin/cpanp-run-perl
144 $maybe = File::Spec->rel2abs(
146 dirname($INC{'CPANPLUS.pm'}),
152 $path = $maybe and last BIN if -f $maybe;
154 ### you installed CPANPLUS in a custom prefix,
155 ### so go paralel to /that/. PREFIX=/tmp/cp
156 ### would put cpanp-run-perl in /tmp/cp/bin and
158 ### /tmp/cp/lib/perl5/site_perl/5.8.8
159 $maybe = File::Spec->rel2abs(
161 dirname( $INC{'CPANPLUS.pm'} ),
162 '..', '..', '..', '..', # 4x updir
167 $path = $maybe and last BIN if -f $maybe;
169 ### in your path -- take this one last, the
170 ### previous two assume extracted tarballs
172 ### note that we don't use 'can_run' as it's
173 ### not an executable, just a wrapper...
174 for my $dir (split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
177 $maybe = File::Spec->catfile( $dir, $bin );
178 $path = $maybe and last BIN if -f $maybe;
182 ### we should have a $path by now ideally, if so return it
183 return $path if defined $path;
185 ### if not, warn about it and give sensible default.
186 ### XXX try to be a no-op instead then..
187 ### cross your fingers...
188 ### pass '-P' to perl: "run program through C
189 ### preprocessor before compilation"
191 "Could not find the '%1' in your path".
192 "--this may be a problem.\n".
193 "Please locate this program and set ".
194 "your '%1' config entry to its path.\n".
195 "Attempting to provide a reasonable ".
203 ### _source, _build and _mirror are supposed to be static
204 ### no changes should be needed unless pause/cpan changes
206 'hosts' => 'MIRRORED.BY',
207 'auth' => '01mailrc.txt.gz',
208 'stored' => 'sourcefiles',
209 'dslip' => '03modlist.data.gz',
211 'mod' => '02packages.details.txt.gz'
214 'plugins' => 'plugins',
218 'autobundle' => 'autobundle',
219 'autobundle_prefix' => 'Snapshot',
220 'autdir' => 'authors',
221 'install_log_dir' => 'install-logs',
225 'base' => 'authors/id/',
226 'auth' => 'authors/01mailrc.txt.gz',
227 'dslip' => 'modules/03modlist.data.gz',
228 'mod' => 'modules/02packages.details.txt.gz'
234 my $obj = $class->SUPER::new;
236 $obj->mk_accessors( keys %$Conf );
238 for my $acc ( keys %$Conf ) {
239 my $subobj = Object::Accessor->new;
240 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
242 ### read in all the settings from the sub accessors;
243 for my $subacc ( $subobj->ls_accessors ) {
244 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
247 ### now store it in the parent object
248 $obj->$acc( $subobj );
251 $obj->_clean_up_paths;
253 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
259 sub _clean_up_paths {
262 ### clean up paths if we are on win32
263 if( $^O eq 'MSWin32' ) {
264 for my $pgm ( $self->program->ls_accessors ) {
265 $self->program->$pgm(
266 Win32::GetShortPathName( $self->program->$pgm )
267 ) if $self->program->$pgm =~ /\s+/;