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 separately :(
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'
129 'host' => 'cpan.hexten.net'
134 'host' => 'cpan.cpantesters.org'
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 possibility 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', unless
344 the perl version is at least 5.10.1 or appropriate versions of L<Module::Build>
345 and L<CPANPLUS::Dist::Build> are available.
349 $Conf->{'conf'}->{'prefer_makefile'} =
351 ( check_install( module => 'Module::Build', version => '0.32' ) and
352 check_install( module => INSTALLER_BUILD, version => '0.24' ) )
357 A digit indicating what to do when a package you are installing has a
358 prerequisite. Options are:
363 3 Ignore (dangerous, install will probably fail!)
365 The default is to ask.
369 $Conf->{'conf'}->{'prereqs'} = PREREQ_ASK;
373 A string holding the shell class you wish to start up when starting
374 C<CPANPLUS> in interactive mode.
376 Defaults to C<CPANPLUS::Shell::Default>, the default CPANPLUS shell.
380 $Conf->{'conf'}->{'shell'} = 'CPANPLUS::Shell::Default';
382 =item show_startup_tip
384 A boolean indicating whether or not to show start up tips in the
385 interactive shell. Defaults to 'true'.
389 $Conf->{'conf'}->{'show_startup_tip'} = 1;
393 A boolean indicating whether or not check signatures if packages are
394 signed. Defaults to 'true' if you have C<gpg> or C<Crypt::OpenPGP>
395 installed, 'false' otherwise.
399 $Conf->{'conf'}->{'signature'} = do {
400 check_install( module => 'Module::Signature', version => '0.06' )
401 and ( can_run('gpg') ||
402 check_install(module => 'Crypt::OpenPGP')
408 A boolean indicating whether or not to skip tests when installing modules.
413 $Conf->{'conf'}->{'skiptest'} = 0;
417 A boolean indicating whether or not to use C<Storable> to write compiled
418 source file information to disk. This makes for faster startup and look
419 up times, but takes extra diskspace. Defaults to 'true' if you have
420 C<Storable> installed and 'false' if you don't.
424 $Conf->{'conf'}->{'storable'} =
425 ( check_install( module => 'Storable' ) ? 1 : 0 );
429 Digit indicating the time before a fetch request times out (in seconds).
434 $Conf->{'conf'}->{'timeout'} = 300;
438 A boolean indicating whether or not C<CPANPLUS> runs in verbose mode.
439 Defaults to 'true' if you have the environment variable
440 C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise.
442 It is recommended you run with verbose enabled, but it is disabled
443 for historical reasons.
447 $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0;
449 =item write_install_log
451 A boolean indicating whether or not to write install logs after installing
452 a module using the interactive shell. Defaults to 'true'.
457 $Conf->{'conf'}->{'write_install_logs'} = 1;
461 Class to use as the source engine, which is generally a subclass of
462 C<CPANPLUS::Internals::Source>. Default to C<CPANPLUS::Internals::Source::Memory>.
466 $Conf->{'conf'}->{'source_engine'} = DEFAULT_SOURCE_ENGINE;
468 =item cpantest_reporter_args
470 A hashref of key => value pairs that are passed to the constructor
471 of C<Test::Reporter>. If you'd want to enable TLS for example, you'd
474 { transport => 'Net::SMTP::TLS',
475 transport_args => [ User => 'Joe', Password => '123' ],
480 $Conf->{'conf'}->{'cpantest_reporter_args'} = {};
484 =head2 Section 'program'
488 ### Paths get stripped of whitespace on win32 in the constructor
489 ### sudo gets emptied if there's no need for it in the constructor
495 A string holding the path to your editor of choice. Defaults to your
496 $ENV{EDITOR}, $ENV{VISUAL}, 'vi' or 'pico' programs, in that order.
500 $Conf->{'program'}->{'editor'} = do {
501 $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
502 can_run('vi') || can_run('pico')
507 A string holding the path to your C<make> binary. Looks for the C<make>
508 program used to build perl or failing that, a C<make> in your path.
512 $Conf->{'program'}->{'make'} =
513 can_run($Config{'make'}) || can_run('make');
517 A string holding the path to your pager of choice. Defaults to your
518 $ENV{PAGER}, 'less' or 'more' programs, in that order.
522 $Conf->{'program'}->{'pager'} =
523 $ENV{'PAGER'} || can_run('less') || can_run('more');
525 ### no one uses this feature anyway, and it's only working for EU::MM
526 ### and not for module::build
531 A string holding the path to your login shell of choice. Defaults to your
532 $ENV{SHELL} setting, or $ENV{COMSPEC} on Windows.
536 $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32'
542 A string holding the path to your C<sudo> binary if your install path
543 requires super user permissions. Looks for C<sudo> in your path, or
544 remains empty if you do not require super user permissions to install.
548 $Conf->{'program'}->{'sudo'} = do {
549 ### let's assume you dont need sudo,
550 ### unless one of the below criteria tells us otherwise
553 ### you're a normal user, you might need sudo
556 ### check for all install dirs!
557 ### you have write permissions to the installdir,
558 ### you don't need sudo
559 if( -w $Config{'installsitelib'} && -w $Config{'installsitebin'} ) {
561 ### installsiteman3dir is a 5.8'ism.. don't check
563 if( defined $Config{'installsiteman3dir'} ) {
564 $sudo = -w $Config{'installsiteman3dir'}
571 ### you have PERL_MM_OPT set to some alternate
572 ### install place. You probably have write permissions
574 } elsif ( $ENV{'PERL_MM_OPT'} and
575 $ENV{'PERL_MM_OPT'} =~ /INSTALL|LIB|PREFIX/
579 ### you probably don't have write permissions
581 $sudo = can_run('sudo');
585 ### and return the value
591 A string holding the path to the C<cpanp-run-perl> utility bundled
592 with CPANPLUS, which is used to enable autoflushing in spawned processes.
596 ### perlwrapper that allows us to turn on autoflushing
597 $Conf->{'program'}->{'perlwrapper'} = sub {
598 my $name = 'cpanp-run-perl';
602 my $ver = $Config::Config{version};
604 ### if we are running with 'versiononly' enabled,
605 ### all binaries will have the perlversion appended
606 ### ie, cpanp will become cpanp5.9.5
607 ### so prefer the versioned binary in that case
608 $Config::Config{versiononly}
609 ? ($name.$ver, $name)
610 : ($name, $name.$ver);
613 ### patch from Steve Hay Fri 29 Jun 2007 14:26:02 GMT+02:00
614 ### Msg-Id: <4684FA5A.7030506@uk.radan.com>
615 ### look for files with a ".bat" extension as well on Win32
616 @bins = map { $_, "$_.bat" } @bins if $^O eq 'MSWin32';
619 BIN: for my $bin (@bins) {
621 ### parallel to your cpanp/cpanp-boxed
622 my $maybe = File::Spec->rel2abs(
623 File::Spec->catfile( dirname($0), $bin )
625 $path = $maybe and last BIN if -f $maybe;
627 ### parallel to your CPANPLUS.pm:
628 ### $INC{cpanplus}/../bin/cpanp-run-perl
629 $maybe = File::Spec->rel2abs(
631 dirname($INC{'CPANPLUS.pm'}),
637 $path = $maybe and last BIN if -f $maybe;
639 ### you installed CPANPLUS in a custom prefix,
640 ### so go parallel to /that/. PREFIX=/tmp/cp
641 ### would put cpanp-run-perl in /tmp/cp/bin and
643 ### /tmp/cp/lib/perl5/site_perl/5.8.8
644 $maybe = File::Spec->rel2abs(
646 dirname( $INC{'CPANPLUS.pm'} ),
647 '..', '..', '..', '..', # 4x updir
652 $path = $maybe and last BIN if -f $maybe;
654 ### in your path -- take this one last, the
655 ### previous two assume extracted tarballs
657 ### note that we don't use 'can_run' as it's
658 ### not an executable, just a wrapper...
659 ### prefer anything that's found in the path paralel to your $^X
660 for my $dir (File::Spec->rel2abs( dirname($^X) ),
661 split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
665 ### On VMS the path could be in UNIX format, and we
666 ### currently need it to be in VMS format
667 $dir = VMS::Filespec::vmspath($dir) if ON_VMS;
669 $maybe = File::Spec->catfile( $dir, $bin );
670 $path = $maybe and last BIN if -f $maybe;
674 ### we should have a $path by now ideally, if so return it
675 return $path if defined $path;
677 ### if not, warn about it and give sensible default.
678 ### XXX try to be a no-op instead then..
679 ### cross your fingers...
680 ### pass '-P' to perl: "run program through C
681 ### preprocessor before compilation"
682 ### XXX using -P actually changes the way some Makefile.PLs
683 ### are executed, so don't do that... --kane
685 "Could not find the '%1' binary in your path".
686 "--this may be a problem.\n".
687 "Please locate this program and set ".
688 "your '%2' config entry to its path.\n".
689 "From the default shell, you can do this by typing:\n\n".
692 $name, 'perlwrapper',
693 's program perlwrapper FULL_PATH_TO_CPANP_RUN_PERL',
705 my $obj = $class->SUPER::new;
707 $obj->mk_accessors( keys %$Conf );
709 for my $acc ( keys %$Conf ) {
710 my $subobj = Object::Accessor->new;
711 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
713 ### read in all the settings from the sub accessors;
714 for my $subacc ( $subobj->ls_accessors ) {
715 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
718 ### now store it in the parent object
719 $obj->$acc( $subobj );
722 $obj->_clean_up_paths;
724 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
730 sub _clean_up_paths {
733 ### clean up paths if we are on win32
734 if( $^O eq 'MSWin32' ) {
735 for my $pgm ( $self->program->ls_accessors ) {
736 my $path = $self->program->$pgm;
738 ### paths with whitespace needs to be shortened
740 if ($path and $path =~ /\s+/) {
743 ### patch from Steve Hay, 13nd of June 2007
744 ### msg-id: <467012A4.6060705@uk.radan.com>
745 ### windows directories are not allowed to end with
746 ### a space, so any occurrence of '\w\s+/\w+' means
747 ### we're dealing with arguments, not directory
749 if ($path =~ /^(.*?)(\s+\/.*$)/) {
750 ($prog, $args) = ($1, $2);
752 ### otherwise, there are no arguments
754 ($prog, $args) = ($path, '');
757 $prog = Win32::GetShortPathName( $prog );
758 $self->program->$pgm( $prog . $args );
772 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
776 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
780 The CPAN++ interface (of which this module is a part of) is copyright (c)
781 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
783 This library is free software; you may redistribute and/or modify it
784 under the same terms as Perl itself.
788 L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure>
793 # c-indentation-style: bsd
795 # indent-tabs-mode: nil
797 # vim: expandtab shiftwidth=4: