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];
31 This module contains defaults and heuristics for configuration
32 information for CPANPLUS. To change any of these values, please
33 see the documentation in C<CPANPLUS::Configure>.
35 Below you'll find a list of configuration types and keys, and
42 ### BAH! you can't have POD interleaved with a hash
43 ### declaration.. so declare every entry seperatedly :(
46 'blacklist' => [ 'ftp' ],
49 ### _source, _build and _mirror are supposed to be static
50 ### no changes should be needed unless pause/cpan changes
52 'hosts' => 'MIRRORED.BY',
53 'auth' => '01mailrc.txt.gz',
54 'stored' => 'sourcefiles',
55 'dslip' => '03modlist.data.gz',
57 'mod' => '02packages.details.txt.gz'
60 'plugins' => 'plugins',
64 'autobundle' => 'autobundle',
65 'autobundle_prefix' => 'Snapshot',
66 'autdir' => 'authors',
67 'install_log_dir' => 'install-logs',
71 'base' => 'authors/id/',
72 'auth' => 'authors/01mailrc.txt.gz',
73 'dslip' => 'modules/03modlist.data.gz',
74 'mod' => 'modules/02packages.details.txt.gz'
84 An array ref containing hosts entries to be queried for packages.
86 An example entry would like this:
89 'path' => '/pub/CPAN/',
90 'host' => 'ftp.cpan.org'
96 $Conf->{'conf'}->{'hosts'} = [
99 'path' => '/pub/CPAN/',
100 'host' => 'ftp.cpan.org'
105 'host' => 'www.cpan.org'
109 'path' => '/pub/CPAN/',
110 'host' => 'ftp.nl.uu.net'
114 'path' => '/pub/CPAN/',
115 'host' => 'cpan.valueclick.com'
119 'path' => '/pub/languages/perl/CPAN/',
120 'host' => 'ftp.funet.fi'
124 =item allow_build_interactivity
126 Boolean flag to indicate whether 'perl Makefile.PL' and similar
127 are run interactively or not. Defaults to 'true'.
131 $Conf->{'conf'}->{'allow_build_interactivity'} = 1;
135 The directory CPANPLUS keeps all it's build and state information in.
136 Defaults to ~/.cpanplus.
140 $Conf->{'conf'}->{'base'} = File::Spec->catdir(
141 __PACKAGE__->_home_dir, DOT_CPANPLUS );
145 Any flags to be passed to 'perl Build.PL'. See C<perldoc Module::Build>
146 for details. Defaults to an empty string.
150 $Conf->{'conf'}->{'buildflags'} = '';
154 Boolean flag to indicate whether or not to mail test results of module
155 installations to C<http://testers.cpan.org>. Defaults to 'false'.
159 $Conf->{'conf'}->{'cpantest'} = 0;
163 String holding an explicit mailserver to use when sending out emails
164 for C<http://testers.cpan.org>. An empty string will use your system
165 settings. Defaults to an empty string.
169 $Conf->{'conf'}->{'cpantest_mx'} = '';
173 Boolean flag to enable or disable extensive debuggging information.
178 $Conf->{'conf'}->{'debug'} = 0;
182 Default distribution type to use when building packages. See C<cpan2dist>
183 or C<CPANPLUS::Dist> for details. An empty string will not use any
184 package building software. Defaults to an empty string.
188 $Conf->{'conf'}->{'dist_type'} = '';
192 Email address to use for anonymous ftp access and as C<from> address
193 when sending emails. Defaults to an C<example.com> address.
197 $Conf->{'conf'}->{'email'} = DEFAULT_EMAIL;
201 String containing the directory where fetched archives should be
202 extracted. An empty string will use a directory under your C<base>
203 directory. Defaults to an empty string.
207 $Conf->{'conf'}->{'extractdir'} = '';
211 String containing the directory where fetched archives should be
212 stored. An empty string will use a directory under your C<base>
213 directory. Defaults to an empty string.
217 $Conf->{'conf'}->{'fetchdir'} = '';
221 Boolean indicating whether build failures, cache dirs etc should
222 be flushed after every operation or not. Defaults to 'true'.
226 $Conf->{'conf'}->{'flush'} = 1;
230 Boolean indicating whether files should be forcefully overwritten
231 if they exist, modules should be installed when they fail tests,
232 etc. Defaults to 'false'.
236 $Conf->{'conf'}->{'force'} = 0;
240 An array ref holding directories to be added to C<@INC> when CPANPLUS
241 starts up. Defaults to an empty array reference.
245 $Conf->{'conf'}->{'lib'} = [];
249 A string holding flags that will be passed to the C<make> program
250 when invoked. Defaults to an empty string.
254 $Conf->{'conf'}->{'makeflags'} = '';
258 A string holding flags that will be passed to C<perl Makefile.PL>
259 when invoked. Defaults to an empty string.
263 $Conf->{'conf'}->{'makemakerflags'} = '';
267 A boolean indicating whether or not md5 checks should be done when
268 an archive is fetched. Defaults to 'true' if you have C<Digest::MD5>
269 installed, 'false' otherwise.
273 $Conf->{'conf'}->{'md5'} = (
274 check_install( module => 'Digest::MD5' ) ? 1 : 0 );
278 A boolean indicating whether or not C<CPANPLUS>' source files should be
279 updated or not. Defaults to 'false'.
283 $Conf->{'conf'}->{'no_update'} = 0;
287 A boolean indicating whether or not to use passive ftp connections.
292 $Conf->{'conf'}->{'passive'} = 1;
296 A boolean indicating whether or not to prefer command line programs
297 over perl modules. Defaults to 'false' unless you do not have
298 C<Compress::Zlib> installed (as that would mean we could not extract
302 ### if we dont have c::zlib, we'll need to use /bin/tar or we
303 ### can not extract any files. Good time to change the default
304 $Conf->{'conf'}->{'prefer_bin'} =
305 (eval {require Compress::Zlib; 1} ? 0 : 1 );
307 =item prefer_makefile
309 A boolean indicating whether or not prefer a C<Makefile.PL> over a
310 C<Build.PL> file if both are present. Defaults to 'true'.
314 $Conf->{'conf'}->{'prefer_makefile'} = 1;
318 A digit indicating what to do when a package you are installing has a
319 prerequisite. Options are:
324 3 Ignore (dangerous, install will probably fail!)
326 The default is to ask.
330 $Conf->{'conf'}->{'prereqs'} = PREREQ_ASK;
334 A string holding the shell class you wish to start up when starting
335 C<CPANPLUS> in interactive mode.
337 Defaults to C<CPANPLUS::Shell::Default>, the default CPANPLUS shell.
341 $Conf->{'conf'}->{'shell'} = 'CPANPLUS::Shell::Default';
343 =item show_startup_tip
345 A boolean indicating whether or not to show start up tips in the
346 interactive shell. Defaults to 'true'.
350 $Conf->{'conf'}->{'show_startup_tip'} = 1;
354 A boolean indicating whether or not check signatures if packages are
355 signed. Defaults to 'true' if you have C<gpg> or C<Crypt::OpenPGP>
356 installed, 'false' otherwise.
360 $Conf->{'conf'}->{'signature'} = do {
361 (can_run('gpg') || check_install(module => 'Crypt::OpenPGP')) ?1:0 };
365 A boolean indicating whether or not to skip tests when installing modules.
370 $Conf->{'conf'}->{'skiptest'} = 0;
374 A boolean indicating whether or not to use C<Storable> to write compiled
375 source file information to disk. This makes for faster startup and look
376 up times, but takes extra diskspace. Defaults to 'true' if you have
377 C<Storable> installed and 'false' if you don't.
381 $Conf->{'conf'}->{'storable'} =
382 ( check_install( module => 'Storable' ) ? 1 : 0 );
386 Digit indicating the time before a fetch request times out (in seconds).
391 $Conf->{'conf'}->{'timeout'} = 300;
395 A boolean indicating whether or not C<CPANPLUS> runs in verbose mode.
396 Defaults to 'true' if you have the environment variable
397 C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise.
399 It is recommended you run with verbose enabled, but it is disabled
400 for historical reasons.
404 $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0;
406 =item write_install_log
408 A boolean indicating whether or not to write install logs after installing
409 a module using the interactive shell. Defaults to 'true'.
414 $Conf->{'conf'}->{'write_install_logs'} = 1;
418 =head2 Section 'program'
422 ### Paths get stripped of whitespace on win32 in the constructor
423 ### sudo gets emptied if there's no need for it in the constructor
429 A string holding the path to your editor of choice. Defaults to your
430 $ENV{EDITOR}, $ENV{VISIUAL}, 'vi' or 'pico' programs, in that order.
434 $Conf->{'program'}->{'editor'} = do {
435 $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
436 can_run('vi') || can_run('pico')
441 A string holding the path to your C<make> binary. Looks for the C<make>
442 program used to build perl or failing that, a C<make> in your path.
446 $Conf->{'program'}->{'make'} =
447 can_run($Config{'make'}) || can_run('make');
451 A string holding the path to your pager of choice. Defaults to your
452 $ENV{PAGER}, 'less' or 'more' programs, in that order.
456 $Conf->{'program'}->{'pager'} =
457 $ENV{'PAGER'} || can_run('less') || can_run('more');
459 ### no one uses this feature anyway, and it's only working for EU::MM
460 ### and not for module::build
465 A string holding the path to your login shell of choice. Defaults to your
466 $ENV{SHELL} setting, or $ENV{COMSPEC} on Windows.
470 $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32'
476 A string holding the path to your C<sudo> binary if your install path
477 requires super user permissions. Looks for C<sudo> in your path, or
478 remains empty if you do not require super user permissiosn to install.
482 $Conf->{'program'}->{'sudo'} = do {
483 $> # check for all install dirs!
484 # installsiteman3dir is a 5.8'ism.. don't check
486 ? ( -w $Config{'installsitelib'} &&
487 ( defined $Config{'installsiteman3dir'} &&
488 -w $Config{'installsiteman3dir'}
490 -w $Config{'installsitebin'}
499 A string holding the path to the C<cpanp-run-perl> utility bundled
500 with CPANPLUS, which is used to enable autoflushing in spawned processes.
504 ### perlwrapper that allows us to turn on autoflushing
505 $Conf->{'program'}->{'perlwrapper'} = sub {
506 my $name = 'cpanp-run-perl';
510 my $ver = $Config::Config{version};
512 ### if we are running with 'versiononly' enabled,
513 ### all binaries will have the perlversion appended
514 ### ie, cpanp will become cpanp5.9.5
515 ### so prefer the versioned binary in that case
516 $Config::Config{versiononly}
517 ? ($name.$ver, $name)
518 : ($name, $name.$ver);
522 BIN: for my $bin (@bins) {
524 ### parallel to your cpanp/cpanp-boxed
525 my $maybe = File::Spec->rel2abs(
526 File::Spec->catdir( dirname($0), $bin )
528 $path = $maybe and last BIN if -f $maybe;
530 ### parallel to your CPANPLUS.pm:
531 ### $INC{cpanplus}/../bin/cpanp-run-perl
532 $maybe = File::Spec->rel2abs(
534 dirname($INC{'CPANPLUS.pm'}),
540 $path = $maybe and last BIN if -f $maybe;
542 ### you installed CPANPLUS in a custom prefix,
543 ### so go paralel to /that/. PREFIX=/tmp/cp
544 ### would put cpanp-run-perl in /tmp/cp/bin and
546 ### /tmp/cp/lib/perl5/site_perl/5.8.8
547 $maybe = File::Spec->rel2abs(
549 dirname( $INC{'CPANPLUS.pm'} ),
550 '..', '..', '..', '..', # 4x updir
555 $path = $maybe and last BIN if -f $maybe;
557 ### in your path -- take this one last, the
558 ### previous two assume extracted tarballs
560 ### note that we don't use 'can_run' as it's
561 ### not an executable, just a wrapper...
562 for my $dir (split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
565 $maybe = File::Spec->catfile( $dir, $bin );
566 $path = $maybe and last BIN if -f $maybe;
570 ### we should have a $path by now ideally, if so return it
571 return $path if defined $path;
573 ### if not, warn about it and give sensible default.
574 ### XXX try to be a no-op instead then..
575 ### cross your fingers...
576 ### pass '-P' to perl: "run program through C
577 ### preprocessor before compilation"
579 "Could not find the '%1' in your path".
580 "--this may be a problem.\n".
581 "Please locate this program and set ".
582 "your '%2' config entry to its path.\n",
594 my $obj = $class->SUPER::new;
596 $obj->mk_accessors( keys %$Conf );
598 for my $acc ( keys %$Conf ) {
599 my $subobj = Object::Accessor->new;
600 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
602 ### read in all the settings from the sub accessors;
603 for my $subacc ( $subobj->ls_accessors ) {
604 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
607 ### now store it in the parent object
608 $obj->$acc( $subobj );
611 $obj->_clean_up_paths;
613 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
619 sub _clean_up_paths {
622 ### clean up paths if we are on win32
623 if( $^O eq 'MSWin32' ) {
624 for my $pgm ( $self->program->ls_accessors ) {
625 $self->program->$pgm(
626 Win32::GetShortPathName( $self->program->$pgm )
627 ) if $self->program->$pgm and $self->program->$pgm =~ /\s+/;
640 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
644 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
648 The CPAN++ interface (of which this module is a part of) is copyright (c)
649 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
651 This library is free software; you may redistribute and/or modify it
652 under the same terms as Perl itself.
656 L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure>
661 # c-indentation-style: bsd
663 # indent-tabs-mode: nil
665 # vim: expandtab shiftwidth=4: