Re: 5.10.0 test hangs on non internet access
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / Config.pm
CommitLineData
6aaee015 1package CPANPLUS::Config;
2
3use strict;
4use warnings;
5
6use base 'Object::Accessor';
7
8use base 'CPANPLUS::Internals::Utils';
9
10use Config;
11use File::Spec;
12use Module::Load;
13use CPANPLUS;
14use CPANPLUS::Error;
15use CPANPLUS::Internals::Constants;
16
17use File::Basename qw[dirname];
18use IPC::Cmd qw[can_run];
19use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
20use Module::Load::Conditional qw[check_install];
21
622d31ac 22
23=pod
24
25=head1 NAME
26
27CPANPLUS::Config
28
29=head1 DESCRIPTION
30
31This module contains defaults and heuristics for configuration
32information for CPANPLUS. To change any of these values, please
33see the documentation in C<CPANPLUS::Configure>.
34
35Below you'll find a list of configuration types and keys, and
36their meaning.
37
38=head1 CONFIGURATION
39
40=cut
41
42### BAH! you can't have POD interleaved with a hash
43### declaration.. so declare every entry seperatedly :(
6aaee015 44my $Conf = {
45 '_fetch' => {
46 'blacklist' => [ 'ftp' ],
47 },
622d31ac 48
49 ### _source, _build and _mirror are supposed to be static
50 ### no changes should be needed unless pause/cpan changes
51 '_source' => {
52 'hosts' => 'MIRRORED.BY',
53 'auth' => '01mailrc.txt.gz',
54 'stored' => 'sourcefiles',
55 'dslip' => '03modlist.data.gz',
56 'update' => '86400',
5bc5f6dc 57 'mod' => '02packages.details.txt.gz',
58 'custom_index' => 'packages.txt',
622d31ac 59 },
60 '_build' => {
61 'plugins' => 'plugins',
62 'moddir' => 'build',
63 'startdir' => '',
64 'distdir' => 'dist',
65 'autobundle' => 'autobundle',
66 'autobundle_prefix' => 'Snapshot',
67 'autdir' => 'authors',
68 'install_log_dir' => 'install-logs',
5bc5f6dc 69 'custom_sources' => 'custom-sources',
622d31ac 70 'sanity_check' => 1,
71 },
72 '_mirror' => {
73 'base' => 'authors/id/',
74 'auth' => 'authors/01mailrc.txt.gz',
75 'dslip' => 'modules/03modlist.data.gz',
76 'mod' => 'modules/02packages.details.txt.gz'
77 },
78};
79
80=head2 Section 'conf'
81
82=over 4
83
84=item hosts
85
86An array ref containing hosts entries to be queried for packages.
87
88An example entry would like this:
89
90 { 'scheme' => 'ftp',
91 'path' => '/pub/CPAN/',
92 'host' => 'ftp.cpan.org'
93 },
94
95=cut
96
97 ### default host list
98 $Conf->{'conf'}->{'hosts'} = [
6aaee015 99 {
100 'scheme' => 'ftp',
101 'path' => '/pub/CPAN/',
102 'host' => 'ftp.cpan.org'
103 },
104 {
105 'scheme' => 'http',
106 'path' => '/',
107 'host' => 'www.cpan.org'
108 },
109 {
110 'scheme' => 'ftp',
111 'path' => '/pub/CPAN/',
112 'host' => 'ftp.nl.uu.net'
113 },
114 {
115 'scheme' => 'ftp',
116 'path' => '/pub/CPAN/',
117 'host' => 'cpan.valueclick.com'
118 },
119 {
120 'scheme' => 'ftp',
121 'path' => '/pub/languages/perl/CPAN/',
122 'host' => 'ftp.funet.fi'
123 }
622d31ac 124 ];
125
126=item allow_build_interactivity
127
128Boolean flag to indicate whether 'perl Makefile.PL' and similar
129are run interactively or not. Defaults to 'true'.
130
131=cut
132
133 $Conf->{'conf'}->{'allow_build_interactivity'} = 1;
134
135=item base
136
137The directory CPANPLUS keeps all it's build and state information in.
138Defaults to ~/.cpanplus.
139
140=cut
141
142 $Conf->{'conf'}->{'base'} = File::Spec->catdir(
143 __PACKAGE__->_home_dir, DOT_CPANPLUS );
144
145=item buildflags
146
147Any flags to be passed to 'perl Build.PL'. See C<perldoc Module::Build>
148for details. Defaults to an empty string.
149
150=cut
151
152 $Conf->{'conf'}->{'buildflags'} = '';
153
154=item cpantest
155
156Boolean flag to indicate whether or not to mail test results of module
157installations to C<http://testers.cpan.org>. Defaults to 'false'.
158
159=cut
160
161 $Conf->{'conf'}->{'cpantest'} = 0;
162
163=item cpantest_mx
164
165String holding an explicit mailserver to use when sending out emails
166for C<http://testers.cpan.org>. An empty string will use your system
167settings. Defaults to an empty string.
168
169=cut
170
171 $Conf->{'conf'}->{'cpantest_mx'} = '';
172
173=item debug
174
175Boolean flag to enable or disable extensive debuggging information.
176Defaults to 'false'.
177
178=cut
179
180 $Conf->{'conf'}->{'debug'} = 0;
181
182=item dist_type
183
184Default distribution type to use when building packages. See C<cpan2dist>
185or C<CPANPLUS::Dist> for details. An empty string will not use any
186package building software. Defaults to an empty string.
187
188=cut
189
190 $Conf->{'conf'}->{'dist_type'} = '';
191
192=item email
193
194Email address to use for anonymous ftp access and as C<from> address
195when sending emails. Defaults to an C<example.com> address.
196
197=cut
198
199 $Conf->{'conf'}->{'email'} = DEFAULT_EMAIL;
200
201=item extractdir
202
203String containing the directory where fetched archives should be
204extracted. An empty string will use a directory under your C<base>
205directory. Defaults to an empty string.
206
207=cut
208
209 $Conf->{'conf'}->{'extractdir'} = '';
210
211=item fetchdir
212
213String containing the directory where fetched archives should be
214stored. An empty string will use a directory under your C<base>
215directory. Defaults to an empty string.
216
217=cut
218
219 $Conf->{'conf'}->{'fetchdir'} = '';
220
221=item flush
222
223Boolean indicating whether build failures, cache dirs etc should
224be flushed after every operation or not. Defaults to 'true'.
225
226=cut
227
228 $Conf->{'conf'}->{'flush'} = 1;
229
230=item force
231
232Boolean indicating whether files should be forcefully overwritten
233if they exist, modules should be installed when they fail tests,
234etc. Defaults to 'false'.
235
236=cut
237
238 $Conf->{'conf'}->{'force'} = 0;
239
240=item lib
241
242An array ref holding directories to be added to C<@INC> when CPANPLUS
243starts up. Defaults to an empty array reference.
244
245=cut
246
247 $Conf->{'conf'}->{'lib'} = [];
248
249=item makeflags
250
251A string holding flags that will be passed to the C<make> program
252when invoked. Defaults to an empty string.
253
254=cut
255
256 $Conf->{'conf'}->{'makeflags'} = '';
257
258=item makemakerflags
259
260A string holding flags that will be passed to C<perl Makefile.PL>
261when invoked. Defaults to an empty string.
262
263=cut
264
265 $Conf->{'conf'}->{'makemakerflags'} = '';
266
267=item md5
268
269A boolean indicating whether or not md5 checks should be done when
270an archive is fetched. Defaults to 'true' if you have C<Digest::MD5>
271installed, 'false' otherwise.
272
273=cut
274
275 $Conf->{'conf'}->{'md5'} = (
276 check_install( module => 'Digest::MD5' ) ? 1 : 0 );
277
278=item no_update
279
280A boolean indicating whether or not C<CPANPLUS>' source files should be
281updated or not. Defaults to 'false'.
282
283=cut
284
285 $Conf->{'conf'}->{'no_update'} = 0;
286
287=item passive
288
289A boolean indicating whether or not to use passive ftp connections.
290Defaults to 'true'.
291
292=cut
293
294 $Conf->{'conf'}->{'passive'} = 1;
295
296=item prefer_bin
297
298A boolean indicating whether or not to prefer command line programs
299over perl modules. Defaults to 'false' unless you do not have
300C<Compress::Zlib> installed (as that would mean we could not extract
301C<.tar.gz> files)
302
303=cut
6aaee015 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
622d31ac 306 $Conf->{'conf'}->{'prefer_bin'} =
307 (eval {require Compress::Zlib; 1} ? 0 : 1 );
308
309=item prefer_makefile
310
311A boolean indicating whether or not prefer a C<Makefile.PL> over a
312C<Build.PL> file if both are present. Defaults to 'true'.
313
314=cut
315
316 $Conf->{'conf'}->{'prefer_makefile'} = 1;
317
318=item prereqs
319
320A digit indicating what to do when a package you are installing has a
321prerequisite. Options are:
322
323 0 Do not install
324 1 Install
325 2 Ask
326 3 Ignore (dangerous, install will probably fail!)
327
328The default is to ask.
329
330=cut
331
332 $Conf->{'conf'}->{'prereqs'} = PREREQ_ASK;
333
334=item shell
335
336A string holding the shell class you wish to start up when starting
337C<CPANPLUS> in interactive mode.
338
339Defaults to C<CPANPLUS::Shell::Default>, the default CPANPLUS shell.
340
341=cut
342
343 $Conf->{'conf'}->{'shell'} = 'CPANPLUS::Shell::Default';
344
345=item show_startup_tip
346
347A boolean indicating whether or not to show start up tips in the
348interactive shell. Defaults to 'true'.
349
350=cut
351
352 $Conf->{'conf'}->{'show_startup_tip'} = 1;
353
354=item signature
355
356A boolean indicating whether or not check signatures if packages are
357signed. Defaults to 'true' if you have C<gpg> or C<Crypt::OpenPGP>
358installed, 'false' otherwise.
359
360=cut
361
362 $Conf->{'conf'}->{'signature'} = do {
502c7995 363 check_install( module => 'Module::Signature', version => '0.06' )
364 and ( can_run('gpg') ||
365 check_install(module => 'Crypt::OpenPGP')
366 );
367 } ? 1 : 0;
622d31ac 368
369=item skiptest
370
371A boolean indicating whether or not to skip tests when installing modules.
372Defaults to 'false'.
373
374=cut
375
376 $Conf->{'conf'}->{'skiptest'} = 0;
377
378=item storable
379
380A boolean indicating whether or not to use C<Storable> to write compiled
381source file information to disk. This makes for faster startup and look
382up times, but takes extra diskspace. Defaults to 'true' if you have
383C<Storable> installed and 'false' if you don't.
384
385=cut
386
387 $Conf->{'conf'}->{'storable'} =
388 ( check_install( module => 'Storable' ) ? 1 : 0 );
389
390=item timeout
391
392Digit indicating the time before a fetch request times out (in seconds).
393Defaults to 300.
394
395=cut
396
397 $Conf->{'conf'}->{'timeout'} = 300;
398
399=item verbose
400
401A boolean indicating whether or not C<CPANPLUS> runs in verbose mode.
402Defaults to 'true' if you have the environment variable
403C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise.
404
405It is recommended you run with verbose enabled, but it is disabled
406for historical reasons.
407
408=cut
409
410 $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0;
411
412=item write_install_log
413
414A boolean indicating whether or not to write install logs after installing
415a module using the interactive shell. Defaults to 'true'.
416
417
418=cut
419
420 $Conf->{'conf'}->{'write_install_logs'} = 1;
421
422=back
423
424=head2 Section 'program'
425
426=cut
427
6aaee015 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
622d31ac 430
431=over 4
432
433=item editor
434
435A string holding the path to your editor of choice. Defaults to your
436$ENV{EDITOR}, $ENV{VISIUAL}, 'vi' or 'pico' programs, in that order.
437
438=cut
439
440 $Conf->{'program'}->{'editor'} = do {
441 $ENV{'EDITOR'} || $ENV{'VISUAL'} ||
442 can_run('vi') || can_run('pico')
443 };
444
445=item make
446
447A string holding the path to your C<make> binary. Looks for the C<make>
448program used to build perl or failing that, a C<make> in your path.
449
450=cut
451
452 $Conf->{'program'}->{'make'} =
453 can_run($Config{'make'}) || can_run('make');
454
455=item pager
456
457A string holding the path to your pager of choice. Defaults to your
458$ENV{PAGER}, 'less' or 'more' programs, in that order.
459
460=cut
461
462 $Conf->{'program'}->{'pager'} =
463 $ENV{'PAGER'} || can_run('less') || can_run('more');
464
6aaee015 465 ### no one uses this feature anyway, and it's only working for EU::MM
466 ### and not for module::build
467 #'perl' => '',
622d31ac 468
469=item shell
470
471A string holding the path to your login shell of choice. Defaults to your
472$ENV{SHELL} setting, or $ENV{COMSPEC} on Windows.
473
474=cut
475
476 $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32'
477 ? $ENV{COMSPEC}
478 : $ENV{SHELL};
479
480=item sudo
481
482A string holding the path to your C<sudo> binary if your install path
483requires super user permissions. Looks for C<sudo> in your path, or
484remains empty if you do not require super user permissiosn to install.
485
486=cut
487
488 $Conf->{'program'}->{'sudo'} = do {
489 $> # check for all install dirs!
490 # installsiteman3dir is a 5.8'ism.. don't check
491 # it on 5.6.x...
492 ? ( -w $Config{'installsitelib'} &&
493 ( defined $Config{'installsiteman3dir'} &&
494 -w $Config{'installsiteman3dir'}
495 ) &&
496 -w $Config{'installsitebin'}
497 ? undef
498 : can_run('sudo')
499 )
500 : can_run('sudo')
501 };
502
503=item perlwrapper
504
505A string holding the path to the C<cpanp-run-perl> utility bundled
506with CPANPLUS, which is used to enable autoflushing in spawned processes.
507
508=cut
509
6aaee015 510 ### perlwrapper that allows us to turn on autoflushing
622d31ac 511 $Conf->{'program'}->{'perlwrapper'} = sub {
494f1016 512 my $name = 'cpanp-run-perl';
6aaee015 513
494f1016 514 my @bins = do{
515 require Config;
516 my $ver = $Config::Config{version};
517
518 ### if we are running with 'versiononly' enabled,
519 ### all binaries will have the perlversion appended
520 ### ie, cpanp will become cpanp5.9.5
521 ### so prefer the versioned binary in that case
522 $Config::Config{versiononly}
523 ? ($name.$ver, $name)
524 : ($name, $name.$ver);
525 };
502c7995 526
527 ### patch from Steve Hay Fri 29 Jun 2007 14:26:02 GMT+02:00
528 ### Msg-Id: <4684FA5A.7030506@uk.radan.com>
529 ### look for files with a ".bat" extension as well on Win32
530 @bins = map { $_, "$_.bat" } @bins if $^O eq 'MSWin32';
531
494f1016 532 my $path;
533 BIN: for my $bin (@bins) {
534
535 ### parallel to your cpanp/cpanp-boxed
536 my $maybe = File::Spec->rel2abs(
537 File::Spec->catdir( dirname($0), $bin )
538 );
539 $path = $maybe and last BIN if -f $maybe;
540
541 ### parallel to your CPANPLUS.pm:
542 ### $INC{cpanplus}/../bin/cpanp-run-perl
543 $maybe = File::Spec->rel2abs(
544 File::Spec->catdir(
545 dirname($INC{'CPANPLUS.pm'}),
546 '..', # lib dir
547 'bin', # bin dir
548 $bin, # script
549 )
550 );
551 $path = $maybe and last BIN if -f $maybe;
552
553 ### you installed CPANPLUS in a custom prefix,
554 ### so go paralel to /that/. PREFIX=/tmp/cp
555 ### would put cpanp-run-perl in /tmp/cp/bin and
556 ### CPANPLUS.pm in
557 ### /tmp/cp/lib/perl5/site_perl/5.8.8
558 $maybe = File::Spec->rel2abs(
559 File::Spec->catdir(
560 dirname( $INC{'CPANPLUS.pm'} ),
561 '..', '..', '..', '..', # 4x updir
562 'bin', # bin dir
563 $bin, # script
564 )
565 );
566 $path = $maybe and last BIN if -f $maybe;
6aaee015 567
494f1016 568 ### in your path -- take this one last, the
569 ### previous two assume extracted tarballs
570 ### or user installs
571 ### note that we don't use 'can_run' as it's
572 ### not an executable, just a wrapper...
d0baa00e 573 ### prefer anything that's found in the path paralel to your $^X
574 for my $dir (File::Spec->rel2abs( dirname($^X) ),
575 split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}),
576 File::Spec->curdir,
494f1016 577 ) {
578 $maybe = File::Spec->catfile( $dir, $bin );
579 $path = $maybe and last BIN if -f $maybe;
580 }
581 }
582
583 ### we should have a $path by now ideally, if so return it
584 return $path if defined $path;
585
586 ### if not, warn about it and give sensible default.
587 ### XXX try to be a no-op instead then..
588 ### cross your fingers...
589 ### pass '-P' to perl: "run program through C
590 ### preprocessor before compilation"
d0baa00e 591 ### XXX using -P actually changes the way some Makefile.PLs
592 ### are executed, so don't do that... --kane
494f1016 593 error(loc(
502c7995 594 "Could not find the '%1' binary in your path".
494f1016 595 "--this may be a problem.\n".
596 "Please locate this program and set ".
502c7995 597 "your '%2' config entry to its path.\n".
598 "From the default shell, you can do this by typing:\n\n".
599 " %3\n".
600 " %4\n",
601 $name, 'perlwrapper',
602 's program perlwrapper FULL_PATH_TO_CPANP_RUN_PERL',
603 's save'
494f1016 604 ));
e3b7d412 605 return '';
622d31ac 606 }->();
607
608=back
609
610=cut
6aaee015 611
6aaee015 612sub new {
613 my $class = shift;
614 my $obj = $class->SUPER::new;
615
616 $obj->mk_accessors( keys %$Conf );
617
618 for my $acc ( keys %$Conf ) {
619 my $subobj = Object::Accessor->new;
620 $subobj->mk_accessors( keys %{$Conf->{$acc}} );
621
622 ### read in all the settings from the sub accessors;
623 for my $subacc ( $subobj->ls_accessors ) {
624 $subobj->$subacc( $Conf->{$acc}->{$subacc} );
625 }
626
627 ### now store it in the parent object
628 $obj->$acc( $subobj );
629 }
630
631 $obj->_clean_up_paths;
632
633 ### shut up IPC::Cmd warning about not findin IPC::Run on win32
634 $IPC::Cmd::WARN = 0;
635
636 return $obj;
637}
638
639sub _clean_up_paths {
640 my $self = shift;
641
642 ### clean up paths if we are on win32
643 if( $^O eq 'MSWin32' ) {
644 for my $pgm ( $self->program->ls_accessors ) {
c1ceaa19 645 my $path = $self->program->$pgm;
646
647 ### paths with whitespace needs to be shortened
648 ### for shell outs.
649 if ($path and $path =~ /\s+/) {
650 my($prog, $args);
651
652 ### patch from Steve Hay, 13nd of June 2007
653 ### msg-id: <467012A4.6060705@uk.radan.com>
654 ### windows directories are not allowed to end with
655 ### a space, so any occurrence of '\w\s+/\w+' means
656 ### we're dealing with arguments, not directory
657 ### names.
658 if ($path =~ /^(.*?)(\s+\/.*$)/) {
659 ($prog, $args) = ($1, $2);
660
661 ### otherwise, there are no arguments
662 } else {
663 ($prog, $args) = ($path, '');
664 }
665
666 $prog = Win32::GetShortPathName( $prog );
667 $self->program->$pgm( $prog . $args );
668 }
6aaee015 669 }
670 }
671
672 return 1;
673}
674
6751;
622d31ac 676
677=pod
678
679=head1 BUG REPORTS
680
681Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
682
683=head1 AUTHOR
684
685This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
686
687=head1 COPYRIGHT
688
689The CPAN++ interface (of which this module is a part of) is copyright (c)
6902001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
691
692This library is free software; you may redistribute and/or modify it
693under the same terms as Perl itself.
694
695=head1 SEE ALSO
696
697L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure>
698
699=cut
700
701# Local variables:
702# c-indentation-style: bsd
703# c-basic-offset: 4
704# indent-tabs-mode: nil
705# End:
706# vim: expandtab shiftwidth=4: