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 check_install( module => 'Module::Signature', version => '0.06' )
362 and ( can_run('gpg') ||
363 check_install(module => 'Crypt::OpenPGP')
369 A boolean indicating whether or not to skip tests when installing modules.
374 $Conf->{'conf'}->{'skiptest'} = 0;
378 A boolean indicating whether or not to use C<Storable> to write compiled
379 source file information to disk. This makes for faster startup and look
380 up times, but takes extra diskspace. Defaults to 'true' if you have
381 C<Storable> installed and 'false' if you don't.
385 $Conf->{'conf'}->{'storable'} =
386 ( check_install( module => 'Storable' ) ? 1 : 0 );
390 Digit indicating the time before a fetch request times out (in seconds).
395 $Conf->{'conf'}->{'timeout'} = 300;
399 A boolean indicating whether or not C<CPANPLUS> runs in verbose mode.
400 Defaults to 'true' if you have the environment variable
401 C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise.
403 It is recommended you run with verbose enabled, but it is disabled
404 for historical reasons.
408 $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0;
410 =item write_install_log
412 A boolean indicating whether or not to write install logs after installing
413 a module using the interactive shell. Defaults to 'true'.
418 $Conf->{'conf'}->{'write_install_logs'} = 1;
422 =head2 Section 'program'
426 ### Paths get stripped of whitespace on win32 in the constructor
427 ### sudo gets emptied if there's no need for it in the constructor
433 A string holding the path to your editor of choice. Defaults to your
434 $ENV{EDITOR}, $ENV{VISIUAL}, 'vi' or 'pico' programs, in that order.
438 $Conf->{'program'}->{'editor'} = do {
439 $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
440 can_run('vi') || can_run('pico')
445 A string holding the path to your C<make> binary. Looks for the C<make>
446 program used to build perl or failing that, a C<make> in your path.
450 $Conf->{'program'}->{'make'} =
451 can_run($Config{'make'}) || can_run('make');
455 A string holding the path to your pager of choice. Defaults to your
456 $ENV{PAGER}, 'less' or 'more' programs, in that order.
460 $Conf->{'program'}->{'pager'} =
461 $ENV{'PAGER'} || can_run('less') || can_run('more');
463 ### no one uses this feature anyway, and it's only working for EU::MM
464 ### and not for module::build
469 A string holding the path to your login shell of choice. Defaults to your
470 $ENV{SHELL} setting, or $ENV{COMSPEC} on Windows.
474 $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32'
480 A string holding the path to your C<sudo> binary if your install path
481 requires super user permissions. Looks for C<sudo> in your path, or
482 remains empty if you do not require super user permissiosn to install.
486 $Conf->{'program'}->{'sudo'} = do {
487 $> # check for all install dirs!
488 # installsiteman3dir is a 5.8'ism.. don't check
490 ? ( -w $Config{'installsitelib'} &&
491 ( defined $Config{'installsiteman3dir'} &&
492 -w $Config{'installsiteman3dir'}
494 -w $Config{'installsitebin'}
503 A string holding the path to the C<cpanp-run-perl> utility bundled
504 with CPANPLUS, which is used to enable autoflushing in spawned processes.
508 ### perlwrapper that allows us to turn on autoflushing
509 $Conf->{'program'}->{'perlwrapper'} = sub {
510 my $name = 'cpanp-run-perl';
514 my $ver = $Config::Config{version};
516 ### if we are running with 'versiononly' enabled,
517 ### all binaries will have the perlversion appended
518 ### ie, cpanp will become cpanp5.9.5
519 ### so prefer the versioned binary in that case
520 $Config::Config{versiononly}
521 ? ($name.$ver, $name)
522 : ($name, $name.$ver);
525 ### patch from Steve Hay Fri 29 Jun 2007 14:26:02 GMT+02:00
526 ### Msg-Id: <4684FA5A.7030506@uk.radan.com>
527 ### look for files with a ".bat" extension as well on Win32
528 @bins = map { $_, "$_.bat" } @bins if $^O eq 'MSWin32';
531 BIN: for my $bin (@bins) {
533 ### parallel to your cpanp/cpanp-boxed
534 my $maybe = File::Spec->rel2abs(
535 File::Spec->catdir( dirname($0), $bin )
537 $path = $maybe and last BIN if -f $maybe;
539 ### parallel to your CPANPLUS.pm:
540 ### $INC{cpanplus}/../bin/cpanp-run-perl
541 $maybe = File::Spec->rel2abs(
543 dirname($INC{'CPANPLUS.pm'}),
549 $path = $maybe and last BIN if -f $maybe;
551 ### you installed CPANPLUS in a custom prefix,
552 ### so go paralel to /that/. PREFIX=/tmp/cp
553 ### would put cpanp-run-perl in /tmp/cp/bin and
555 ### /tmp/cp/lib/perl5/site_perl/5.8.8
556 $maybe = File::Spec->rel2abs(
558 dirname( $INC{'CPANPLUS.pm'} ),
559 '..', '..', '..', '..', # 4x updir
564 $path = $maybe and last BIN if -f $maybe;
566 ### in your path -- take this one last, the
567 ### previous two assume extracted tarballs
569 ### note that we don't use 'can_run' as it's
570 ### not an executable, just a wrapper...
571 for my $dir (split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
574 $maybe = File::Spec->catfile( $dir, $bin );
575 $path = $maybe and last BIN if -f $maybe;
579 ### we should have a $path by now ideally, if so return it
580 return $path if defined $path;
582 ### if not, warn about it and give sensible default.
583 ### XXX try to be a no-op instead then..
584 ### cross your fingers...
585 ### pass '-P' to perl: "run program through C
586 ### preprocessor before compilation"
588 "Could not find the '%1' binary in your path".
589 "--this may be a problem.\n".
590 "Please locate this program and set ".
591 "your '%2' config entry to its path.\n".
592 "From the default shell, you can do this by typing:\n\n".
595 $name, 'perlwrapper',
596 's program perlwrapper FULL_PATH_TO_CPANP_RUN_PERL',
608 my $obj = $class->SUPER::new;
610 $obj->mk_accessors( keys %$Conf );
612 for my $acc ( keys %$Conf ) {
613 my $subobj = Object::Accessor->new;
614 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
616 ### read in all the settings from the sub accessors;
617 for my $subacc ( $subobj->ls_accessors ) {
618 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
621 ### now store it in the parent object
622 $obj->$acc( $subobj );
625 $obj->_clean_up_paths;
627 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
633 sub _clean_up_paths {
636 ### clean up paths if we are on win32
637 if( $^O eq 'MSWin32' ) {
638 for my $pgm ( $self->program->ls_accessors ) {
639 my $path = $self->program->$pgm;
641 ### paths with whitespace needs to be shortened
643 if ($path and $path =~ /\s+/) {
646 ### patch from Steve Hay, 13nd of June 2007
647 ### msg-id: <467012A4.6060705@uk.radan.com>
648 ### windows directories are not allowed to end with
649 ### a space, so any occurrence of '\w\s+/\w+' means
650 ### we're dealing with arguments, not directory
652 if ($path =~ /^(.*?)(\s+\/.*$)/) {
653 ($prog, $args) = ($1, $2);
655 ### otherwise, there are no arguments
657 ($prog, $args) = ($path, '');
660 $prog = Win32::GetShortPathName( $prog );
661 $self->program->$pgm( $prog . $args );
675 Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
679 This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
683 The CPAN++ interface (of which this module is a part of) is copyright (c)
684 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
686 This library is free software; you may redistribute and/or modify it
687 under the same terms as Perl itself.
691 L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure>
696 # c-indentation-style: bsd
698 # indent-tabs-mode: nil
700 # vim: expandtab shiftwidth=4: