This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[PATCH] Update CPAN.pm to 1.93_52
[perl5.git] / lib / CPAN / HandleConfig.pm
CommitLineData
e82b9348
SP
1package CPAN::HandleConfig;
2use strict;
547d3dfd 3use vars qw(%can %keys $loading $VERSION);
1a43333d 4
5254b38e 5$VERSION = "5.5";
e82b9348
SP
6
7%can = (
4d1321a7
A
8 commit => "Commit changes to disk",
9 defaults => "Reload defaults from disk",
10 help => "Short help about 'o conf' usage",
11 init => "Interactive setting of all options",
e82b9348
SP
12);
13
1e8f9a0a
SP
14# Q: where is the "How do I add a new config option" HOWTO?
15# A1: svn diff -r 757:758 # where dagolden added test_report
16# A2: svn diff -r 985:986 # where andk added yaml_module
5254b38e
SP
17# A3: 1. add new config option to %keys below
18# 2. add a Pod description in CPAN::FirstTime; it should include a
19# prompt line; see others for examples
20# 3. add a "matcher" section in CPAN::FirstTime::init that includes
21# a prompt function; see others for examples
22# 4. add config option to documentation section in CPAN.pm
23
6658a91b
SP
24%keys = map { $_ => undef }
25 (
b72dd56f
SP
26 "applypatch",
27 "auto_commit",
6658a91b
SP
28 "build_cache",
29 "build_dir",
05bab18e 30 "build_dir_reuse",
6658a91b
SP
31 "build_requires_install_policy",
32 "bzip2",
33 "cache_metadata",
34 "check_sigs",
b72dd56f 35 "colorize_debug",
6658a91b
SP
36 "colorize_output",
37 "colorize_print",
38 "colorize_warn",
39 "commandnumber_in_prompt",
40 "commands_quote",
5254b38e 41 "connect_to_internet_ok",
6658a91b
SP
42 "cpan_home",
43 "curl",
44 "dontload_hash", # deprecated after 1.83_68 (rev. 581)
45 "dontload_list",
46 "ftp",
47 "ftp_passive",
48 "ftp_proxy",
5254b38e
SP
49 "ftpstats_size",
50 "ftpstats_period",
6658a91b
SP
51 "getcwd",
52 "gpg",
53 "gzip",
5254b38e 54 "halt_on_failure",
6658a91b
SP
55 "histfile",
56 "histsize",
57 "http_proxy",
58 "inactivity_timeout",
59 "index_expire",
60 "inhibit_startup_message",
61 "keep_source_where",
547d3dfd 62 "load_module_verbosity",
6658a91b
SP
63 "lynx",
64 "make",
65 "make_arg",
66 "make_install_arg",
67 "make_install_make_command",
68 "makepl_arg",
69 "mbuild_arg",
70 "mbuild_install_arg",
71 "mbuild_install_build_command",
72 "mbuildpl_arg",
73 "ncftp",
74 "ncftpget",
75 "no_proxy",
76 "pager",
77 "password",
78 "patch",
f9916dde 79 "patches_dir",
5254b38e 80 "perl5lib_verbosity",
6658a91b 81 "prefer_installer",
6658a91b 82 "prefs_dir",
547d3dfd 83 "prerequisites_policy",
6658a91b
SP
84 "proxy_pass",
85 "proxy_user",
05bab18e 86 "randomize_urllist",
6658a91b
SP
87 "scan_cache",
88 "shell",
547d3dfd 89 "show_unparsable_versions",
6658a91b 90 "show_upload_date",
547d3dfd 91 "show_zero_versions",
6658a91b 92 "tar",
547d3dfd 93 "tar_verbosity",
6658a91b
SP
94 "term_is_latin",
95 "term_ornaments",
96 "test_report",
5254b38e 97 "trust_test_report_history",
6658a91b
SP
98 "unzip",
99 "urllist",
810a0276 100 "use_sqlite",
6658a91b
SP
101 "username",
102 "wait_list",
103 "wget",
547d3dfd 104 "yaml_load_code",
6658a91b
SP
105 "yaml_module",
106 );
107
108my %prefssupport = map { $_ => 1 }
109 (
110 "build_requires_install_policy",
be34b10d 111 "check_sigs",
6658a91b
SP
112 "make",
113 "make_install_make_command",
114 "prefer_installer",
115 "test_report",
116 );
117
e82b9348
SP
118# returns true on successful action
119sub edit {
120 my($self,@args) = @_;
121 return unless @args;
122 CPAN->debug("self[$self]args[".join(" | ",@args)."]");
123 my($o,$str,$func,$args,$key_exists);
124 $o = shift @args;
125 if($can{$o}) {
547d3dfd
SP
126 $self->$o(args => \@args); # o conf init => sub init => sub load
127 return 1;
e82b9348
SP
128 } else {
129 CPAN->debug("o[$o]") if $CPAN::DEBUG;
130 unless (exists $keys{$o}) {
131 $CPAN::Frontend->mywarn("Warning: unknown configuration variable '$o'\n");
132 }
b72dd56f
SP
133 my $changed;
134
135
05bab18e
SP
136 # one day I used randomize_urllist for a boolean, so we must
137 # list them explicitly --ak
547d3dfd 138 if (0) {
b72dd56f
SP
139 } elsif ($o =~ /^(wait_list|urllist|dontload_list)$/) {
140
141 #
142 # ARRAYS
143 #
144
547d3dfd
SP
145 $func = shift @args;
146 $func ||= "";
05bab18e 147 CPAN->debug("func[$func]args[@args]") if $CPAN::DEBUG;
547d3dfd
SP
148 # Let's avoid eval, it's easier to comprehend without.
149 if ($func eq "push") {
150 push @{$CPAN::Config->{$o}}, @args;
e82b9348 151 $changed = 1;
547d3dfd
SP
152 } elsif ($func eq "pop") {
153 pop @{$CPAN::Config->{$o}};
e82b9348 154 $changed = 1;
547d3dfd
SP
155 } elsif ($func eq "shift") {
156 shift @{$CPAN::Config->{$o}};
e82b9348 157 $changed = 1;
547d3dfd
SP
158 } elsif ($func eq "unshift") {
159 unshift @{$CPAN::Config->{$o}}, @args;
e82b9348 160 $changed = 1;
547d3dfd 161 } elsif ($func eq "splice") {
05bab18e
SP
162 my $offset = shift @args || 0;
163 my $length = shift @args || 0;
547d3dfd 164 splice @{$CPAN::Config->{$o}}, $offset, $length, @args; # may warn
e82b9348 165 $changed = 1;
547d3dfd
SP
166 } elsif ($func) {
167 $CPAN::Config->{$o} = [$func, @args];
e82b9348 168 $changed = 1;
547d3dfd 169 } else {
e82b9348 170 $self->prettyprint($o);
547d3dfd 171 }
4d1321a7
A
172 if ($changed) {
173 if ($o eq "urllist") {
174 # reset the cached values
175 undef $CPAN::FTP::Thesite;
176 undef $CPAN::FTP::Themethod;
f20de9f0 177 $CPAN::Index::LAST_TIME = 0;
4d1321a7
A
178 } elsif ($o eq "dontload_list") {
179 # empty it, it will be built up again
180 $CPAN::META->{dontload_hash} = {};
181 }
e82b9348 182 }
ca79d794 183 } elsif ($o =~ /_hash$/) {
b72dd56f
SP
184
185 #
186 # HASHES
187 #
188
547d3dfd 189 if (@args==1 && $args[0] eq "") {
6658a91b
SP
190 @args = ();
191 } elsif (@args % 2) {
192 push @args, "";
193 }
ca79d794 194 $CPAN::Config->{$o} = { @args };
b72dd56f 195 $changed = 1;
ca79d794 196 } else {
b72dd56f
SP
197
198 #
199 # SCALARS
200 #
201
547d3dfd 202 if (defined $args[0]) {
6658a91b
SP
203 $CPAN::CONFIG_DIRTY = 1;
204 $CPAN::Config->{$o} = $args[0];
b72dd56f 205 $changed = 1;
6658a91b 206 }
547d3dfd 207 $self->prettyprint($o)
7d97ad34 208 if exists $keys{$o} or defined $CPAN::Config->{$o};
547d3dfd 209 }
b72dd56f
SP
210 if ($changed) {
211 if ($CPAN::Config->{auto_commit}) {
212 $self->commit;
213 } else {
214 $CPAN::CONFIG_DIRTY = 1;
215 $CPAN::Frontend->myprint("Please use 'o conf commit' to ".
216 "make the config permanent!\n\n");
217 }
218 }
e82b9348
SP
219 }
220}
221
222sub prettyprint {
547d3dfd
SP
223 my($self,$k) = @_;
224 my $v = $CPAN::Config->{$k};
225 if (ref $v) {
226 my(@report);
227 if (ref $v eq "ARRAY") {
228 @report = map {"\t$_ \[$v->[$_]]\n"} 0..$#$v;
229 } else {
230 @report = map
231 {
232 sprintf "\t%-18s => %s\n",
233 "[$_]",
234 defined $v->{$_} ? "[$v->{$_}]" : "undef"
235 } keys %$v;
236 }
237 $CPAN::Frontend->myprint(
238 join(
239 "",
240 sprintf(
241 " %-18s\n",
242 $k
243 ),
244 @report
245 )
246 );
247 } elsif (defined $v) {
248 $CPAN::Frontend->myprint(sprintf " %-18s [%s]\n", $k, $v);
9ddc4ed0 249 } else {
547d3dfd 250 $CPAN::Frontend->myprint(sprintf " %-18s undef\n", $k);
9ddc4ed0 251 }
e82b9348
SP
252}
253
254sub commit {
9ddc4ed0 255 my($self,@args) = @_;
6658a91b 256 CPAN->debug("args[@args]") if $CPAN::DEBUG;
05bab18e
SP
257 if ($CPAN::RUN_DEGRADED) {
258 $CPAN::Frontend->mydie(
259 "'o conf commit' disabled in ".
260 "degraded mode. Maybe try\n".
261 " !undef \$CPAN::RUN_DEGRADED\n"
262 );
263 }
9ddc4ed0
A
264 my $configpm;
265 if (@args) {
266 if ($args[0] eq "args") {
267 # we have not signed that contract
268 } else {
269 $configpm = $args[0];
270 }
271 }
547d3dfd
SP
272 unless (defined $configpm) {
273 $configpm ||= $INC{"CPAN/MyConfig.pm"};
274 $configpm ||= $INC{"CPAN/Config.pm"};
275 $configpm || Carp::confess(q{
e82b9348
SP
276CPAN::Config::commit called without an argument.
277Please specify a filename where to save the configuration or try
278"o conf init" to have an interactive course through configing.
279});
280 }
281 my($mode);
282 if (-f $configpm) {
547d3dfd
SP
283 $mode = (stat $configpm)[2];
284 if ($mode && ! -w _) {
285 Carp::confess("$configpm is not writable");
286 }
e82b9348
SP
287 }
288
289 my $msg;
5254b38e 290 my $home = home();
e82b9348
SP
291 $msg = <<EOF unless $configpm =~ /MyConfig/;
292
293# This is CPAN.pm's systemwide configuration file. This file provides
294# defaults for users, and the values can be changed in a per-user
295# configuration file. The user-config file is being looked for as
5254b38e 296# $home/.cpan/CPAN/MyConfig.pm.
e82b9348
SP
297
298EOF
299 $msg ||= "\n";
300 my($fh) = FileHandle->new;
301 rename $configpm, "$configpm~" if -f $configpm;
302 open $fh, ">$configpm" or
303 $CPAN::Frontend->mydie("Couldn't open >$configpm: $!");
304 $fh->print(qq[$msg\$CPAN::Config = \{\n]);
305 foreach (sort keys %$CPAN::Config) {
44d21104 306 unless (exists $keys{$_}) {
dc053c64
SP
307 # do not drop them: forward compatibility!
308 $CPAN::Frontend->mywarn("Unknown config variable '$_'\n");
44d21104
A
309 next;
310 }
547d3dfd
SP
311 $fh->print(
312 " '$_' => ",
313 $self->neatvalue($CPAN::Config->{$_}),
314 ",\n"
315 );
e82b9348
SP
316 }
317
318 $fh->print("};\n1;\n__END__\n");
319 close $fh;
320
321 #$mode = 0444 | ( $mode & 0111 ? 0111 : 0 );
322 #chmod $mode, $configpm;
323###why was that so? $self->defaults;
9ddc4ed0 324 $CPAN::Frontend->myprint("commit: wrote '$configpm'\n");
6658a91b 325 $CPAN::CONFIG_DIRTY = 0;
e82b9348
SP
326 1;
327}
328
ca79d794
SP
329# stolen from MakeMaker; not taking the original because it is buggy;
330# bugreport will have to say: keys of hashes remain unquoted and can
331# produce syntax errors
332sub neatvalue {
333 my($self, $v) = @_;
334 return "undef" unless defined $v;
335 my($t) = ref $v;
547d3dfd 336 unless ($t) {
6658a91b
SP
337 $v =~ s/\\/\\\\/g;
338 return "q[$v]";
339 }
ca79d794
SP
340 if ($t eq 'ARRAY') {
341 my(@m, @neat);
342 push @m, "[";
343 foreach my $elem (@$v) {
344 push @neat, "q[$elem]";
345 }
346 push @m, join ", ", @neat;
347 push @m, "]";
348 return join "", @m;
349 }
350 return "$v" unless $t eq 'HASH';
351 my(@m, $key, $val);
547d3dfd 352 while (($key,$val) = each %$v) {
ca79d794
SP
353 last unless defined $key; # cautious programming in case (undef,undef) is true
354 push(@m,"q[$key]=>".$self->neatvalue($val)) ;
355 }
356 return "{ ".join(', ',@m)." }";
357}
358
e82b9348
SP
359sub defaults {
360 my($self) = @_;
05bab18e
SP
361 if ($CPAN::RUN_DEGRADED) {
362 $CPAN::Frontend->mydie(
363 "'o conf defaults' disabled in ".
364 "degraded mode. Maybe try\n".
365 " !undef \$CPAN::RUN_DEGRADED\n"
366 );
367 }
c9869e1c
SP
368 my $done;
369 for my $config (qw(CPAN/MyConfig.pm CPAN/Config.pm)) {
26844e27 370 if ($INC{$config}) {
6658a91b 371 CPAN->debug("INC{'$config'}[$INC{$config}]") if $CPAN::DEBUG;
810a0276 372 CPAN::Shell->_reload_this($config,{reloforce => 1});
26844e27
SP
373 $CPAN::Frontend->myprint("'$INC{$config}' reread\n");
374 last;
375 }
c9869e1c 376 }
6658a91b 377 $CPAN::CONFIG_DIRTY = 0;
e82b9348
SP
378 1;
379}
380
ed84aac9
A
381=head2 C<< CLASS->safe_quote ITEM >>
382
383Quotes an item to become safe against spaces
384in shell interpolation. An item is enclosed
385in double quotes if:
386
387 - the item contains spaces in the middle
388 - the item does not start with a quote
389
390This happens to avoid shell interpolation
391problems when whitespace is present in
392directory names.
393
394This method uses C<commands_quote> to determine
395the correct quote. If C<commands_quote> is
396a space, no quoting will take place.
397
398
399if it starts and ends with the same quote character: leave it as it is
400
401if it contains no whitespace: leave it as it is
402
403if it contains whitespace, then
404
405if it contains quotes: better leave it as it is
406
407else: quote it with the correct quote type for the box we're on
408
409=cut
410
411{
412 # Instead of patching the guess, set commands_quote
413 # to the right value
414 my ($quotes,$use_quote)
415 = $^O eq 'MSWin32'
416 ? ('"', '"')
547d3dfd 417 : (q{"'}, "'")
ed84aac9
A
418 ;
419
420 sub safe_quote {
421 my ($self, $command) = @_;
422 # Set up quote/default quote
423 my $quote = $CPAN::Config->{commands_quote} || $quotes;
424
425 if ($quote ne ' '
6658a91b 426 and defined($command )
ed84aac9
A
427 and $command =~ /\s/
428 and $command !~ /[$quote]/) {
429 return qq<$use_quote$command$use_quote>
430 }
431 return $command;
432 }
433}
434
e82b9348 435sub init {
9ddc4ed0 436 my($self,@args) = @_;
547d3dfd
SP
437 CPAN->debug("self[$self]args[".join(",",@args)."]");
438 $self->load(doit => 1, @args);
e82b9348
SP
439 1;
440}
441
442# This is a piece of repeated code that is abstracted here for
443# maintainability. RMB
444#
445sub _configpmtest {
547d3dfd 446 my($configpmdir, $configpmtest) = @_;
e82b9348
SP
447 if (-w $configpmtest) {
448 return $configpmtest;
449 } elsif (-w $configpmdir) {
450 #_#_# following code dumped core on me with 5.003_11, a.k.
451 my $configpm_bak = "$configpmtest.bak";
452 unlink $configpm_bak if -f $configpm_bak;
453 if( -f $configpmtest ) {
454 if( rename $configpmtest, $configpm_bak ) {
547d3dfd 455 $CPAN::Frontend->mywarn(<<END);
e82b9348
SP
456Old configuration file $configpmtest
457 moved to $configpm_bak
458END
547d3dfd
SP
459 }
460 }
461 my $fh = FileHandle->new;
462 if ($fh->open(">$configpmtest")) {
463 $fh->print("1;\n");
464 return $configpmtest;
465 } else {
466 # Should never happen
467 Carp::confess("Cannot open >$configpmtest");
468 }
e82b9348
SP
469 } else { return }
470}
471
87892b73
RGS
472sub require_myconfig_or_config () {
473 return if $INC{"CPAN/MyConfig.pm"};
474 local @INC = @INC;
475 my $home = home();
476 unshift @INC, File::Spec->catdir($home,'.cpan');
477 eval { require CPAN::MyConfig };
ed84aac9
A
478 my $err_myconfig = $@;
479 if ($err_myconfig and $err_myconfig !~ m#locate CPAN/MyConfig\.pm#) {
480 die "Error while requiring CPAN::MyConfig:\n$err_myconfig";
481 }
87892b73
RGS
482 unless ($INC{"CPAN/MyConfig.pm"}) { # this guy has settled his needs already
483 eval {require CPAN::Config;}; # not everybody has one
ed84aac9
A
484 my $err_config = $@;
485 if ($err_config and $err_config !~ m#locate CPAN/Config\.pm#) {
486 die "Error while requiring CPAN::Config:\n$err_config";
487 }
87892b73
RGS
488 }
489}
490
491sub home () {
492 my $home;
5254b38e
SP
493 # Suppress load messages until we load the config and know whether
494 # load messages are desired. Otherwise, it's unexpected and odd
495 # why one load message pops up even when verbosity is turned off.
496 # This means File::HomeDir load messages are never seen, but I
497 # think that's probably OK -- DAGOLDEN
498
499 # 5.6.2 seemed to segfault localizing a value in a hashref
500 # so do it manually instead
501 my $old_v = $CPAN::Config->{load_module_verbosity};
502 $CPAN::Config->{load_module_verbosity} = q[none];
87892b73 503 if ($CPAN::META->has_usable("File::HomeDir")) {
5254b38e
SP
504 $home = File::HomeDir->can('my_dot_config')
505 ? File::HomeDir->my_dot_config
506 : File::HomeDir->my_data;
547d3dfd
SP
507 unless (defined $home) {
508 $home = File::HomeDir->my_home
509 }
510 }
511 unless (defined $home) {
87892b73
RGS
512 $home = $ENV{HOME};
513 }
5254b38e 514 $CPAN::Config->{load_module_verbosity} = $old_v;
87892b73
RGS
515 $home;
516}
517
e82b9348
SP
518sub load {
519 my($self, %args) = @_;
547d3dfd
SP
520 $CPAN::Be_Silent++ if $args{be_silent};
521 my $doit;
522 $doit = delete $args{doit};
e82b9348 523
e82b9348 524 use Carp;
87892b73 525 require_myconfig_or_config;
547d3dfd 526 my @miss = $self->missing_config_data;
2f2071b1 527 CPAN->debug("doit[$doit]loading[$loading]miss[@miss]") if $CPAN::DEBUG;
547d3dfd
SP
528 return unless $doit || @miss;
529 return if $loading;
530 $loading++;
e82b9348
SP
531
532 require CPAN::FirstTime;
547d3dfd 533 my($configpm,$fh,$redo);
e82b9348 534 $redo ||= "";
e82b9348 535 if (defined $INC{"CPAN/Config.pm"} && -w $INC{"CPAN/Config.pm"}) {
547d3dfd
SP
536 $configpm = $INC{"CPAN/Config.pm"};
537 $redo++;
e82b9348 538 } elsif (defined $INC{"CPAN/MyConfig.pm"} && -w $INC{"CPAN/MyConfig.pm"}) {
547d3dfd
SP
539 $configpm = $INC{"CPAN/MyConfig.pm"};
540 $redo++;
e82b9348 541 } else {
547d3dfd
SP
542 my($path_to_cpan) = File::Basename::dirname($INC{"CPAN.pm"});
543 my($configpmdir) = File::Spec->catdir($path_to_cpan,"CPAN");
544 my($configpmtest) = File::Spec->catfile($configpmdir,"Config.pm");
c9869e1c 545 my $inc_key;
547d3dfd
SP
546 if (-d $configpmdir or File::Path::mkpath($configpmdir)) {
547 $configpm = _configpmtest($configpmdir,$configpmtest);
c9869e1c 548 $inc_key = "CPAN/Config.pm";
547d3dfd
SP
549 }
550 unless ($configpm) {
551 $configpmdir = File::Spec->catdir(home,".cpan","CPAN");
552 File::Path::mkpath($configpmdir);
553 $configpmtest = File::Spec->catfile($configpmdir,"MyConfig.pm");
554 $configpm = _configpmtest($configpmdir,$configpmtest);
c9869e1c 555 $inc_key = "CPAN/MyConfig.pm";
547d3dfd 556 }
c9869e1c
SP
557 if ($configpm) {
558 $INC{$inc_key} = $configpm;
559 } else {
560 my $text = qq{WARNING: CPAN.pm is unable to } .
561 qq{create a configuration file.};
562 output($text, 'confess');
563 }
564
e82b9348
SP
565 }
566 local($") = ", ";
547d3dfd 567 if ($redo && !$doit) {
8962fc49 568 $CPAN::Frontend->myprint(<<END);
0cf35e6a 569Sorry, we have to rerun the configuration dialog for CPAN.pm due to
547d3dfd 570some missing parameters...
e82b9348 571
e82b9348 572END
26844e27 573 $args{args} = \@miss;
8962fc49 574 }
e82b9348 575 CPAN::FirstTime::init($configpm, %args);
547d3dfd
SP
576 $loading--;
577 return;
e82b9348
SP
578}
579
b72dd56f
SP
580
581# returns mandatory but missing entries in the Config
e82b9348
SP
582sub missing_config_data {
583 my(@miss);
584 for (
b72dd56f 585 "auto_commit",
0cf35e6a
SP
586 "build_cache",
587 "build_dir",
588 "cache_metadata",
589 "cpan_home",
590 "ftp_proxy",
ed84aac9 591 #"gzip",
0cf35e6a
SP
592 "http_proxy",
593 "index_expire",
547d3dfd 594 #"inhibit_startup_message",
0cf35e6a 595 "keep_source_where",
ed84aac9 596 #"make",
0cf35e6a
SP
597 "make_arg",
598 "make_install_arg",
599 "makepl_arg",
600 "mbuild_arg",
601 "mbuild_install_arg",
5254b38e 602 ($^O eq "MSWin32" ? "" : "mbuild_install_build_command"),
0cf35e6a
SP
603 "mbuildpl_arg",
604 "no_proxy",
ed84aac9 605 #"pager",
e82b9348 606 "prerequisites_policy",
0cf35e6a 607 "scan_cache",
ed84aac9
A
608 #"tar",
609 #"unzip",
0cf35e6a 610 "urllist",
e82b9348 611 ) {
44d21104 612 next unless exists $keys{$_};
547d3dfd 613 push @miss, $_ unless defined $CPAN::Config->{$_};
e82b9348
SP
614 }
615 return @miss;
616}
617
e82b9348
SP
618sub help {
619 $CPAN::Frontend->myprint(q[
620Known options:
e82b9348 621 commit commit session changes to disk
4d1321a7
A
622 defaults reload default config values from disk
623 help this help
26844e27 624 init enter a dialog to set all or a set of parameters
e82b9348 625
4d1321a7 626Edit key values as in the following (the "o" is a literal letter o):
e82b9348 627 o conf build_cache 15
e82b9348 628 o conf build_dir "/foo/bar"
e82b9348 629 o conf urllist shift
e82b9348 630 o conf urllist unshift ftp://ftp.foo.bar/
4d1321a7 631 o conf inhibit_startup_message 1
e82b9348
SP
632
633]);
634 undef; #don't reprint CPAN::Config
635}
636
637sub cpl {
638 my($word,$line,$pos) = @_;
639 $word ||= "";
640 CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
641 my(@words) = split " ", substr($line,0,$pos+1);
642 if (
547d3dfd
SP
643 defined($words[2])
644 and
8962fc49
SP
645 $words[2] =~ /list$/
646 and
547d3dfd
SP
647 (
648 @words == 3
649 ||
650 @words == 4 && length($word)
651 )
e82b9348 652 ) {
547d3dfd 653 return grep /^\Q$word\E/, qw(splice shift unshift pop push);
8962fc49
SP
654 } elsif (defined($words[2])
655 and
656 $words[2] eq "init"
657 and
658 (
659 @words == 3
660 ||
26844e27 661 @words >= 4 && length($word)
8962fc49 662 )) {
547d3dfd 663 return sort grep /^\Q$word\E/, keys %keys;
e82b9348 664 } elsif (@words >= 4) {
547d3dfd 665 return ();
e82b9348
SP
666 }
667 my %seen;
668 my(@o_conf) = sort grep { !$seen{$_}++ }
669 keys %can,
670 keys %$CPAN::Config,
671 keys %keys;
672 return grep /^\Q$word\E/, @o_conf;
673}
674
6658a91b
SP
675sub prefs_lookup {
676 my($self,$distro,$what) = @_;
be34b10d 677
6658a91b 678 if ($prefssupport{$what}) {
be34b10d
SP
679 return $CPAN::Config->{$what} unless
680 $distro
681 and $distro->prefs
682 and $distro->prefs->{cpanconfig}
683 and defined $distro->prefs->{cpanconfig}{$what};
684 return $distro->prefs->{cpanconfig}{$what};
6658a91b 685 } else {
be34b10d
SP
686 $CPAN::Frontend->mywarn("Warning: $what not yet officially ".
687 "supported for distroprefs, doing a normal lookup");
6658a91b
SP
688 return $CPAN::Config->{$what};
689 }
690}
9ddc4ed0 691
9ddc4ed0 692
6658a91b
SP
693{
694 package
695 CPAN::Config; ####::###### #hide from indexer
696 # note: J. Nick Koston wrote me that they are using
697 # CPAN::Config->commit although undocumented. I suggested
698 # CPAN::Shell->o("conf","commit") even when ugly it is at least
699 # documented
700
701 # that's why I added the CPAN::Config class with autoload and
702 # deprecated warning
703
704 use strict;
705 use vars qw($AUTOLOAD $VERSION);
5254b38e 706 $VERSION = "5.5";
6658a91b
SP
707
708 # formerly CPAN::HandleConfig was known as CPAN::Config
f9916dde 709 sub AUTOLOAD { ## no critic
547d3dfd 710 my $class = shift; # e.g. in dh-make-perl: CPAN::Config
6658a91b
SP
711 my($l) = $AUTOLOAD;
712 $CPAN::Frontend->mywarn("Dispatching deprecated method '$l' to CPAN::HandleConfig\n");
713 $l =~ s/.*:://;
714 CPAN::HandleConfig->$l(@_);
715 }
9ddc4ed0
A
716}
717
e82b9348 7181;
0cf35e6a
SP
719
720__END__
26844e27
SP
721
722=head1 LICENSE
723
724This program is free software; you can redistribute it and/or
725modify it under the same terms as Perl itself.
726
727=cut
728
0cf35e6a
SP
729# Local Variables:
730# mode: cperl
ca79d794 731# cperl-indent-level: 4
0cf35e6a 732# End: