blib/lib/CPAN/HandleConfig.pm

filter: Statementstmt 14.4% 81 / 559 Branchbran 5.9% 20 / 334 Conditioncond 4.4% 10 / 226 MC/DCmcdc 0.0% 0 / 118 Subroutinesub 28.0% 14 / 50 Podpod 6.2% 2 / 32 totaltotal 9.6% 127 / 1319 CC 263 SCAR 55.0
CC
263
Cov
10%
edit
870.0
edit
870.0
load
257.7
CRAP 244.5
« blib/lib/CPAN/Module.pm ↑ Summary blib/lib/CPAN/Complete.pm »
1 package CPAN::HandleConfig;
2 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use vars qw(%can %keys $loading $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 CPAN::HandleConfig - internal configuration handling for CPAN.pm
12  
13 =cut
14  
15 27 $VERSION = "5.5014"; # see also CPAN::Config::VERSION at end of file
16  
17 27 %can = (
18 commit => "Commit changes to disk",
19 defaults => "Reload defaults from disk",
20 help => "Short help about 'o conf' usage",
21 init => "Interactive setting of all options",
22 );
23  
24 # Q: where is the "How do I add a new config option" HOWTO?
25 # A1: svn diff -r 757:758 # where dagolden added test_report [git e997b71de88f1019a1472fc13cb97b1b7f96610f]
26 # A2: svn diff -r 985:986 # where andk added yaml_module [git 312b6d9b12b1bdec0b6e282d853482145475021f]
27 # A3: 1. add new config option to %keys below
28 # 2. add a Pod description in CPAN::FirstTime in the DESCRIPTION
29 # section; it should include a prompt line; see others for
30 # examples
31 # 3. add a "matcher" section in CPAN::FirstTime::init that includes
32 # a prompt function; see others for examples
33 # 4. add config option to documentation section in CPAN.pm
34 # 5. possibly add the new variable to %prefssupport
35  
36 27 %keys = map { $_ => undef }
37 (
38 "allow_installing_module_downgrades",
39 "allow_installing_outdated_dists",
40 "applypatch",
41 "auto_commit",
42 "build_cache",
43 "build_dir",
44 "build_dir_reuse",
45 "build_requires_install_policy",
46 "bzip2",
47 "cache_metadata",
48 "check_sigs",
49 "cleanup_after_install",
50 "colorize_debug",
51 "colorize_output",
52 "colorize_print",
53 "colorize_warn",
54 "commandnumber_in_prompt",
55 "commands_quote",
56 "connect_to_internet_ok",
57 "cpan_home",
58 "curl",
59 "dontload_hash", # deprecated after 1.83_68 (rev. 581)
60 "dontload_list",
61 "ftp",
62 "ftp_passive",
63 "ftp_proxy",
64 "ftpstats_size",
65 "ftpstats_period",
66 "getcwd",
67 "gpg",
68 "gzip",
69 "halt_on_failure",
70 "histfile",
71 "histsize",
72 "http_proxy",
73 "inactivity_timeout",
74 "index_expire",
75 "inhibit_startup_message",
76 "keep_source_where",
77 "load_module_verbosity",
78 "lynx",
79 "make",
80 "make_arg",
81 "make_install_arg",
82 "make_install_make_command",
83 "makepl_arg",
84 "mbuild_arg",
85 "mbuild_install_arg",
86 "mbuild_install_build_command",
87 "mbuildpl_arg",
88 "ncftp",
89 "ncftpget",
90 "no_proxy",
91 "pager",
92 "password",
93 "patch",
94 "patches_dir",
95 "perl5lib_verbosity",
96 "plugin_list",
97 "prefer_external_tar",
98 "prefer_installer",
99 "prefs_dir",
100 "prerequisites_policy",
101 "proxy_pass",
102 "proxy_user",
103 "pushy_https",
104 "randomize_urllist",
105 "recommends_policy",
106 "scan_cache",
107 "shell",
108 "show_unparsable_versions",
109 "show_upload_date",
110 "show_zero_versions",
111 "suggests_policy",
112 "tar",
113 "tar_verbosity",
114 "term_is_latin",
115 "term_ornaments",
116 "test_report",
117 "trust_test_report_history",
118 "unzip",
119 "urllist",
120 "urllist_ping_verbose",
121 "urllist_ping_external",
122 "use_prompt_default",
123 "use_sqlite",
124 "use_static_install",
125 "username",
126 "version_timeout",
127 "wait_list",
128 "wget",
129 "yaml_load_code",
130 "yaml_module",
131 );
132  
133 27 my %prefssupport = map { $_ => 1 }
134 (
135 "allow_installing_module_downgrades",
136 "allow_installing_outdated_dists",
137 "build_requires_install_policy",
138 "check_sigs",
139 "make",
140 "make_install_make_command",
141 "prefer_installer",
142 "test_report",
143 );
144  
145 # returns true on successful action
146 0 ▶sub edit {
Subroutine edit: not called CC=29 SCAR=67.7
Pod undocumented
147 0 ▶ my($self,@args) = @_;
Subroutine edit: not called CC=29 SCAR=67.7
Pod undocumented
148 0 ▶ return unless @args;
Branch: 2 branches
BranchTrueFalseTotal
unless @args 0 0 0
unless @args 0 0 0
149 0 CPAN->debug("self[$self]args[".join(" | ",@args)."]");
150 0 my($o,$str,$func,$args,$key_exists);
151 0 $o = shift @args;
152 0 ▶ if($can{$o}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::HandleConfig::can{$o}) { } 0 0 0
if ($CPAN::HandleConfig::can{$o}) { } 0 0 0
153 0 my $success = $self->$o(args => \@args); # o conf init => sub init => sub load
154 0 ▶ unless ($success) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($success) 0 0 0
unless ($success) 0 0 0
155 0 die "Panic: could not configure CPAN.pm for args [@args]. Giving up.";
156 }
157 } else {
158 0 ▶ CPAN->debug("o[$o]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
159 0 ▶ unless (exists $keys{$o}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $CPAN::HandleConfig::keys{$o}) 0 0 0
unless (exists $CPAN::HandleConfig::keys{$o}) 0 0 0
160 0 $CPAN::Frontend->mywarn("Warning: unknown configuration variable '$o'\n");
161 }
162 0 require_myconfig_or_config();
163 0 my $changed;
164  
165 # one day I used randomize_urllist for a boolean, so we must
166 # list them explicitly --ak
167 0 ▶ if (0) {
Branch: 4 branches
BranchTrueFalseTotal
if (do { $o =~ /^(wait_list|urllist|dontload_list|plugin_list)$/ }) { } 0 0 0
elsif ($o =~ /_hash$/) { } 0 0 0
if (do { $o =~ /^(wait_list|urllist|dontload_list|plugin_list)$/ }) { } 0 0 0
elsif ($o =~ /_hash$/) { } 0 0 0
168 } elsif ($o =~ /^(wait_list|urllist|dontload_list|plugin_list)$/) {
169  
170 #
171 # ARRAYS
172 #
173  
174 0 $func = shift @args;
175 0 ▶ $func ||= "";
Condition0%0/4
$func ||= ""
l!l
00
$func ||= ""
l!l
00
MC/DC0%0/1
$func ||= ""
$func
MC/DC0%0/1
$func ||= ""
$func
Truth table0%0/2
A
A= $func
Aresult
11
00
Truth table0%0/2
A
A= $func
Aresult
11
00
176 0 ▶ CPAN->debug("func[$func]args[@args]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
177 # Let's avoid eval, it's easier to comprehend without.
178 0 ▶ if ($func eq "push") {
Branch: 12 branches
BranchTrueFalseTotal
if ($func eq 'push') { } 0 0 0
elsif ($func eq 'pop') { } 0 0 0
elsif ($func eq 'shift') { } 0 0 0
elsif ($func eq 'unshift') { } 0 0 0
elsif ($func eq 'splice') { } 0 0 0
elsif ($func) { } 0 0 0
if ($func eq 'push') { } 0 0 0
elsif ($func eq 'pop') { } 0 0 0
elsif ($func eq 'shift') { } 0 0 0
elsif ($func eq 'unshift') { } 0 0 0
elsif ($func eq 'splice') { } 0 0 0
elsif ($func) { } 0 0 0
179 0 push @{$CPAN::Config->{$o}}, @args;
180 0 $changed = 1;
181 } elsif ($func eq "pop") {
182 0 pop @{$CPAN::Config->{$o}};
183 0 $changed = 1;
184 } elsif ($func eq "shift") {
185 0 shift @{$CPAN::Config->{$o}};
186 0 $changed = 1;
187 } elsif ($func eq "unshift") {
188 0 unshift @{$CPAN::Config->{$o}}, @args;
189 0 $changed = 1;
190 } elsif ($func eq "splice") {
191 0 ▶ my $offset = shift @args || 0;
Condition0%0/4
shift @args || 0
l!l
00
shift @args || 0
l!l
00
MC/DC0%0/1
shift @args || 0
shift @args
MC/DC0%0/1
shift @args || 0
shift @args
Truth table0%0/2
A
A= shift @args
Aresult
11
00
Truth table0%0/2
A
A= shift @args
Aresult
11
00
192 0 ▶ my $length = shift @args || 0;
Condition0%0/4
shift @args || 0
l!l
00
shift @args || 0
l!l
00
MC/DC0%0/1
shift @args || 0
shift @args
MC/DC0%0/1
shift @args || 0
shift @args
Truth table0%0/2
A
A= shift @args
Aresult
11
00
Truth table0%0/2
A
A= shift @args
Aresult
11
00
193 0 splice @{$CPAN::Config->{$o}}, $offset, $length, @args; # may warn
194 0 $changed = 1;
195 } elsif ($func) {
196 0 $CPAN::Config->{$o} = [$func, @args];
197 0 $changed = 1;
198 } else {
199 0 $self->prettyprint($o);
200 }
201 0 ▶ if ($changed) {
Branch: 2 branches
BranchTrueFalseTotal
if ($changed) 0 0 0
if ($changed) 0 0 0
202 0 ▶ if ($o eq "urllist") {
Branch: 4 branches
BranchTrueFalseTotal
if ($o eq 'urllist') { } 0 0 0
elsif ($o eq 'dontload_list') { } 0 0 0
if ($o eq 'urllist') { } 0 0 0
elsif ($o eq 'dontload_list') { } 0 0 0
203 # reset the cached values
204 0 undef $CPAN::FTP::Thesite;
205 0 undef $CPAN::FTP::Themethod;
206 0 $CPAN::Index::LAST_TIME = 0;
207 } elsif ($o eq "dontload_list") {
208 # empty it, it will be built up again
209 0 $CPAN::META->{dontload_hash} = {};
210 }
211 }
212 } elsif ($o =~ /_hash$/) {
213  
214 #
215 # HASHES
216 #
217  
218 0 ▶ if (@args==1 && $args[0] eq "") {
Branch: 4 branches
BranchTrueFalseTotal
if (@args == 1 and $args[0] eq '') { } 0 0 0
elsif (@args % 2) { } 0 0 0
if (@args == 1 and $args[0] eq '') { } 0 0 0
elsif (@args % 2) { } 0 0 0
Condition0%0/6
@args == 1 and $args[0] eq ""
!ll&&!rl&&r
000
@args == 1 and $args[0] eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
@args == 1 and $args[0] eq ""
@args == 1 $args[0] eq ""
MC/DC0%0/2
@args == 1 and $args[0] eq ""
@args == 1 $args[0] eq ""
Truth table0%0/3
A and B
A= @args == 1B= $args[0] eq ""
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @args == 1B= $args[0] eq ""
ABresult
0X0
100
111
219 0 @args = ();
220 } elsif (@args % 2) {
221 0 push @args, "";
222 }
223 0 $CPAN::Config->{$o} = { @args };
224 0 $changed = 1;
225 } else {
226  
227 #
228 # SCALARS
229 #
230  
231 0 ▶ if (defined $args[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args[0]) 0 0 0
if (defined $args[0]) 0 0 0
232 0 $CPAN::CONFIG_DIRTY = 1;
233 0 $CPAN::Config->{$o} = $args[0];
234 0 $changed = 1;
235 }
236 $self->prettyprint($o)
237 0 ▶ if exists $keys{$o} or defined $CPAN::Config->{$o};
Branch: 2 branches
BranchTrueFalseTotal
if exists $CPAN::HandleConfig::keys{$o} or defined $CPAN::Config->{$o} 0 0 0
if exists $CPAN::HandleConfig::keys{$o} or defined $CPAN::Config->{$o} 0 0 0
Condition0%0/6
exists $CPAN::HandleConfig::keys{$o} or defined $CPAN::Config->{$o}
l!l&&r!l&&!r
000
exists $CPAN::HandleConfig::keys{$o} or defined $CPAN::Config->{$o}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $CPAN::HandleConfig::keys{$o} or defined $CPAN::Config->{$o}
exists $CPAN::HandleConfig::keys{$o} defined $CPAN::Config->{$o}
MC/DC0%0/2
exists $CPAN::HandleConfig::keys{$o} or defined $CPAN::Config->{$o}
exists $CPAN::HandleConfig::keys{$o} defined $CPAN::Config->{$o}
Truth table0%0/3
A or B
A= exists $CPAN::HandleConfig::keys{$o}B= defined $CPAN::Config->{$o}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= exists $CPAN::HandleConfig::keys{$o}B= defined $CPAN::Config->{$o}
ABresult
1X1
011
000
238 }
239 0 ▶ if ($changed) {
Branch: 2 branches
BranchTrueFalseTotal
if ($changed) 0 0 0
if ($changed) 0 0 0
240 0 ▶ if ($CPAN::Config->{auto_commit}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::Config->{'auto_commit'}) { } 0 0 0
if ($CPAN::Config->{'auto_commit'}) { } 0 0 0
241 0 $self->commit;
242 } else {
243 0 $CPAN::CONFIG_DIRTY = 1;
244 0 $CPAN::Frontend->myprint("Please use 'o conf commit' to ".
245 "make the config permanent!\n\n");
246 }
247 }
248 }
249 }
250  
251 0 ▶sub prettyprint {
Subroutine prettyprint: not called CC=5 SCAR=34.0
Pod undocumented
252 0 ▶ my($self,$k) = @_;
Subroutine prettyprint: not called CC=5 SCAR=34.0
Pod undocumented
253 0 my $v = $CPAN::Config->{$k};
254 0 ▶ if (ref $v) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $v) { } 0 0 0
elsif (defined $v) { } 0 0 0
if (ref $v) { } 0 0 0
elsif (defined $v) { } 0 0 0
255 0 my(@report);
256 0 ▶ if (ref $v eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 0 0 0
if (ref $v eq 'ARRAY') { } 0 0 0
257 0 @report = map {"\t$_ \[$v->[$_]]\n"} 0..$#$v;
258 } else {
259 @report = map
260 {
261 0 sprintf "\t%-18s => %s\n",
262 "[$_]",
263 0 ▶ defined $v->{$_} ? "[$v->{$_}]" : "undef"
Branch: 2 branches
BranchTrueFalseTotal
defined $v->{$_} ? : 0 0 0
defined $v->{$_} ? : 0 0 0
264 } sort keys %$v;
265 }
266 0 $CPAN::Frontend->myprint(
267 join(
268 "",
269 sprintf(
270 " %-18s\n",
271 $k
272 ),
273 @report
274 )
275 );
276 } elsif (defined $v) {
277 0 $CPAN::Frontend->myprint(sprintf " %-18s [%s]\n", $k, $v);
278 } else {
279 0 $CPAN::Frontend->myprint(sprintf " %-18s undef\n", $k);
280 }
281 }
282  
283 # generally, this should be called without arguments so that the currently
284 # loaded config file is where changes are committed.
285 0 ▶sub commit {
Subroutine commit: not called CC=13 SCAR=52.0
Pod undocumented
286 0 ▶ my($self,@args) = @_;
Subroutine commit: not called CC=13 SCAR=52.0
Pod undocumented
287 0 ▶ CPAN->debug("args[@args]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
288 0 ▶ if ($CPAN::RUN_DEGRADED) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::RUN_DEGRADED) 0 0 0
if ($CPAN::RUN_DEGRADED) 0 0 0
289 0 $CPAN::Frontend->mydie(
290 "'o conf commit' disabled in ".
291 "degraded mode. Maybe try\n".
292 " !undef \$CPAN::RUN_DEGRADED\n"
293 );
294 }
295 0 my ($configpm, $must_reload);
296  
297 # XXX does anything do this? can it be simplified? -- dagolden, 2011-01-19
298 0 ▶ if (@args) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args) 0 0 0
if (@args) 0 0 0
299 0 ▶ if ($args[0] eq "args") {
Branch: 2 branches
BranchTrueFalseTotal
if ($args[0] eq 'args') { } 0 0 0
if ($args[0] eq 'args') { } 0 0 0
300 # we have not signed that contract
301 } else {
302 0 $configpm = $args[0];
303 }
304 }
305  
306 # use provided name or the current config or create a new MyConfig
307 0 ▶ $configpm ||= require_myconfig_or_config() || make_new_config();
Condition0%0/12
$configpm ||= &require_myconfig_or_config() || make_new_config()
l!l&&r!l&&!r
000
&require_myconfig_or_config() || make_new_config()
l!l&&r!l&&!r
000
$configpm ||= &require_myconfig_or_config() || make_new_config()
l!l&&r!l&&!r
000
&require_myconfig_or_config() || make_new_config()
l!l&&r!l&&!r
000
MC/DC0%0/3
$configpm ||= &require_myconfig_or_config() || make_new_config()
$configpm &require_myconfig_or_config() make_new_config()
MC/DC0%0/3
$configpm ||= &require_myconfig_or_config() || make_new_config()
$configpm &require_myconfig_or_config() make_new_config()
Truth table0%0/4
A ||= B || C
A= $configpmB= &require_myconfig_or_config()C= make_new_config()
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A ||= B || C
A= $configpmB= &require_myconfig_or_config()C= make_new_config()
ABCresult
1XX1
01X1
0011
0000
308  
309 # commit to MyConfig if we can't write to Config
310 0 ▶ if ( ! -w $configpm && $configpm =~ m{CPAN/Config\.pm} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -w $configpm and $configpm =~ m[CPAN/Config\.pm]) 0 0 0
if (not -w $configpm and $configpm =~ m[CPAN/Config\.pm]) 0 0 0
Condition0%0/6
not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
!ll&&!rl&&r
000
not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
!ll&&!rl&&r
000
MC/DC0%0/2
not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
not -w $configpm $configpm =~ m[CPAN/Config\.pm]
MC/DC0%0/2
not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
not -w $configpm $configpm =~ m[CPAN/Config\.pm]
Truth table0%0/3
not(A) and B
A= not -w $configpmB= $configpm =~ m[CPAN/Config\.pm]
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not -w $configpmB= $configpm =~ m[CPAN/Config\.pm]
ABresult
0X0
100
111
311 0 my $myconfig = _new_config_name();
312 0 $CPAN::Frontend->mywarn(
313 "Your $configpm file\n".
314 "is not writable. I will attempt to write your configuration to\n" .
315 "$myconfig instead.\n\n"
316 );
317 0 $configpm = make_new_config();
318 0 $must_reload++; # so it gets loaded as $INC{'CPAN/MyConfig.pm'}
319 }
320  
321 # XXX why not just "-w $configpm"? -- dagolden, 2011-01-19
322 0 my($mode);
323 0 ▶ if (-f $configpm) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $configpm) 0 0 0
if (-f $configpm) 0 0 0
324 0 $mode = (stat $configpm)[2];
325 0 ▶ if ($mode && ! -w _) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode and not -w _) 0 0 0
if ($mode and not -w _) 0 0 0
Condition0%0/6
$mode and not -w _
!ll&&!rl&&r
000
$mode and not -w _
!ll&&!rl&&r
000
MC/DC0%0/2
$mode and not -w _
$mode not -w _
MC/DC0%0/2
$mode and not -w _
$mode not -w _
Truth table0%0/3
A and not(B)
A= $modeB= not -w _
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $modeB= not -w _
ABresult
0X0
100
111
326 0 _die_cant_write_config($configpm);
327 }
328 }
329  
330 0 $self->_write_config_file($configpm);
331 0 ▶ require_myconfig_or_config() if $must_reload;
Branch: 2 branches
BranchTrueFalseTotal
if $must_reload 0 0 0
if $must_reload 0 0 0
332  
333 #$mode = 0444 | ( $mode & 0111 ? 0111 : 0 );
334 #chmod $mode, $configpm;
335 ###why was that so? $self->defaults;
336 0 $CPAN::Frontend->myprint("commit: wrote '$configpm'\n");
337 0 $CPAN::CONFIG_DIRTY = 0;
338 0 1;
339 }
340  
341 0 ▶sub _write_config_file {
Subroutine _write_config_file: not called CC=7 SCAR=40.3
342 0 ▶ my ($self, $configpm) = @_;
Subroutine _write_config_file: not called CC=7 SCAR=40.3
343 0 my $msg;
344 0 ▶ $msg = <<EOF if $configpm =~ m{CPAN/Config\.pm};
Branch: 2 branches
BranchTrueFalseTotal
if $configpm =~ m[CPAN/Config\.pm] 0 0 0
if $configpm =~ m[CPAN/Config\.pm] 0 0 0
345  
346 # This is CPAN.pm's systemwide configuration file. This file provides
347 # defaults for users, and the values can be changed in a per-user
348 # configuration file.
349  
350 EOF
351 0 ▶ $msg ||= "\n";
Condition0%0/4
$msg ||= "\n"
l!l
00
$msg ||= "\n"
l!l
00
MC/DC0%0/1
$msg ||= "\n"
$msg
MC/DC0%0/1
$msg ||= "\n"
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
Truth table0%0/2
A
A= $msg
Aresult
11
00
352 0 my($fh) = FileHandle->new;
353 0 ▶ rename $configpm, "$configpm~" if -f $configpm;
Branch: 2 branches
BranchTrueFalseTotal
if -f $configpm 0 0 0
if -f $configpm 0 0 0
354 0 ▶ open $fh, ">$configpm" or
Branch: 2 branches
BranchTrueFalseTotal
open $fh, ">$configpm" or $CPAN::Frontend->mydie("Couldn't open >${configpm}: $!") 0 0 0
open $fh, ">$configpm" or $CPAN::Frontend->mydie("Couldn't open >${configpm}: $!") 0 0 0
355 $CPAN::Frontend->mydie("Couldn't open >$configpm: $!");
356 0 $fh->print(qq[$msg\$CPAN::Config = \{\n]);
357 0 foreach (sort keys %$CPAN::Config) {
358 0 ▶ unless (exists $keys{$_}) {
Branch: 2 branches
BranchTrueFalseTotal
unless (exists $CPAN::HandleConfig::keys{$_}) 0 0 0
unless (exists $CPAN::HandleConfig::keys{$_}) 0 0 0
359 # do not drop them: forward compatibility!
360 0 $CPAN::Frontend->mywarn("Unknown config variable '$_'\n");
361 0 next;
362 }
363 $fh->print(
364 " '$_' => ",
365 0 $self->neatvalue($CPAN::Config->{$_}),
366 ",\n"
367 );
368 }
369 0 $fh->print("};\n1;\n__END__\n");
370 0 close $fh;
371  
372 0 return;
373 }
374  
375  
376 # stolen from MakeMaker; not taking the original because it is buggy;
377 # bugreport will have to say: keys of hashes remain unquoted and can
378 # produce syntax errors
379 7 ▶sub neatvalue {
Subroutine neatvalue: called CC=7 SCAR=26.8
Pod undocumented
380 0 ▶ my($self, $v) = @_;
Subroutine neatvalue: not called CC=7 SCAR=26.8
Pod undocumented
381 0 ▶ return "undef" unless defined $v;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $v 0 7 7
unless defined $v 0 0 0
382 0 my($t) = ref $v;
383 0 ▶ unless ($t) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($t) 4 3 7
unless ($t) 0 0 0
384 0 $v =~ s/\\/\\\\/g;
385 0 return "q[$v]";
386 }
387 0 ▶ if ($t eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($t eq "ARRAY") 1 2 3
if ($t eq "ARRAY") 0 0 0
388 0 my(@m, @neat);
389 0 push @m, "[";
390 0 foreach my $elem (@$v) {
391 0 push @neat, "q[$elem]";
392 }
393 0 push @m, join ", ", @neat;
394 0 push @m, "]";
395 0 return join "", @m;
396 }
397 0 ▶ return "$v" unless $t eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless $t eq "HASH" 0 2 2
unless $t eq "HASH" 0 0 0
398 0 my @m;
399 0 foreach my $key (sort keys %$v) {
400 0 my $val = $v->{$key};
401 0 push(@m,"q[$key]=>".$self->neatvalue($val)) ;
402 }
403 0 return "{ ".join(', ',@m)." }";
404 }
405  
406 0 ▶sub defaults {
Subroutine defaults: not called CC=5 SCAR=34.0
Pod undocumented
407 0 ▶ my($self) = @_;
Subroutine defaults: not called CC=5 SCAR=34.0
Pod undocumented
408 0 ▶ if ($CPAN::RUN_DEGRADED) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::RUN_DEGRADED) 0 0 0
if ($CPAN::RUN_DEGRADED) 0 0 0
409 0 $CPAN::Frontend->mydie(
410 "'o conf defaults' disabled in ".
411 "degraded mode. Maybe try\n".
412 " !undef \$CPAN::RUN_DEGRADED\n"
413 );
414 }
415 0 my $done;
416 0 for my $config (qw(CPAN/MyConfig.pm CPAN/Config.pm)) {
417 0 ▶ if ($INC{$config}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($INC{$config}) 0 0 0
if ($INC{$config}) 0 0 0
418 0 ▶ CPAN->debug("INC{'$config'}[$INC{$config}]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
419 0 CPAN::Shell->_reload_this($config,{reloforce => 1});
420 0 $CPAN::Frontend->myprint("'$INC{$config}' reread\n");
421 0 last;
422 }
423 }
424 0 $CPAN::CONFIG_DIRTY = 0;
425 0 1;
426 }
427  
428 =head2 C<< CLASS->safe_quote ITEM >>
429  
430 Quotes an item to become safe against spaces
431 in shell interpolation. An item is enclosed
432 in double quotes if:
433  
434 - the item contains spaces in the middle
435 - the item does not start with a quote
436  
437 This happens to avoid shell interpolation
438 problems when whitespace is present in
439 directory names.
440  
441 This method uses C<commands_quote> to determine
442 the correct quote. If C<commands_quote> is
443 a space, no quoting will take place.
444  
445  
446 if it starts and ends with the same quote character: leave it as it is
447  
448 if it contains no whitespace: leave it as it is
449  
450 if it contains whitespace, then
451  
452 if it contains quotes: better leave it as it is
453  
454 else: quote it with the correct quote type for the box we're on
455  
456 =cut
457  
458 {
459 # Instead of patching the guess, set commands_quote
460 # to the right value
461 27 ▶ my ($quotes,$use_quote)
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 27 27
462 = $^O eq 'MSWin32'
463 ? ('"', '"')
464 : (q{"'}, "'")
465 ;
466  
467 32 ▶ sub safe_quote {
Subroutine safe_quote: called CC=6 SCAR=30.9
Pod documented
468 0 ▶ my ($self, $command) = @_;
Subroutine safe_quote: not called CC=6 SCAR=30.9
Pod documented
469 # Set up quote/default quote
470 0 ▶ my $quote = $CPAN::Config->{commands_quote} || $quotes;
Condition16%1/6
$CPAN::Config->{'commands_quote'} || $quotes
l!l&&r!l&&!r
0320
$CPAN::Config->{'commands_quote'} || $quotes
l!l&&r!l&&!r
000
MC/DC0%0/2
$CPAN::Config->{'commands_quote'} || $quotes
$CPAN::Config->{'commands_quote'} $quotes
MC/DC0%0/2
$CPAN::Config->{'commands_quote'} || $quotes
$CPAN::Config->{'commands_quote'} $quotes
Truth table33%1/3
A || B
A= $CPAN::Config->{'commands_quote'}B= $quotes
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $CPAN::Config->{'commands_quote'}B= $quotes
ABresult
1X1
011
000
471  
472 0 ▶ if ($quote ne ' '
Branch: 2 branches
BranchTrueFalseTotal
if ($quote ne " " and defined $command and $command =~ /\s/ and not $command =~ /[$quote]/) 0 32 32
if ($quote ne " " and defined $command and $command =~ /\s/ and not $command =~ /[$quote]/) 0 0 0
Condition16%3/18
$quote ne " " and defined $command and $command =~ /\s/ and not $command =~ /[$quote]/
!ll&&!rl&&r
3200
$quote ne " " and defined $command and $command =~ /\s/
!ll&&!rl&&r
0320
$quote ne " " and defined $command
!ll&&!rl&&r
0032
$quote ne " " and defined $command and $command =~ /\s/ and not $command =~ /[$quote]/
!ll&&!rl&&r
000
$quote ne " " and defined $command and $command =~ /\s/
!ll&&!rl&&r
000
$quote ne " " and defined $command
!ll&&!rl&&r
000
MC/DC0%0/4
$quote ne " " and defined $command and $command =~ /\s/ and not $command =~ /[$quote]/
$quote ne " " defined $command $command =~ /\s/ not $command =~ /[$quote]/
MC/DC0%0/4
$quote ne " " and defined $command and $command =~ /\s/ and not $command =~ /[$quote]/
$quote ne " " defined $command $command =~ /\s/ not $command =~ /[$quote]/
Truth table20%1/5
A and B and C and not(D)
A= $quote ne " "B= defined $commandC= $command =~ /\s/D= not $command =~ /[$quote]/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and not(D)
A= $quote ne " "B= defined $commandC= $command =~ /\s/D= not $command =~ /[$quote]/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
473 and defined($command )
474 and $command =~ /\s/
475 and $command !~ /[$quote]/) {
476 0 return qq<$use_quote$command$use_quote>
477 }
478 0 return $command;
479 }
480 }
481  
482 27 ▶sub init {
Subroutine init: not called CC=1 SCAR=5.3
Pod undocumented
483 0 ▶ my($self,@args) = @_;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
484 0 CPAN->debug("self[$self]args[".join(",",@args)."]");
485 0 $self->load(do_init => 1, @args);
486 0 1;
487 }
488  
489 # Loads CPAN::MyConfig or fall-back to CPAN::Config. Will not reload a file
490 # if already loaded. Returns the path to the file %INC or else the empty string
491 #
492 # Note -- if CPAN::Config were loaded and CPAN::MyConfig subsequently
493 # created, calling this again will leave *both* in %INC
494  
495 37 ▶sub require_myconfig_or_config () {
Subroutine require_myconfig_or_config: called CC=5 SCAR=30.3
Pod undocumented
496 0 ▶ if ( $INC{"CPAN/MyConfig.pm"} || _try_loading("CPAN::MyConfig", cpan_home())) {
Subroutine require_myconfig_or_config: not called CC=5 SCAR=30.3
Pod undocumented
Branch: 4 branches
BranchTrueFalseTotal
if ($INC{'CPAN/MyConfig.pm'} or _try_loading('CPAN::MyConfig', cpan_home())) { } 37 0 37
elsif ($INC{'CPAN/Config.pm'} or _try_loading('CPAN::Config')) { } 0 0 0
if ($INC{'CPAN/MyConfig.pm'} or _try_loading('CPAN::MyConfig', cpan_home())) { } 0 0 0
elsif ($INC{'CPAN/Config.pm'} or _try_loading('CPAN::Config')) { } 0 0 0
Condition16%1/6
$INC{"CPAN/MyConfig.pm"} or _try_loading("CPAN::MyConfig", cpan_home())
l!l&&r!l&&!r
3700
$INC{"CPAN/MyConfig.pm"} or _try_loading("CPAN::MyConfig", cpan_home())
l!l&&r!l&&!r
000
MC/DC0%0/2
$INC{"CPAN/MyConfig.pm"} or _try_loading("CPAN::MyConfig", cpan_home())
$INC{"CPAN/MyConfig.pm"} _try_loading("CPAN::MyConfig", cpan_home())
MC/DC0%0/2
$INC{"CPAN/MyConfig.pm"} or _try_loading("CPAN::MyConfig", cpan_home())
$INC{"CPAN/MyConfig.pm"} _try_loading("CPAN::MyConfig", cpan_home())
Truth table33%1/3
A or B
A= $INC{"CPAN/MyConfig.pm"}B= _try_loading("CPAN::MyConfig", cpan_home())
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $INC{"CPAN/MyConfig.pm"}B= _try_loading("CPAN::MyConfig", cpan_home())
ABresult
1X1
011
000
497 0 return $INC{"CPAN/MyConfig.pm"};
498 }
499 ▶ elsif ( $INC{"CPAN/Config.pm"} || _try_loading("CPAN::Config") ) {
Condition0%0/6
$INC{"CPAN/Config.pm"} or _try_loading("CPAN::Config")
l!l&&r!l&&!r
000
$INC{"CPAN/Config.pm"} or _try_loading("CPAN::Config")
l!l&&r!l&&!r
000
MC/DC0%0/2
$INC{"CPAN/Config.pm"} or _try_loading("CPAN::Config")
$INC{"CPAN/Config.pm"} _try_loading("CPAN::Config")
MC/DC0%0/2
$INC{"CPAN/Config.pm"} or _try_loading("CPAN::Config")
$INC{"CPAN/Config.pm"} _try_loading("CPAN::Config")
Truth table0%0/3
A or B
A= $INC{"CPAN/Config.pm"}B= _try_loading("CPAN::Config")
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $INC{"CPAN/Config.pm"}B= _try_loading("CPAN::Config")
ABresult
1X1
011
000
500 0 return $INC{"CPAN/Config.pm"};
501 }
502 else {
503 0 return q{};
504 }
505 }
506  
507 # Load a module, but ignore "can't locate..." errors
508 # Optionally take a list of directories to add to @INC for the load
509 0 ▶sub _try_loading {
Subroutine _try_loading: not called CC=5 SCAR=34.0
510 0 ▶ my ($module, @dirs) = @_;
Subroutine _try_loading: not called CC=5 SCAR=34.0
511 0 (my $file = $module) =~ s{::}{/}g;
512 0 $file .= ".pm";
513  
514 0 local @INC = @INC;
515 0 for my $dir ( @dirs ) {
516 0 ▶ if ( -f File::Spec->catfile($dir, $file) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f "File::Spec"->catfile($dir, $file)) 0 0 0
if (-f "File::Spec"->catfile($dir, $file)) 0 0 0
517 0 unshift @INC, $dir;
518 0 last;
519 }
520 }
521  
522 0 eval { require $file };
523 0 my $err_myconfig = $@;
524 0 ▶ if ($err_myconfig and $err_myconfig !~ m#locate \Q$file\E#) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err_myconfig and not $err_myconfig =~ /locate \Q$file\E/) 0 0 0
if ($err_myconfig and not $err_myconfig =~ /locate \Q$file\E/) 0 0 0
Condition0%0/6
$err_myconfig and not $err_myconfig =~ /locate \Q$file\E/
!ll&&!rl&&r
000
$err_myconfig and not $err_myconfig =~ /locate \Q$file\E/
!ll&&!rl&&r
000
MC/DC0%0/2
$err_myconfig and not $err_myconfig =~ /locate \Q$file\E/
$err_myconfig not $err_myconfig =~ /locate \Q$file\E/
MC/DC0%0/2
$err_myconfig and not $err_myconfig =~ /locate \Q$file\E/
$err_myconfig not $err_myconfig =~ /locate \Q$file\E/
Truth table0%0/3
A and not(B)
A= $err_myconfigB= not $err_myconfig =~ /locate \Q$file\E/
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $err_myconfigB= not $err_myconfig =~ /locate \Q$file\E/
ABresult
0X0
100
111
525 0 die "Error while requiring ${module}:\n$err_myconfig";
526 }
527 0 return $INC{$file};
528 }
529  
530 # prioritized list of possible places for finding "CPAN/MyConfig.pm"
531 0 ▶sub cpan_home_dir_candidates {
Subroutine cpan_home_dir_candidates: not called CC=9 SCAR=45.0
Pod undocumented
532 0 ▶ my @dirs;
Subroutine cpan_home_dir_candidates: not called CC=9 SCAR=45.0
Pod undocumented
533 0 my $old_v = $CPAN::Config->{load_module_verbosity};
534 0 $CPAN::Config->{load_module_verbosity} = q[none];
535 0 ▶ if ($CPAN::META->has_usable('File::HomeDir')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CPAN::META->has_usable("File::HomeDir")) 0 0 0
if ($CPAN::META->has_usable("File::HomeDir")) 0 0 0
536 0 ▶ if ($^O ne 'darwin') {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O ne "darwin") 0 0 0
if ($^O ne "darwin") 0 0 0
537 0 push @dirs, File::HomeDir->my_data;
538 # my_data is ~/Library/Application Support on darwin,
539 # which causes issues in the toolchain.
540 }
541 0 push @dirs, File::HomeDir->my_home;
542 }
543 # Windows might not have HOME, so check it first
544 0 ▶ push @dirs, $ENV{HOME} if $ENV{HOME};
Branch: 2 branches
BranchTrueFalseTotal
if $ENV{"HOME"} 0 0 0
if $ENV{"HOME"} 0 0 0
545 # Windows might have these instead
546 push( @dirs, File::Spec->catpath($ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '') )
547 0 ▶ if $ENV{HOMEDRIVE} && $ENV{HOMEPATH};
Branch: 2 branches
BranchTrueFalseTotal
if $ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"} 0 0 0
if $ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"} 0 0 0
Condition0%0/6
$ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}
!ll&&!rl&&r
000
$ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}
$ENV{"HOMEDRIVE"} $ENV{"HOMEPATH"}
MC/DC0%0/2
$ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}
$ENV{"HOMEDRIVE"} $ENV{"HOMEPATH"}
Truth table0%0/3
A and B
A= $ENV{"HOMEDRIVE"}B= $ENV{"HOMEPATH"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $ENV{"HOMEDRIVE"}B= $ENV{"HOMEPATH"}
ABresult
0X0
100
111
548 0 ▶ push @dirs, $ENV{USERPROFILE} if $ENV{USERPROFILE};
Branch: 2 branches
BranchTrueFalseTotal
if $ENV{"USERPROFILE"} 0 0 0
if $ENV{"USERPROFILE"} 0 0 0
549  
550 0 $CPAN::Config->{load_module_verbosity} = $old_v;
551 0 ▶ my $dotcpan = $^O eq 'VMS' ? '_cpan' : '.cpan';
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'VMS' ? : 0 0 0
$^O eq 'VMS' ? : 0 0 0
552 0 @dirs = map { File::Spec->catdir($_, $dotcpan) } grep { defined } @dirs;
553 0 ▶ return wantarray ? @dirs : $dirs[0];
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
wantarray ? : 0 0 0
554 }
555  
556 37 ▶sub load {
Subroutine load: called CC=19 SCAR=55.5
Pod undocumented
557 0 ▶ my($self, %args) = @_;
Subroutine load: not called CC=19 SCAR=55.5
Pod undocumented
558 0 $CPAN::Be_Silent+=0; # protect against 'used only once'
559 0 ▶ $CPAN::Be_Silent++ if $args{be_silent}; # do not use; planned to be removed in 2011
Branch: 2 branches
BranchTrueFalseTotal
if $args{"be_silent"} 0 37 37
if $args{"be_silent"} 0 0 0
560 0 ▶ my $do_init = delete $args{do_init} || 0;
Condition25%1/4
delete $args{'do_init'} || 0
l!l
037
delete $args{'do_init'} || 0
l!l
00
MC/DC0%0/1
delete $args{'do_init'} || 0
delete $args{'do_init'}
MC/DC0%0/1
delete $args{'do_init'} || 0
delete $args{'do_init'}
Truth table50%1/2
A
A= delete $args{'do_init'}
Aresult
11
00
Truth table0%0/2
A
A= delete $args{'do_init'}
Aresult
11
00
561 0 my $make_myconfig = delete $args{make_myconfig};
562 0 ▶ $loading = 0 unless defined $loading;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $CPAN::HandleConfig::loading 13 24 37
unless defined $CPAN::HandleConfig::loading 0 0 0
563  
564 0 my $configpm = require_myconfig_or_config;
565 0 my @miss = $self->missing_config_data;
566 0 ▶ CPAN->debug("do_init[$do_init]loading[$loading]miss[@miss]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 37 37
if $CPAN::DEBUG 0 0 0
567 0 ▶ return unless $do_init || @miss;
Branch: 2 branches
BranchTrueFalseTotal
unless $do_init or @miss 37 0 37
unless $do_init or @miss 0 0 0
Condition16%1/6
$do_init or @miss
l!l&&r!l&&!r
0037
$do_init or @miss
l!l&&r!l&&!r
000
MC/DC0%0/2
$do_init or @miss
$do_init @miss
MC/DC0%0/2
$do_init or @miss
$do_init @miss
Truth table33%1/3
A or B
A= $do_initB= @miss
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $do_initB= @miss
ABresult
1X1
011
000
568 0 ▶ if (@miss==1 and $miss[0] eq "pushy_https" && !$do_init) {
Branch: 2 branches
BranchTrueFalseTotal
if (@miss == 1 and ($miss[0] eq "pushy_https" and not $do_init)) 0 0 0
if (@miss == 1 and ($miss[0] eq "pushy_https" and not $do_init)) 0 0 0
Condition0%0/12
@miss == 1 and ($miss[0] eq "pushy_https" and not $do_init)
!ll&&!rl&&r
000
$miss[0] eq "pushy_https" and not $do_init
!ll&&!rl&&r
000
@miss == 1 and ($miss[0] eq "pushy_https" and not $do_init)
!ll&&!rl&&r
000
$miss[0] eq "pushy_https" and not $do_init
!ll&&!rl&&r
000
MC/DC0%0/3
@miss == 1 and ($miss[0] eq "pushy_https" and not $do_init)
@miss == 1 $miss[0] eq "pushy_https" not $do_init
MC/DC0%0/3
@miss == 1 and ($miss[0] eq "pushy_https" and not $do_init)
@miss == 1 $miss[0] eq "pushy_https" not $do_init
Truth table0%0/4
A and B and not(C)
A= @miss == 1B= $miss[0] eq "pushy_https"C= not $do_init
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= @miss == 1B= $miss[0] eq "pushy_https"C= not $do_init
ABCresult
0XX0
10X0
1100
1111
569 0 $CPAN::Frontend->myprint(<<'END');
570  
571 Starting with version 2.29 of the cpan shell, a new download mechanism
572 is the default which exclusively uses cpan.org as the host to download
573 from. The configuration variable pushy_https can be used to (de)select
574 the new mechanism. Please read more about it and make your choice
575 between the old and the new mechanism by running
576  
577 o conf init pushy_https
578  
579 Once you have done that and stored the config variable this dialog
580 will disappear.
581 END
582  
583 0 return;
584 }
585  
586 # I'm not how we'd ever wind up in a recursive loop, but I'm leaving
587 # this here for safety's sake -- dagolden, 2011-01-19
588 0 ▶ return if $loading;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::HandleConfig::loading 0 0 0
if $CPAN::HandleConfig::loading 0 0 0
589 0 ▶ local $loading = ($loading||0) + 1;
Condition0%0/4
$CPAN::HandleConfig::loading || 0
l!l
00
$CPAN::HandleConfig::loading || 0
l!l
00
MC/DC0%0/1
$CPAN::HandleConfig::loading || 0
$CPAN::HandleConfig::loading
MC/DC0%0/1
$CPAN::HandleConfig::loading || 0
$CPAN::HandleConfig::loading
Truth table0%0/2
A
A= $CPAN::HandleConfig::loading
Aresult
11
00
Truth table0%0/2
A
A= $CPAN::HandleConfig::loading
Aresult
11
00
590  
591 # Warn if we have a config file, but things were found missing
592 0 ▶ if ($configpm && @miss && !$do_init) {
Branch: 2 branches
BranchTrueFalseTotal
if ($configpm and @miss and not $do_init) 0 0 0
if ($configpm and @miss and not $do_init) 0 0 0
Condition0%0/12
$configpm and @miss and not $do_init
!ll&&!rl&&r
000
$configpm and @miss
!ll&&!rl&&r
000
$configpm and @miss and not $do_init
!ll&&!rl&&r
000
$configpm and @miss
!ll&&!rl&&r
000
MC/DC0%0/3
$configpm and @miss and not $do_init
$configpm @miss not $do_init
MC/DC0%0/3
$configpm and @miss and not $do_init
$configpm @miss not $do_init
Truth table0%0/4
A and B and not(C)
A= $configpmB= @missC= not $do_init
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= $configpmB= @missC= not $do_init
ABCresult
0XX0
10X0
1100
1111
593 0 ▶ if ($make_myconfig || ( ! -w $configpm && $configpm =~ m{CPAN/Config\.pm})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($make_myconfig or not -w $configpm and $configpm =~ m[CPAN/Config\.pm]) { } 0 0 0
if ($make_myconfig or not -w $configpm and $configpm =~ m[CPAN/Config\.pm]) { } 0 0 0
Condition0%0/12
$make_myconfig or not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
l!l&&r!l&&!r
000
not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
!ll&&!rl&&r
000
$make_myconfig or not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
l!l&&r!l&&!r
000
not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
!ll&&!rl&&r
000
MC/DC0%0/3
$make_myconfig or not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
$make_myconfig not -w $configpm $configpm =~ m[CPAN/Config\.pm]
MC/DC0%0/3
$make_myconfig or not -w $configpm and $configpm =~ m[CPAN/Config\.pm]
$make_myconfig not -w $configpm $configpm =~ m[CPAN/Config\.pm]
Truth table0%0/4
A or not(B) and C
A= $make_myconfigB= not -w $configpmC= $configpm =~ m[CPAN/Config\.pm]
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
A or not(B) and C
A= $make_myconfigB= not -w $configpmC= $configpm =~ m[CPAN/Config\.pm]
ABCresult
1XX1
0111
00X0
0100
594 0 $configpm = make_new_config();
595 0 $CPAN::Frontend->myprint(<<END);
596 The system CPAN configuration file has provided some default values,
597 but you need to complete the configuration dialog for CPAN.pm.
598 Configuration will be written to
599 <<$configpm>>
600 END
601 }
602 else {
603 0 $CPAN::Frontend->myprint(<<END);
604 Sorry, we have to rerun the configuration dialog for CPAN.pm due to
605 some missing parameters. Configuration will be written to
606 <<$configpm>>
607  
608 END
609 }
610 }
611  
612 0 require CPAN::FirstTime;
613 0 ▶ return CPAN::FirstTime::init($configpm || make_new_config(), %args);
Condition0%0/6
$configpm || make_new_config()
l!l&&r!l&&!r
000
$configpm || make_new_config()
l!l&&r!l&&!r
000
MC/DC0%0/2
$configpm || make_new_config()
$configpm make_new_config()
MC/DC0%0/2
$configpm || make_new_config()
$configpm make_new_config()
Truth table0%0/3
A || B
A= $configpmB= make_new_config()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $configpmB= make_new_config()
ABresult
1X1
011
000
614 }
615  
616 # Creates a new, empty config file at the preferred location
617 # Any existing will be renamed with a ".bak" suffix if possible
618 # If the file cannot be created, an exception is thrown
619 0 ▶sub make_new_config {
Subroutine make_new_config: not called CC=7 SCAR=40.3
Pod undocumented
620 0 ▶ my $configpm = _new_config_name();
Subroutine make_new_config: not called CC=7 SCAR=40.3
Pod undocumented
621 0 my $configpmdir = File::Basename::dirname( $configpm );
622 0 ▶ File::Path::mkpath($configpmdir) unless -d $configpmdir;
Branch: 2 branches
BranchTrueFalseTotal
unless -d $configpmdir 0 0 0
unless -d $configpmdir 0 0 0
623  
624 0 ▶ if ( -w $configpmdir ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-w $configpmdir) 0 0 0
if (-w $configpmdir) 0 0 0
625 #_#_# following code dumped core on me with 5.003_11, a.k.
626 0 ▶ if( -f $configpm ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $configpm) 0 0 0
if (-f $configpm) 0 0 0
627 0 my $configpm_bak = "$configpm.bak";
628 0 ▶ unlink $configpm_bak if -f $configpm_bak;
Branch: 2 branches
BranchTrueFalseTotal
if -f $configpm_bak 0 0 0
if -f $configpm_bak 0 0 0
629 0 ▶ if( rename $configpm, $configpm_bak ) {
Branch: 2 branches
BranchTrueFalseTotal
if (rename $configpm, $configpm_bak) 0 0 0
if (rename $configpm, $configpm_bak) 0 0 0
630 0 $CPAN::Frontend->mywarn(<<END);
631 Old configuration file $configpm
632 moved to $configpm_bak
633 END
634 }
635 }
636 0 my $fh = FileHandle->new;
637 0 ▶ if ($fh->open(">$configpm")) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fh->open(">$configpm")) 0 0 0
if ($fh->open(">$configpm")) 0 0 0
638 0 $fh->print("1;\n");
639 0 return $configpm;
640 }
641 }
642 0 _die_cant_write_config($configpm);
643 }
644  
645 0 ▶sub _die_cant_write_config {
Subroutine _die_cant_write_config: not called CC=1 SCAR=6.9
646 0 ▶ my ($configpm) = @_;
Subroutine _die_cant_write_config: not called CC=1 SCAR=6.9
647 0 $CPAN::Frontend->mydie(<<"END");
648 WARNING: CPAN.pm is unable to write a configuration file. You
649 must be able to create and write to '$configpm'.
650  
651 Aborting configuration.
652 END
653  
654 }
655  
656 # From candidate directories, we would like (in descending preference order):
657 # * the one that contains a MyConfig file
658 # * one that exists (even without MyConfig)
659 # * the first one on the list
660 0 ▶sub cpan_home {
Subroutine cpan_home: not called CC=5 SCAR=34.0
Pod undocumented
661 0 ▶ my @dirs = cpan_home_dir_candidates();
Subroutine cpan_home: not called CC=5 SCAR=34.0
Pod undocumented
662 0 for my $d (@dirs) {
663 0 ▶ return $d if -f "$d/CPAN/MyConfig.pm";
Branch: 2 branches
BranchTrueFalseTotal
if -f "$d/CPAN/MyConfig.pm" 0 0 0
if -f "$d/CPAN/MyConfig.pm" 0 0 0
664 }
665 0 for my $d (@dirs) {
666 0 ▶ return $d if -d $d;
Branch: 2 branches
BranchTrueFalseTotal
if -d $d 0 0 0
if -d $d 0 0 0
667 }
668 0 return $dirs[0];
669 }
670  
671 0 ▶sub _new_config_name {
Subroutine _new_config_name: not called CC=1 SCAR=6.9
672 0 ▶ return File::Spec->catfile(cpan_home(), 'CPAN', 'MyConfig.pm');
Subroutine _new_config_name: not called CC=1 SCAR=6.9
673 }
674  
675 # returns mandatory but missing entries in the Config
676 37 ▶sub missing_config_data {
Subroutine missing_config_data: called CC=5 SCAR=24.4
Pod undocumented
677 0 ▶ my(@miss);
Subroutine missing_config_data: not called CC=5 SCAR=24.4
Pod undocumented
678 0 ▶ for (
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 37 37
$^O eq 'MSWin32' ? : 0 0 0
679 "auto_commit",
680 "build_cache",
681 "build_dir",
682 "cache_metadata",
683 "cpan_home",
684 "ftp_proxy",
685 #"gzip",
686 "http_proxy",
687 "index_expire",
688 #"inhibit_startup_message",
689 "keep_source_where",
690 #"make",
691 "make_arg",
692 "make_install_arg",
693 "makepl_arg",
694 "mbuild_arg",
695 "mbuild_install_arg",
696 ($^O eq "MSWin32" ? "" : "mbuild_install_build_command"),
697 "mbuildpl_arg",
698 "no_proxy",
699 #"pager",
700 "prerequisites_policy",
701 "pushy_https",
702 "scan_cache",
703 #"tar",
704 #"unzip",
705 "urllist",
706 ) {
707 0 ▶ next unless exists $keys{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $CPAN::HandleConfig::keys{$_} 0 777 777
unless exists $CPAN::HandleConfig::keys{$_} 0 0 0
708 0 ▶ push @miss, $_ unless defined $CPAN::Config->{$_};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $CPAN::Config->{$_} 0 777 777
unless defined $CPAN::Config->{$_} 0 0 0
709 }
710 0 return @miss;
711 }
712  
713 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod undocumented
714 0 ▶ $CPAN::Frontend->myprint(q[
Subroutine help: not called CC=1 SCAR=6.9
Pod undocumented
715 Known options:
716 commit commit session changes to disk
717 defaults reload default config values from disk
718 help this help
719 init enter a dialog to set all or a set of parameters
720  
721 Edit key values as in the following (the "o" is a literal letter o):
722 o conf build_cache 15
723 o conf build_dir "/foo/bar"
724 o conf urllist shift
725 o conf urllist unshift ftp://ftp.foo.bar/
726 o conf inhibit_startup_message 1
727  
728 ]);
729 0 1; #don't reprint CPAN::Config
730 }
731  
732 0 ▶sub cpl {
Subroutine cpl: not called CC=14 SCAR=53.5
Pod undocumented
733 0 ▶ my($word,$line,$pos) = @_;
Subroutine cpl: not called CC=14 SCAR=53.5
Pod undocumented
734 0 ▶ $word ||= "";
Condition0%0/4
$word ||= ""
l!l
00
$word ||= ""
l!l
00
MC/DC0%0/1
$word ||= ""
$word
MC/DC0%0/1
$word ||= ""
$word
Truth table0%0/2
A
A= $word
Aresult
11
00
Truth table0%0/2
A
A= $word
Aresult
11
00
735 0 ▶ CPAN->debug("word[$word] line[$line] pos[$pos]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
736 0 my(@words) = split " ", substr($line,0,$pos+1);
737 0 ▶ if (
Branch: 6 branches
BranchTrueFalseTotal
if (defined $words[2] and $words[2] =~ /list$/ and @words == 3 || @words == 4 && length $word) { } 0 0 0
elsif (defined $words[2] and $words[2] eq 'init' and @words == 3 || @words >= 4 && length $word) { } 0 0 0
elsif (@words >= 4) { } 0 0 0
if (defined $words[2] and $words[2] =~ /list$/ and @words == 3 || @words == 4 && length $word) { } 0 0 0
elsif (defined $words[2] and $words[2] eq 'init' and @words == 3 || @words >= 4 && length $word) { } 0 0 0
elsif (@words >= 4) { } 0 0 0
Condition0%0/24
defined $words[2] and $words[2] =~ /list$/ and @words == 3 || @words == 4 && length $word
!ll&&!rl&&r
000
defined $words[2] and $words[2] =~ /list$/
!ll&&!rl&&r
000
@words == 3 or @words == 4 and length $word
l!l&&r!l&&!r
000
@words == 4 and length $word
!ll&&!rl&&r
000
defined $words[2] and $words[2] =~ /list$/ and @words == 3 || @words == 4 && length $word
!ll&&!rl&&r
000
defined $words[2] and $words[2] =~ /list$/
!ll&&!rl&&r
000
@words == 3 or @words == 4 and length $word
l!l&&r!l&&!r
000
@words == 4 and length $word
!ll&&!rl&&r
000
MC/DC0%0/5
defined $words[2] and $words[2] =~ /list$/ and @words == 3 || @words == 4 && length $word
defined $words[2] $words[2] =~ /list$/ @words == 3 @words == 4 length $word
MC/DC0%0/5
defined $words[2] and $words[2] =~ /list$/ and @words == 3 || @words == 4 && length $word
defined $words[2] $words[2] =~ /list$/ @words == 3 @words == 4 length $word
Truth table0%0/6
A and B and C or D and E
A= defined $words[2]B= $words[2] =~ /list$/C= @words == 3D= @words == 4E= length $word
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
Truth table0%0/6
A and B and C or D and E
A= defined $words[2]B= $words[2] =~ /list$/C= @words == 3D= @words == 4E= length $word
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
738 defined($words[2])
739 and
740 $words[2] =~ /list$/
741 and
742 (
743 @words == 3
744 ||
745 @words == 4 && length($word)
746 )
747 ) {
748 0 return grep /^\Q$word\E/, qw(splice shift unshift pop push);
749 ▶ } elsif (defined($words[2])
Condition0%0/24
defined $words[2] and $words[2] eq "init" and @words == 3 || @words >= 4 && length $word
!ll&&!rl&&r
000
defined $words[2] and $words[2] eq "init"
!ll&&!rl&&r
000
@words == 3 or @words >= 4 and length $word
l!l&&r!l&&!r
000
@words >= 4 and length $word
!ll&&!rl&&r
000
defined $words[2] and $words[2] eq "init" and @words == 3 || @words >= 4 && length $word
!ll&&!rl&&r
000
defined $words[2] and $words[2] eq "init"
!ll&&!rl&&r
000
@words == 3 or @words >= 4 and length $word
l!l&&r!l&&!r
000
@words >= 4 and length $word
!ll&&!rl&&r
000
MC/DC0%0/5
defined $words[2] and $words[2] eq "init" and @words == 3 || @words >= 4 && length $word
defined $words[2] $words[2] eq "init" @words == 3 @words >= 4 length $word
MC/DC0%0/5
defined $words[2] and $words[2] eq "init" and @words == 3 || @words >= 4 && length $word
defined $words[2] $words[2] eq "init" @words == 3 @words >= 4 length $word
Truth table0%0/6
A and B and C or D and E
A= defined $words[2]B= $words[2] eq "init"C= @words == 3D= @words >= 4E= length $word
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
Truth table0%0/6
A and B and C or D and E
A= defined $words[2]B= $words[2] eq "init"C= @words == 3D= @words >= 4E= length $word
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
750 and
751 $words[2] eq "init"
752 and
753 (
754 @words == 3
755 ||
756 @words >= 4 && length($word)
757 )) {
758 0 return sort grep /^\Q$word\E/, keys %keys;
759 } elsif (@words >= 4) {
760 0 return ();
761 }
762 0 my %seen;
763 0 my(@o_conf) = sort grep { !$seen{$_}++ }
764 keys %can,
765 keys %$CPAN::Config,
766 keys %keys;
767 0 return grep /^\Q$word\E/, @o_conf;
768 }
769  
770 47 ▶sub prefs_lookup {
Subroutine prefs_lookup: called CC=6 SCAR=29.4
Pod undocumented
771 0 ▶ my($self,$distro,$what) = @_;
Subroutine prefs_lookup: not called CC=6 SCAR=29.4
Pod undocumented
772  
773 0 ▶ if ($prefssupport{$what}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($prefssupport{$what}) { } 33 14 47
if ($prefssupport{$what}) { } 0 0 0
774 return $CPAN::Config->{$what} unless
775 $distro
776 and $distro->prefs
777 and $distro->prefs->{cpanconfig}
778 0 ▶ and defined $distro->prefs->{cpanconfig}{$what};
Branch: 2 branches
BranchTrueFalseTotal
unless $distro and $distro->prefs and $distro->prefs->{"cpanconfig"} and defined $distro->prefs->{"cpanconfig"}{$what} 33 0 33
unless $distro and $distro->prefs and $distro->prefs->{"cpanconfig"} and defined $distro->prefs->{"cpanconfig"}{$what} 0 0 0
Condition16%3/18
$distro and $distro->prefs and $distro->prefs->{"cpanconfig"} and defined $distro->prefs->{"cpanconfig"}{$what}
!ll&&!rl&&r
3300
$distro and $distro->prefs and $distro->prefs->{"cpanconfig"}
!ll&&!rl&&r
0330
$distro and $distro->prefs
!ll&&!rl&&r
0033
$distro and $distro->prefs and $distro->prefs->{"cpanconfig"} and defined $distro->prefs->{"cpanconfig"}{$what}
!ll&&!rl&&r
000
$distro and $distro->prefs and $distro->prefs->{"cpanconfig"}
!ll&&!rl&&r
000
$distro and $distro->prefs
!ll&&!rl&&r
000
MC/DC0%0/4
$distro and $distro->prefs and $distro->prefs->{"cpanconfig"} and defined $distro->prefs->{"cpanconfig"}{$what}
$distro $distro->prefs $distro->prefs->{"cpanconfig"} defined $distro->prefs->{"cpanconfig"}{$what}
MC/DC0%0/4
$distro and $distro->prefs and $distro->prefs->{"cpanconfig"} and defined $distro->prefs->{"cpanconfig"}{$what}
$distro $distro->prefs $distro->prefs->{"cpanconfig"} defined $distro->prefs->{"cpanconfig"}{$what}
Truth table20%1/5
A and B and C and D
A= $distroB= $distro->prefsC= $distro->prefs->{"cpanconfig"}D= defined $distro->prefs->{"cpanconfig"}{$what}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= $distroB= $distro->prefsC= $distro->prefs->{"cpanconfig"}D= defined $distro->prefs->{"cpanconfig"}{$what}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
779 0 return $distro->prefs->{cpanconfig}{$what};
780 } else {
781 0 $CPAN::Frontend->mywarn("Warning: $what not yet officially ".
782 "supported for distroprefs, doing a normal lookup\n");
783 0 return $CPAN::Config->{$what};
784 }
785 }
786  
787  
788 {
789 package
790 CPAN::Config; ####::###### #hide from indexer
791 # note: J. Nick Koston wrote me that they are using
792 # CPAN::Config->commit although undocumented. I suggested
793 # CPAN::Shell->o("conf","commit") even when ugly it is at least
794 # documented
795  
796 # that's why I added the CPAN::Config class with autoload and
797 # deprecated warning
798  
799 27 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
800 27 ▶ use vars qw($AUTOLOAD $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
801 27 $VERSION = "5.5014";
802  
803 # formerly CPAN::HandleConfig was known as CPAN::Config
804 0 ▶ sub AUTOLOAD { ## no critic
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
805 0 ▶ my $class = shift; # e.g. in dh-make-perl: CPAN::Config
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
806 0 my($l) = $AUTOLOAD;
807 0 $CPAN::Frontend->mywarn("Dispatching deprecated method '$l' to CPAN::HandleConfig\n");
808 0 $l =~ s/.*:://;
809 0 CPAN::HandleConfig->$l(@_);
810 }
811 }
812  
813 27 1;
814  
815 __END__
« blib/lib/CPAN/Module.pm ↑ Summary blib/lib/CPAN/Complete.pm »