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