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 ### conf object via CPANPLUS::Backend;
32 $cb = CPANPLUS::Backend->new;
33 $conf = $cb->configure_object;
35 ### or as a standalone object
36 $conf = CPANPLUS::Configure->new;
38 ### values in 'conf' section
39 $verbose = $conf->get_conf( 'verbose' );
40 $conf->set_conf( verbose => 1 );
42 ### values in 'program' section
43 $editor = $conf->get_program( 'editor' );
44 $conf->set_program( editor => '/bin/vi' );
48 This module contains defaults and heuristics for configuration
49 information for CPANPLUS. To change any of these values, please
50 see the documentation in C<CPANPLUS::Configure>.
52 Below you'll find a list of configuration types and keys, and
59 ### BAH! you can't have POD interleaved with a hash
60 ### declaration.. so declare every entry seperatedly :(
63 'blacklist' => [ 'ftp' ],
66 ### _source, _build and _mirror are supposed to be static
67 ### no changes should be needed unless pause/cpan changes
69 'hosts' => 'MIRRORED.BY',
70 'auth' => '01mailrc.txt.gz',
71 'stored' => 'sourcefiles',
72 'dslip' => '03modlist.data.gz',
74 'mod' => '02packages.details.txt.gz',
75 'custom_index' => 'packages.txt',
78 'plugins' => 'plugins',
82 'autobundle' => 'autobundle',
83 'autobundle_prefix' => 'Snapshot',
84 'autdir' => 'authors',
85 'install_log_dir' => 'install-logs',
86 'custom_sources' => 'custom-sources',
90 'base' => 'authors/id/',
91 'auth' => 'authors/01mailrc.txt.gz',
92 'dslip' => 'modules/03modlist.data.gz',
93 'mod' => 'modules/02packages.details.txt.gz'
103 An array ref containing hosts entries to be queried for packages.
105 An example entry would like this:
108 'path' => '/pub/CPAN/',
109 'host' => 'ftp.cpan.org'
114 ### default host list
115 $Conf->{'conf'}->{'hosts'} = [
118 'path' => '/pub/CPAN/',
119 'host' => 'ftp.cpan.org'
124 'host' => 'www.cpan.org'
128 'path' => '/pub/CPAN/',
129 'host' => 'ftp.nl.uu.net'
133 'path' => '/pub/CPAN/',
134 'host' => 'cpan.valueclick.com'
138 'path' => '/pub/languages/perl/CPAN/',
139 'host' => 'ftp.funet.fi'
143 =item allow_build_interactivity
145 Boolean flag to indicate whether 'perl Makefile.PL' and similar
146 are run interactively or not. Defaults to 'true'.
150 $Conf->{'conf'}->{'allow_build_interactivity'} = 1;
154 The directory CPANPLUS keeps all its build and state information in.
155 Defaults to ~/.cpanplus.
159 $Conf->{'conf'}->{'base'} = File::Spec->catdir(
160 __PACKAGE__->_home_dir, DOT_CPANPLUS );
164 Any flags to be passed to 'perl Build.PL'. See C<perldoc Module::Build>
165 for details. Defaults to an empty string.
169 $Conf->{'conf'}->{'buildflags'} = '';
173 Boolean flag to indicate whether or not to mail test results of module
174 installations to C<http://testers.cpan.org>. Defaults to 'false'.
178 $Conf->{'conf'}->{'cpantest'} = 0;
182 String holding an explicit mailserver to use when sending out emails
183 for C<http://testers.cpan.org>. An empty string will use your system
184 settings. Defaults to an empty string.
188 $Conf->{'conf'}->{'cpantest_mx'} = '';
192 Boolean flag to enable or disable extensive debuggging information.
197 $Conf->{'conf'}->{'debug'} = 0;
201 Default distribution type to use when building packages. See C<cpan2dist>
202 or C<CPANPLUS::Dist> for details. An empty string will not use any
203 package building software. Defaults to an empty string.
207 $Conf->{'conf'}->{'dist_type'} = '';
211 Email address to use for anonymous ftp access and as C<from> address
212 when sending emails. Defaults to an C<example.com> address.
216 $Conf->{'conf'}->{'email'} = DEFAULT_EMAIL;
218 =item enable_custom_sources
220 Boolean flag indicating whether custom sources should be enabled or
221 not. See the C<CUSTOM MODULE SOURCES> in C<CPANPLUS::Backend> for
222 details on how to use them.
228 ### this addresses #32248 which requests a possibillity to
229 ### turn off custom sources
230 $Conf->{'conf'}->{'enable_custom_sources'} = 1;
234 String containing the directory where fetched archives should be
235 extracted. An empty string will use a directory under your C<base>
236 directory. Defaults to an empty string.
240 $Conf->{'conf'}->{'extractdir'} = '';
244 String containing the directory where fetched archives should be
245 stored. An empty string will use a directory under your C<base>
246 directory. Defaults to an empty string.
250 $Conf->{'conf'}->{'fetchdir'} = '';
254 Boolean indicating whether build failures, cache dirs etc should
255 be flushed after every operation or not. Defaults to 'true'.
259 $Conf->{'conf'}->{'flush'} = 1;
263 Boolean indicating whether files should be forcefully overwritten
264 if they exist, modules should be installed when they fail tests,
265 etc. Defaults to 'false'.
269 $Conf->{'conf'}->{'force'} = 0;
273 An array ref holding directories to be added to C<@INC> when CPANPLUS
274 starts up. Defaults to an empty array reference.
278 $Conf->{'conf'}->{'lib'} = [];
282 A string holding flags that will be passed to the C<make> program
283 when invoked. Defaults to an empty string.
287 $Conf->{'conf'}->{'makeflags'} = '';
291 A string holding flags that will be passed to C<perl Makefile.PL>
292 when invoked. Defaults to an empty string.
296 $Conf->{'conf'}->{'makemakerflags'} = '';
300 A boolean indicating whether or not md5 checks should be done when
301 an archive is fetched. Defaults to 'true' if you have C<Digest::MD5>
302 installed, 'false' otherwise.
306 $Conf->{'conf'}->{'md5'} = (
307 check_install( module => 'Digest::MD5' ) ? 1 : 0 );
311 A boolean indicating whether or not C<CPANPLUS>' source files should be
312 updated or not. Defaults to 'false'.
316 $Conf->{'conf'}->{'no_update'} = 0;
320 A boolean indicating whether or not to use passive ftp connections.
325 $Conf->{'conf'}->{'passive'} = 1;
329 A boolean indicating whether or not to prefer command line programs
330 over perl modules. Defaults to 'false' unless you do not have
331 C<Compress::Zlib> installed (as that would mean we could not extract
335 ### if we dont have c::zlib, we'll need to use /bin/tar or we
336 ### can not extract any files. Good time to change the default
337 $Conf->{'conf'}->{'prefer_bin'} =
338 (eval {require Compress::Zlib; 1} ? 0 : 1 );
340 =item prefer_makefile
342 A boolean indicating whether or not prefer a C<Makefile.PL> over a
343 C<Build.PL> file if both are present. Defaults to 'true'.
347 $Conf->{'conf'}->{'prefer_makefile'} = 1;
351 A digit indicating what to do when a package you are installing has a
352 prerequisite. Options are:
357 3 Ignore (dangerous, install will probably fail!)
359 The default is to ask.
363 $Conf->{'conf'}->{'prereqs'} = PREREQ_ASK;
367 A string holding the shell class you wish to start up when starting
368 C<CPANPLUS> in interactive mode.
370 Defaults to C<CPANPLUS::Shell::Default>, the default CPANPLUS shell.
374 $Conf->{'conf'}->{'shell'} = 'CPANPLUS::Shell::Default';
376 =item show_startup_tip
378 A boolean indicating whether or not to show start up tips in the
379 interactive shell. Defaults to 'true'.
383 $Conf->{'conf'}->{'show_startup_tip'} = 1;
387 A boolean indicating whether or not check signatures if packages are
388 signed. Defaults to 'true' if you have C<gpg> or C<Crypt::OpenPGP>
389 installed, 'false' otherwise.
393 $Conf->{'conf'}->{'signature'} = do {
394 check_install( module => 'Module::Signature', version => '0.06' )
395 and ( can_run('gpg') ||
396 check_install(module => 'Crypt::OpenPGP')
402 A boolean indicating whether or not to skip tests when installing modules.
407 $Conf->{'conf'}->{'skiptest'} = 0;
411 A boolean indicating whether or not to use C<Storable> to write compiled
412 source file information to disk. This makes for faster startup and look
413 up times, but takes extra diskspace. Defaults to 'true' if you have
414 C<Storable> installed and 'false' if you don't.
418 $Conf->{'conf'}->{'storable'} =
419 ( check_install( module => 'Storable' ) ? 1 : 0 );
423 Digit indicating the time before a fetch request times out (in seconds).
428 $Conf->{'conf'}->{'timeout'} = 300;
432 A boolean indicating whether or not C<CPANPLUS> runs in verbose mode.
433 Defaults to 'true' if you have the environment variable
434 C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise.
436 It is recommended you run with verbose enabled, but it is disabled
437 for historical reasons.
441 $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0;
443 =item write_install_log
445 A boolean indicating whether or not to write install logs after installing
446 a module using the interactive shell. Defaults to 'true'.
451 $Conf->{'conf'}->{'write_install_logs'} = 1;
455 Class to use as the source engine, which is generally a subclass of
456 C<CPANPLUS::Internals::Source>. Default to C<CPANPLUS::Internals::Source::Memory>.
460 $Conf->{'conf'}->{'source_engine'} = DEFAULT_SOURCE_ENGINE;
462 =item cpantest_reporter_args
464 A hashref of key => value pairs that are passed to the constructor
465 of C<Test::Reporter>. If you'd want to enable TLS for example, you'd
468 { transport => 'Net::SMTP::TLS',
469 transport_args => [ User => 'Joe', Password => '123' ],
474 $Conf->{'conf'}->{'cpantest_reporter_args'} = {};
478 =head2 Section 'program'
482 ### Paths get stripped of whitespace on win32 in the constructor
483 ### sudo gets emptied if there's no need for it in the constructor
489 A string holding the path to your editor of choice. Defaults to your
490 $ENV{EDITOR}, $ENV{VISUAL}, 'vi' or 'pico' programs, in that order.
494 $Conf->{'program'}->{'editor'} = do {
495 $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
496 can_run('vi') || can_run('pico')
501 A string holding the path to your C<make> binary. Looks for the C<make>
502 program used to build perl or failing that, a C<make> in your path.
506 $Conf->{'program'}->{'make'} =
507 can_run($Config{'make'}) || can_run('make');
511 A string holding the path to your pager of choice. Defaults to your
512 $ENV{PAGER}, 'less' or 'more' programs, in that order.
516 $Conf->{'program'}->{'pager'} =
517 $ENV{'PAGER'} || can_run('less') || can_run('more');
519 ### no one uses this feature anyway, and it's only working for EU::MM
520 ### and not for module::build
525 A string holding the path to your login shell of choice. Defaults to your
526 $ENV{SHELL} setting, or $ENV{COMSPEC} on Windows.
530 $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32'
536 A string holding the path to your C<sudo> binary if your install path
537 requires super user permissions. Looks for C<sudo> in your path, or
538 remains empty if you do not require super user permissiosn to install.
542 $Conf->{'program'}->{'sudo'} = do {
543 ### let's assume you dont need sudo,
544 ### unless one of the below criteria tells us otherwise
547 ### you're a normal user, you might need sudo
550 ### check for all install dirs!
551 ### you have write permissions to the installdir,
552 ### you don't need sudo
553 if( -w $Config{'installsitelib'} && -w $Config{'installsitebin'} ) {
555 ### installsiteman3dir is a 5.8'ism.. don't check
557 if( defined $Config{'installsiteman3dir'} ) {
558 $sudo = -w $Config{'installsiteman3dir'}
565 ### you have PERL_MM_OPT set to some alternate
566 ### install place. You probably have write permissions
568 } elsif ( $ENV{'PERL_MM_OPT'} and
569 $ENV{'PERL_MM_OPT'} =~ /INSTALL|LIB|PREFIX/
573 ### you probably don't have write permissions
575 $sudo = can_run('sudo');
579 ### and return the value
585 A string holding the path to the C<cpanp-run-perl> utility bundled
586 with CPANPLUS, which is used to enable autoflushing in spawned processes.
590 ### perlwrapper that allows us to turn on autoflushing
591 $Conf->{'program'}->{'perlwrapper'} = sub {
592 my $name = 'cpanp-run-perl';
596 my $ver = $Config::Config{version};
598 ### if we are running with 'versiononly' enabled,
599 ### all binaries will have the perlversion appended
600 ### ie, cpanp will become cpanp5.9.5
601 ### so prefer the versioned binary in that case
602 $Config::Config{versiononly}
603 ? ($name.$ver, $name)
604 : ($name, $name.$ver);
607 ### patch from Steve Hay Fri 29 Jun 2007 14:26:02 GMT+02:00
608 ### Msg-Id: <4684FA5A.7030506@uk.radan.com>
609 ### look for files with a ".bat" extension as well on Win32
610 @bins = map { $_, "$_.bat" } @bins if $^O eq 'MSWin32';
613 BIN: for my $bin (@bins) {
615 ### parallel to your cpanp/cpanp-boxed
616 my $maybe = File::Spec->rel2abs(
617 File::Spec->catfile( dirname($0), $bin )
619 $path = $maybe and last BIN if -f $maybe;
621 ### parallel to your CPANPLUS.pm:
622 ### $INC{cpanplus}/../bin/cpanp-run-perl
623 $maybe = File::Spec->rel2abs(
625 dirname($INC{'CPANPLUS.pm'}),
631 $path = $maybe and last BIN if -f $maybe;
633 ### you installed CPANPLUS in a custom prefix,
634 ### so go paralel to /that/. PREFIX=/tmp/cp
635 ### would put cpanp-run-perl in /tmp/cp/bin and
637 ### /tmp/cp/lib/perl5/site_perl/5.8.8
638 $maybe = File::Spec->rel2abs(
640 dirname( $INC{'CPANPLUS.pm'} ),
641 '..', '..', '..', '..', # 4x updir
646 $path = $maybe and last BIN if -f $maybe;
648 ### in your path -- take this one last, the
649 ### previous two assume extracted tarballs
651 ### note that we don't use 'can_run' as it's
652 ### not an executable, just a wrapper...
653 ### prefer anything that's found in the path paralel to your $^X
654 for my $dir (File::Spec->rel2abs( dirname($^X) ),
655 split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
659 ### On VMS the path could be in UNIX format, and we
660 ### currently need it to be in VMS format
661 $dir = VMS::Filespec::vmspath($dir) if ON_VMS;
663 $maybe = File::Spec->catfile( $dir, $bin );
664 $path = $maybe and last BIN if -f $maybe;
668 ### we should have a $path by now ideally, if so return it
669 return $path if defined $path;
671 ### if not, warn about it and give sensible default.
672 ### XXX try to be a no-op instead then..
673 ### cross your fingers...
674 ### pass '-P' to perl: "run program through C
675 ### preprocessor before compilation"
676 ### XXX using -P actually changes the way some Makefile.PLs
677 ### are executed, so don't do that... --kane
679 "Could not find the '%1' binary in your path".
680 "--this may be a problem.\n".
681 "Please locate this program and set ".
682 "your '%2' config entry to its path.\n".
683 "From the default shell, you can do this by typing:\n\n".
686 $name, 'perlwrapper',
687 's program perlwrapper FULL_PATH_TO_CPANP_RUN_PERL',
699 my $obj = $class->SUPER::new;
701 $obj->mk_accessors( keys %$Conf );
703 for my $acc ( keys %$Conf ) {
704 my $subobj = Object::Accessor->new;
705 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
707 ### read in all the settings from the sub accessors;
708 for my $subacc ( $subobj->ls_accessors ) {
709 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
712 ### now store it in the parent object
713 $obj->$acc( $subobj );
716 $obj->_clean_up_paths;
718 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
724 sub _clean_up_paths {
727 ### clean up paths if we are on win32
728 if( $^O eq 'MSWin32' ) {
729 for my $pgm ( $self->program->ls_accessors ) {
730 my $path = $self->program->$pgm;
732 ### paths with whitespace needs to be shortened
734 if ($path and $path =~ /\s+/) {
737 ### patch from Steve Hay, 13nd of June 2007
738 ### msg-id: <467012A4.6060705@uk.radan.com>
739 ### windows directories are not allowed to end with
740 ### a space, so any occurrence of '\w\s+/\w+' means
741 ### we're dealing with arguments, not directory
743 if ($path =~ /^(.*?)(\s+\/.*$)/) {
744 ($prog, $args) = ($1, $2);
746 ### otherwise, there are no arguments
748 ($prog, $args) = ($path, '');
751 $prog = Win32::GetShortPathName( $prog );
752 $self->program->$pgm( $prog . $args );
766 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
770 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
774 The CPAN++ interface (of which this module is a part of) is copyright (c)
775 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
777 This library is free software; you may redistribute and/or modify it
778 under the same terms as Perl itself.
782 L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure>
787 # c-indentation-style: bsd
789 # indent-tabs-mode: nil
791 # vim: expandtab shiftwidth=4: