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',
58 'custom_index' => 'packages.txt',
61 'plugins' => 'plugins',
65 'autobundle' => 'autobundle',
66 'autobundle_prefix' => 'Snapshot',
67 'autdir' => 'authors',
68 'install_log_dir' => 'install-logs',
69 'custom_sources' => 'custom-sources',
73 'base' => 'authors/id/',
74 'auth' => 'authors/01mailrc.txt.gz',
75 'dslip' => 'modules/03modlist.data.gz',
76 'mod' => 'modules/02packages.details.txt.gz'
86 An array ref containing hosts entries to be queried for packages.
88 An example entry would like this:
91 'path' => '/pub/CPAN/',
92 'host' => 'ftp.cpan.org'
98 $Conf->{'conf'}->{'hosts'} = [
101 'path' => '/pub/CPAN/',
102 'host' => 'ftp.cpan.org'
107 'host' => 'www.cpan.org'
111 'path' => '/pub/CPAN/',
112 'host' => 'ftp.nl.uu.net'
116 'path' => '/pub/CPAN/',
117 'host' => 'cpan.valueclick.com'
121 'path' => '/pub/languages/perl/CPAN/',
122 'host' => 'ftp.funet.fi'
126 =item allow_build_interactivity
128 Boolean flag to indicate whether 'perl Makefile.PL' and similar
129 are run interactively or not. Defaults to 'true'.
133 $Conf->{'conf'}->{'allow_build_interactivity'} = 1;
137 The directory CPANPLUS keeps all it's build and state information in.
138 Defaults to ~/.cpanplus.
142 $Conf->{'conf'}->{'base'} = File::Spec->catdir(
143 __PACKAGE__->_home_dir, DOT_CPANPLUS );
147 Any flags to be passed to 'perl Build.PL'. See C<perldoc Module::Build>
148 for details. Defaults to an empty string.
152 $Conf->{'conf'}->{'buildflags'} = '';
156 Boolean flag to indicate whether or not to mail test results of module
157 installations to C<http://testers.cpan.org>. Defaults to 'false'.
161 $Conf->{'conf'}->{'cpantest'} = 0;
165 String holding an explicit mailserver to use when sending out emails
166 for C<http://testers.cpan.org>. An empty string will use your system
167 settings. Defaults to an empty string.
171 $Conf->{'conf'}->{'cpantest_mx'} = '';
175 Boolean flag to enable or disable extensive debuggging information.
180 $Conf->{'conf'}->{'debug'} = 0;
184 Default distribution type to use when building packages. See C<cpan2dist>
185 or C<CPANPLUS::Dist> for details. An empty string will not use any
186 package building software. Defaults to an empty string.
190 $Conf->{'conf'}->{'dist_type'} = '';
194 Email address to use for anonymous ftp access and as C<from> address
195 when sending emails. Defaults to an C<example.com> address.
199 $Conf->{'conf'}->{'email'} = DEFAULT_EMAIL;
203 String containing the directory where fetched archives should be
204 extracted. An empty string will use a directory under your C<base>
205 directory. Defaults to an empty string.
209 $Conf->{'conf'}->{'extractdir'} = '';
213 String containing the directory where fetched archives should be
214 stored. An empty string will use a directory under your C<base>
215 directory. Defaults to an empty string.
219 $Conf->{'conf'}->{'fetchdir'} = '';
223 Boolean indicating whether build failures, cache dirs etc should
224 be flushed after every operation or not. Defaults to 'true'.
228 $Conf->{'conf'}->{'flush'} = 1;
232 Boolean indicating whether files should be forcefully overwritten
233 if they exist, modules should be installed when they fail tests,
234 etc. Defaults to 'false'.
238 $Conf->{'conf'}->{'force'} = 0;
242 An array ref holding directories to be added to C<@INC> when CPANPLUS
243 starts up. Defaults to an empty array reference.
247 $Conf->{'conf'}->{'lib'} = [];
251 A string holding flags that will be passed to the C<make> program
252 when invoked. Defaults to an empty string.
256 $Conf->{'conf'}->{'makeflags'} = '';
260 A string holding flags that will be passed to C<perl Makefile.PL>
261 when invoked. Defaults to an empty string.
265 $Conf->{'conf'}->{'makemakerflags'} = '';
269 A boolean indicating whether or not md5 checks should be done when
270 an archive is fetched. Defaults to 'true' if you have C<Digest::MD5>
271 installed, 'false' otherwise.
275 $Conf->{'conf'}->{'md5'} = (
276 check_install( module => 'Digest::MD5' ) ? 1 : 0 );
280 A boolean indicating whether or not C<CPANPLUS>' source files should be
281 updated or not. Defaults to 'false'.
285 $Conf->{'conf'}->{'no_update'} = 0;
289 A boolean indicating whether or not to use passive ftp connections.
294 $Conf->{'conf'}->{'passive'} = 1;
298 A boolean indicating whether or not to prefer command line programs
299 over perl modules. Defaults to 'false' unless you do not have
300 C<Compress::Zlib> installed (as that would mean we could not extract
304 ### if we dont have c::zlib, we'll need to use /bin/tar or we
305 ### can not extract any files. Good time to change the default
306 $Conf->{'conf'}->{'prefer_bin'} =
307 (eval {require Compress::Zlib; 1} ? 0 : 1 );
309 =item prefer_makefile
311 A boolean indicating whether or not prefer a C<Makefile.PL> over a
312 C<Build.PL> file if both are present. Defaults to 'true'.
316 $Conf->{'conf'}->{'prefer_makefile'} = 1;
320 A digit indicating what to do when a package you are installing has a
321 prerequisite. Options are:
326 3 Ignore (dangerous, install will probably fail!)
328 The default is to ask.
332 $Conf->{'conf'}->{'prereqs'} = PREREQ_ASK;
336 A string holding the shell class you wish to start up when starting
337 C<CPANPLUS> in interactive mode.
339 Defaults to C<CPANPLUS::Shell::Default>, the default CPANPLUS shell.
343 $Conf->{'conf'}->{'shell'} = 'CPANPLUS::Shell::Default';
345 =item show_startup_tip
347 A boolean indicating whether or not to show start up tips in the
348 interactive shell. Defaults to 'true'.
352 $Conf->{'conf'}->{'show_startup_tip'} = 1;
356 A boolean indicating whether or not check signatures if packages are
357 signed. Defaults to 'true' if you have C<gpg> or C<Crypt::OpenPGP>
358 installed, 'false' otherwise.
362 $Conf->{'conf'}->{'signature'} = do {
363 check_install( module => 'Module::Signature', version => '0.06' )
364 and ( can_run('gpg') ||
365 check_install(module => 'Crypt::OpenPGP')
371 A boolean indicating whether or not to skip tests when installing modules.
376 $Conf->{'conf'}->{'skiptest'} = 0;
380 A boolean indicating whether or not to use C<Storable> to write compiled
381 source file information to disk. This makes for faster startup and look
382 up times, but takes extra diskspace. Defaults to 'true' if you have
383 C<Storable> installed and 'false' if you don't.
387 $Conf->{'conf'}->{'storable'} =
388 ( check_install( module => 'Storable' ) ? 1 : 0 );
392 Digit indicating the time before a fetch request times out (in seconds).
397 $Conf->{'conf'}->{'timeout'} = 300;
401 A boolean indicating whether or not C<CPANPLUS> runs in verbose mode.
402 Defaults to 'true' if you have the environment variable
403 C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise.
405 It is recommended you run with verbose enabled, but it is disabled
406 for historical reasons.
410 $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0;
412 =item write_install_log
414 A boolean indicating whether or not to write install logs after installing
415 a module using the interactive shell. Defaults to 'true'.
420 $Conf->{'conf'}->{'write_install_logs'} = 1;
424 =head2 Section 'program'
428 ### Paths get stripped of whitespace on win32 in the constructor
429 ### sudo gets emptied if there's no need for it in the constructor
435 A string holding the path to your editor of choice. Defaults to your
436 $ENV{EDITOR}, $ENV{VISIUAL}, 'vi' or 'pico' programs, in that order.
440 $Conf->{'program'}->{'editor'} = do {
441 $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
442 can_run('vi') || can_run('pico')
447 A string holding the path to your C<make> binary. Looks for the C<make>
448 program used to build perl or failing that, a C<make> in your path.
452 $Conf->{'program'}->{'make'} =
453 can_run($Config{'make'}) || can_run('make');
457 A string holding the path to your pager of choice. Defaults to your
458 $ENV{PAGER}, 'less' or 'more' programs, in that order.
462 $Conf->{'program'}->{'pager'} =
463 $ENV{'PAGER'} || can_run('less') || can_run('more');
465 ### no one uses this feature anyway, and it's only working for EU::MM
466 ### and not for module::build
471 A string holding the path to your login shell of choice. Defaults to your
472 $ENV{SHELL} setting, or $ENV{COMSPEC} on Windows.
476 $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32'
482 A string holding the path to your C<sudo> binary if your install path
483 requires super user permissions. Looks for C<sudo> in your path, or
484 remains empty if you do not require super user permissiosn to install.
488 $Conf->{'program'}->{'sudo'} = do {
490 ### let's assume you dont need sudo,
491 ### unless one of the below criteria tells us otherwise
494 ### you're a normal user, you might need sudo
497 ### check for all install dirs!
498 ### installsiteman3dir is a 5.8'ism.. don't check
500 ### you have write permissions to the installdir,
501 ### you don't need sudo
502 if( -w $Config{'installsitelib'} &&
503 ( defined $Config{'installsiteman3dir'} &&
504 -w $Config{'installsiteman3dir'}
505 ) && -w $Config{'installsitebin'}
509 ### you have PERL_MM_OPT set to some alternate
510 ### install place. You probably have write permissions
512 } elsif ( $ENV{'PERL_MM_OPT'} and
513 $ENV{'PERL_MM_OPT'} =~ /INSTALL|LIB|PREFIX/
517 ### you probably don't have write permissions
519 $sudo = can_run('sudo');
523 ### and return the value
529 A string holding the path to the C<cpanp-run-perl> utility bundled
530 with CPANPLUS, which is used to enable autoflushing in spawned processes.
534 ### perlwrapper that allows us to turn on autoflushing
535 $Conf->{'program'}->{'perlwrapper'} = sub {
536 my $name = 'cpanp-run-perl';
540 my $ver = $Config::Config{version};
542 ### if we are running with 'versiononly' enabled,
543 ### all binaries will have the perlversion appended
544 ### ie, cpanp will become cpanp5.9.5
545 ### so prefer the versioned binary in that case
546 $Config::Config{versiononly}
547 ? ($name.$ver, $name)
548 : ($name, $name.$ver);
551 ### patch from Steve Hay Fri 29 Jun 2007 14:26:02 GMT+02:00
552 ### Msg-Id: <4684FA5A.7030506@uk.radan.com>
553 ### look for files with a ".bat" extension as well on Win32
554 @bins = map { $_, "$_.bat" } @bins if $^O eq 'MSWin32';
557 BIN: for my $bin (@bins) {
559 ### parallel to your cpanp/cpanp-boxed
560 my $maybe = File::Spec->rel2abs(
561 File::Spec->catfile( dirname($0), $bin )
563 $path = $maybe and last BIN if -f $maybe;
565 ### parallel to your CPANPLUS.pm:
566 ### $INC{cpanplus}/../bin/cpanp-run-perl
567 $maybe = File::Spec->rel2abs(
569 dirname($INC{'CPANPLUS.pm'}),
575 $path = $maybe and last BIN if -f $maybe;
577 ### you installed CPANPLUS in a custom prefix,
578 ### so go paralel to /that/. PREFIX=/tmp/cp
579 ### would put cpanp-run-perl in /tmp/cp/bin and
581 ### /tmp/cp/lib/perl5/site_perl/5.8.8
582 $maybe = File::Spec->rel2abs(
584 dirname( $INC{'CPANPLUS.pm'} ),
585 '..', '..', '..', '..', # 4x updir
590 $path = $maybe and last BIN if -f $maybe;
592 ### in your path -- take this one last, the
593 ### previous two assume extracted tarballs
595 ### note that we don't use 'can_run' as it's
596 ### not an executable, just a wrapper...
597 ### prefer anything that's found in the path paralel to your $^X
598 for my $dir (File::Spec->rel2abs( dirname($^X) ),
599 split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
603 ### On VMS the path could be in UNIX format, and we
604 ### currently need it to be in VMS format
605 $dir = VMS::Filespec::vmspath($dir) if ON_VMS;
607 $maybe = File::Spec->catfile( $dir, $bin );
608 $path = $maybe and last BIN if -f $maybe;
612 ### we should have a $path by now ideally, if so return it
613 return $path if defined $path;
615 ### if not, warn about it and give sensible default.
616 ### XXX try to be a no-op instead then..
617 ### cross your fingers...
618 ### pass '-P' to perl: "run program through C
619 ### preprocessor before compilation"
620 ### XXX using -P actually changes the way some Makefile.PLs
621 ### are executed, so don't do that... --kane
623 "Could not find the '%1' binary in your path".
624 "--this may be a problem.\n".
625 "Please locate this program and set ".
626 "your '%2' config entry to its path.\n".
627 "From the default shell, you can do this by typing:\n\n".
630 $name, 'perlwrapper',
631 's program perlwrapper FULL_PATH_TO_CPANP_RUN_PERL',
643 my $obj = $class->SUPER::new;
645 $obj->mk_accessors( keys %$Conf );
647 for my $acc ( keys %$Conf ) {
648 my $subobj = Object::Accessor->new;
649 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
651 ### read in all the settings from the sub accessors;
652 for my $subacc ( $subobj->ls_accessors ) {
653 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
656 ### now store it in the parent object
657 $obj->$acc( $subobj );
660 $obj->_clean_up_paths;
662 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
668 sub _clean_up_paths {
671 ### clean up paths if we are on win32
672 if( $^O eq 'MSWin32' ) {
673 for my $pgm ( $self->program->ls_accessors ) {
674 my $path = $self->program->$pgm;
676 ### paths with whitespace needs to be shortened
678 if ($path and $path =~ /\s+/) {
681 ### patch from Steve Hay, 13nd of June 2007
682 ### msg-id: <467012A4.6060705@uk.radan.com>
683 ### windows directories are not allowed to end with
684 ### a space, so any occurrence of '\w\s+/\w+' means
685 ### we're dealing with arguments, not directory
687 if ($path =~ /^(.*?)(\s+\/.*$)/) {
688 ($prog, $args) = ($1, $2);
690 ### otherwise, there are no arguments
692 ($prog, $args) = ($path, '');
695 $prog = Win32::GetShortPathName( $prog );
696 $self->program->$pgm( $prog . $args );
710 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
714 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
718 The CPAN++ interface (of which this module is a part of) is copyright (c)
719 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
721 This library is free software; you may redistribute and/or modify it
722 under the same terms as Perl itself.
726 L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure>
731 # c-indentation-style: bsd
733 # indent-tabs-mode: nil
735 # vim: expandtab shiftwidth=4: