Site/Index.pm

filter: Statementstmt 37.8% 110 / 291 Branchbran 26.0% 37 / 142 Conditioncond 39.2% 22 / 56 MC/DCmcdc 31.2% 10 / 32 Subroutinesub 61.7% 21 / 34 Podpod 0.0% 0 / 18 totaltotal 34.9% 200 / 573 SCAR 79.7
CC
100
Cov
35%
cpan_mirror
182.0
cpan_index
156.0
create_details
72.0
CRAP 2902.4
↑ Summary Site.pm »
1 # Copyrights 1998,2005-2018 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution CPAN::Site.
6 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
7  
8 package CPAN::Site::Index;
9 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 $VERSION = '1.15';
11  
12 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our @EXPORT_OK = qw/cpan_index cpan_mirror/;
18 1 our $VERSION; # required in test-env
19  
20 1 ▶use Log::Report 'cpan-site', syntax => 'SHORT';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use File::Find qw/find/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use File::Copy qw/copy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use File::Basename qw/basename dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use HTTP::Date qw/time2str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use File::Spec::Functions qw/catfile catdir splitdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use LWP::UserAgent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Archive::Tar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use CPAN::Checksums ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use IO::Zlib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 1 my $tar_gz = qr/ \.tar\.gz$ | \.tar\.Z$ | \.tgz$/xi;
35 1 my $zip = qr/ \.zip$ /xi;
36 1 my $cpan_update = 0.04; # days between reload of full CPAN index
37 1 my $ua;
38  
39 sub safe_copy($$);
40 sub cpan_index($@);
41 sub register($$$);
42 sub package_inventory($$;$);
43 sub package_on_usual_location($);
44 sub inspect_archive;
45 sub inspect_tar_archive($$);
46 sub inspect_zip_archive($$);
47 sub collect_package_details($$$);
48 sub update_global_cpan($$);
49 sub load_file($$);
50 sub merge_global_cpan($$$);
51 sub create_details($$$$$);
52 sub calculate_checksums($);
53 sub read_details($);
54 sub remove_expired_details($$$);
55 sub mkdirhier(@);
56 sub cpan_mirror($$$@);
57  
58 sub safe_copy($$)
59 0 ▶{ my ($from, $to) = @_;
Subroutine safe_copy: not called CC=2 SCAR=17.9
Pod undocumented
60 0 trace "copy $from to $to";
61 0 ▶ copy $from, $to
Branch: 1 branch
BranchTrueFalseTotal
copy($from, $to) or &fault(&__x("cannot copy {from} to {to}", "from", $from, "to", $to)) 0 0 0
62 or fault __x"cannot copy {from} to {to}", from => $from, to => $to;
63 }
64  
65 sub cpan_index($@)
66 0 ▶{ my ($mycpan, $globalcpan, %opts) = @_;
Subroutine cpan_index: not called CC=12 SCAR=50.5
Pod undocumented
67 0 my $lazy = $opts{lazy};
68 0 my $fallback = $opts{fallback};
69 0 ▶ my $undefs = exists $opts{undefs} ? $opts{undefs} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'undefs'} ? : 0 0 0
70  
71 0 ▶ unless($ua)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 0 0 0
72 0 { $ua = LWP::UserAgent->new;
73 0 ▶ $ua->env_proxy if $opts{env_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"env_proxy"} 0 0 0
74 }
75  
76 0 ▶ -d $mycpan
Branch: 1 branch
BranchTrueFalseTotal
-d $mycpan or &error(&__x("archive top '{dir}' is not a directory", "dir", $mycpan)) 0 0 0
77 or error __x"archive top '{dir}' is not a directory"
78 , dir => $mycpan;
79  
80 0 my $program = basename $0;
81 0 ▶ $VERSION ||= 'undef'; # test env at home
Condition0%0/2
$CPAN::Site::Index::VERSION ||= "undef"
l!l
00
MC/DC0%0/1
$CPAN::Site::Index::VERSION ||= "undef"
$CPAN::Site::Index::VERSION
Truth table0%0/2
A
A= $CPAN::Site::Index::VERSION
Aresult
11
00
82 0 trace "$program version $VERSION";
83  
84 0 my $global = catdir $mycpan, 'global';
85 0 my $mods = catdir $mycpan, 'modules';
86 0 my $authors = catdir $mycpan, 'authors';
87 0 mkdirhier $global, $mods, $authors;
88  
89 0 my $globdetails = update_global_cpan $mycpan, $globalcpan;
90  
91 # Create mailrc and modlist
92  
93 0 safe_copy catfile($global, '01mailrc.txt.gz')
94 , catfile($authors, '01mailrc.txt.gz');
95  
96 0 safe_copy catfile($global, '03modlist.data.gz')
97 , catfile($mods, '03modlist.data.gz');
98  
99 # Create packages details
100  
101 0 my $details = catfile $mods, '02packages.details.txt.gz';
102 0 my $newlist = catfile $mods, '02packages.details.tmp.gz';
103 0 my $newer;
104  
105 0 my $reuse_dists = {};
106 0 ▶ if($lazy && -f $details)
Branch: 1 branch
BranchTrueFalseTotal
if ($lazy and -f $details) 0 0 0
Condition0%0/3
$lazy and -f $details
!ll&&!rl&&r
000
MC/DC0%0/2
$lazy and -f $details
$lazy -f $details
Truth table0%0/3
A and B
A= $lazyB= -f $details
ABresult
0X0
100
111
107 0 { $reuse_dists = read_details $details;
108 0 $newer = -M $details;
109 0 remove_expired_details $mycpan, $reuse_dists, $newer;
110 }
111  
112 0 my ($mypkgs, $distdirs)
113 = package_inventory $mycpan, $reuse_dists, $newer;
114  
115 0 ▶ merge_global_cpan $mycpan, $mypkgs, $globdetails
Branch: 1 branch
BranchTrueFalseTotal
if $fallback 0 0 0
116 if $fallback;
117  
118 0 create_details $details, $newlist, $mypkgs, $lazy, $undefs;
119  
120 0 ▶ if(-f $details)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $details) 0 0 0
121 0 { trace "backup old details file to $details.bak";
122 0 safe_copy $details, "$details.bak";
123 }
124  
125 0 ▶ if(-f $newlist)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $newlist) 0 0 0
126 0 { trace "promoting $newlist to current";
127 0 ▶ rename $newlist, $details
Branch: 1 branch
BranchTrueFalseTotal
rename $newlist, $details or &error(&__x("cannot rename '{from}' in '{to}'", "from", $newlist, "to", $details)) 0 0 0
128 or error __x"cannot rename '{from}' in '{to}'"
129 , from => $newlist, to => $details;
130 }
131  
132 0 calculate_checksums $distdirs;
133 }
134  
135 #
136 # Package Inventory
137 #
138  
139 # global variables for testing purposes (sorry)
140 1 our ($topdir, $findpkgs, %finddirs, $olddists, $index_age);
141  
142 sub register($$$)
143 28 ▶{ my ($package, $this_version, $dist) = @_;
Subroutine register: called CC=7 SCAR=25.7
Pod undocumented
144  
145 # warn "register $package, " . (defined $this_version ? $this_version : 'undef');
146  
147 28 ▶ if(ref $this_version)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this_version) 0 28 28
148 0 { eval { $this_version = version->parse($this_version) };
149 0 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
150 0 { alert __x"error when creating version object for {pkg}: {err}"
151 , pkg => $package, err => $@;
152 0 return;
153 }
154 }
155
156 28 ▶ my $registered_version = exists $findpkgs->{$package} ? $findpkgs->{$package}[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $CPAN::Site::Index::findpkgs->{$package} ? : 0 28 28
157 28 ▶ $this_version =~ s/^v// if $this_version;
Branch: 1 branch
BranchTrueFalseTotal
if $this_version 7 21 28
158  
159 28 ▶ return if defined $registered_version
Branch: 1 branch
BranchTrueFalseTotal
if defined $registered_version and $registered_version > $this_version 0 28 28
Condition33%1/3
defined $registered_version and $registered_version > $this_version
!ll&&!rl&&r
2800
MC/DC0%0/2
defined $registered_version and $registered_version > $this_version
defined $registered_version $registered_version > $this_version
Truth table33%1/3
A and B
A= defined $registered_versionB= $registered_version > $this_version
ABresult
0X0
100
111
160 && $registered_version > $this_version;
161  
162 28 $findpkgs->{$package} = [ $this_version, $dist ];
163 }
164  
165 sub package_inventory($$;$)
166 0 ▶{ (my $mycpan, $olddists, $index_age) = @_; #!!! see "my"
Subroutine package_inventory: not called CC=1 SCAR=6.9
Pod undocumented
167 0 $topdir = catdir $mycpan, 'authors', 'id';
168 0 mkdirhier $topdir;
169  
170 0 $findpkgs = {};
171 0 trace "creating inventory from $topdir";
172  
173 0 find {wanted => \&inspect_archive, no_chdir => 1}, $topdir;
174 0 ($findpkgs, \%finddirs);
175 }
176  
177 sub package_on_usual_location($)
178 22 ▶{ my $file = shift;
Subroutine package_on_usual_location: called CC=3 SCAR=11.0
Pod undocumented
179 22 my ($top, $subdir, @rest) = splitdir $file;
180 22 ▶ defined $subdir or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $subdir or return 0 0 22 22
181  
182 !@rest # path is at top-level of distro
183 22 ▶ || $subdir eq 'lib'; # inside lib
Branch: 1 branch
BranchTrueFalseTotal
not @rest or $subdir eq "lib" 21 1 22
184 }
185  
186 sub inspect_archive
187 3 ▶{ my $fn = $File::Find::name;
Subroutine inspect_archive: called CC=10 SCAR=35.9
Pod undocumented
188 3 ▶ return unless -f $fn && ($fn =~ $tar_gz || $fn =~ $zip);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn and $fn =~ /$tar_gz/xi || $fn =~ /$zip/ 0 3 3
Condition33%2/6
-f $fn and $fn =~ /$tar_gz/xi || $fn =~ /$zip/
!ll&&!rl&&r
030
$fn =~ /$tar_gz/xi or $fn =~ /$zip/
l!l&&r!l&&!r
300
MC/DC0%0/3
-f $fn and $fn =~ /$tar_gz/xi || $fn =~ /$zip/
-f $fn $fn =~ /$tar_gz/xi $fn =~ /$zip/
Truth table0%0/4
A and B or C
A= -f $fnB= $fn =~ /$tar_gz/xiC= $fn =~ /$zip/
ABCresult
0XX0
1000
11X1
1011
189  
190 3 (my $dist = $fn) =~ s!^\Q$topdir\E[\\/]!!;
191  
192 3 ▶ if(defined $index_age && -M $fn > $index_age)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CPAN::Site::Index::index_age and -M $fn > $CPAN::Site::Index::index_age) 0 3 3
Condition33%1/3
defined $CPAN::Site::Index::index_age and -M $fn > $CPAN::Site::Index::index_age
!ll&&!rl&&r
300
MC/DC0%0/2
defined $CPAN::Site::Index::index_age and -M $fn > $CPAN::Site::Index::index_age
defined $CPAN::Site::Index::index_age -M $fn > $CPAN::Site::Index::index_age
Truth table33%1/3
A and B
A= defined $CPAN::Site::Index::index_ageB= -M $fn > $CPAN::Site::Index::index_age
ABresult
0X0
100
111
193 {
194 0 ▶ unless(exists $olddists->{$dist})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $CPAN::Site::Index::olddists->{$dist}) 0 0 0
195 0 { trace "not the latest: $dist";
196 0 return;
197 }
198  
199 0 trace "latest older than index: $dist";
200 0 foreach (@{$olddists->{$dist}})
201 0 { my ($pkg, $version) = @$_;
202 0 register $pkg, $version, $dist;
203 }
204 0 return;
205 }
206  
207 3 trace "inspecting archive $fn";
208 3 $finddirs{$File::Find::dir}++;
209  
210 3 ▶ return inspect_tar_archive $dist, $fn
Branch: 1 branch
BranchTrueFalseTotal
if $fn =~ /$tar_gz/xi 3 0 3
211 if $fn =~ $tar_gz;
212  
213 0 ▶ return inspect_zip_archive $dist, $fn
Branch: 1 branch
BranchTrueFalseTotal
if $fn =~ /$zip/ 0 0 0
214 if $fn =~ $zip;
215 }
216  
217 sub inspect_tar_archive($$)
218 3 ▶{ my ($dist, $fn) = @_;
Subroutine inspect_tar_archive: called CC=6 SCAR=17.9
Pod undocumented
219  
220 3 my $arch = Archive::Tar->new;
221 3 ▶ $arch->read($fn, 1)
Branch: 1 branch
BranchTrueFalseTotal
$arch->read($fn, 1) or &error(&__x("no files in tar archive '{fn}': {err}", "fn", $fn, "err", $arch->error)) 0 3 3
222 or error __x"no files in tar archive '{fn}': {err}"
223 , fn => $fn, err => $arch->error;
224  
225 3 foreach my $file ($arch->get_files)
226 60 { my $fn = $file->full_path;
227 60 ▶ $file->is_file && $fn =~ m/\.pm$/i && package_on_usual_location $fn
Branch: 1 branch
BranchTrueFalseTotal
$file->is_file and $fn =~ /\.pm$/i and &package_on_usual_location($fn) or next 24 20 44
Condition100%6/6
$file->is_file and $fn =~ /\.pm$/i and &package_on_usual_location($fn)
!ll&&!rl&&r
38220
$file->is_file and $fn =~ /\.pm$/i
!ll&&!rl&&r
162222
MC/DC100%3/3
$file->is_file and $fn =~ /\.pm$/i and &package_on_usual_location($fn)
$file->is_file $fn =~ /\.pm$/i &package_on_usual_location($fn)
Truth table100%4/4
A and B and C
A= $file->is_fileB= $fn =~ /\.pm$/iC= &package_on_usual_location($fn)
ABCresult
0XX0
10X0
1100
1111
228 or next;
229 20 collect_package_details $fn, $dist, $file->get_content_by_ref;
230 }
231 }
232  
233 sub inspect_zip_archive($$)
234 0 ▶{ my ($dist, $fn) = @_;
Subroutine inspect_zip_archive: not called CC=6 SCAR=37.4
Pod undocumented
235  
236 0 my $arch = Archive::Zip->new;
237 0 ▶ $arch->read($fn)==AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$arch->read($fn) == 0 or &error(&__x("no files in zip archive '{fn}': {err}", "fn", $fn, "err", $arch->error)) 0 0 0
238 or error __x"no files in zip archive '{fn}': {err}"
239 , fn => $fn, err => $arch->error;
240  
241 0 foreach my $member ($arch->membersMatching( qr/\.pm$/i ))
242 0 { my $fn = $member->fileName;
243 0 ▶ $member->isTextFile && package_on_usual_location $fn
Branch: 1 branch
BranchTrueFalseTotal
$member->isTextFile and &package_on_usual_location($fn) or next 0 0 0
Condition0%0/3
$member->isTextFile and &package_on_usual_location($fn)
!ll&&!rl&&r
000
MC/DC0%0/2
$member->isTextFile and &package_on_usual_location($fn)
$member->isTextFile &package_on_usual_location($fn)
Truth table0%0/3
A and B
A= $member->isTextFileB= &package_on_usual_location($fn)
ABresult
0X0
100
111
244 or next;
245 0 my ($contents, $status) = $member->contents;
246 0 ▶ $status==AZ_OK
Branch: 1 branch
BranchTrueFalseTotal
$status == 0 or &error("error in zip file {fn}: {err}", "fn", $fn, "err", $status) 0 0 0
247 or error "error in zip file {fn}: {err}"
248 , fn => $fn, err => $status;
249 0 collect_package_details $fn, $dist, \$contents;
250 }
251 }
252  
253 sub collect_package_details($$$)
254 20 ▶{ my ($fn, $dist) = (shift, shift);
Subroutine collect_package_details: called CC=21 SCAR=31.4
Pod undocumented
255 20 my @lines = split /\r?\n/, ${shift()};
256 20 my $in_pod = 0;
257 20 my $package;
258 20 local $VERSION = undef; # may get destroyed by eval
259  
260 20 ▶ while(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 4623 20 4643
261 4623 { local $_ = shift @lines;
262 4623 ▶ last if m/^__(?:END|DATA)__$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^__(?:END|DATA)__$/ 0 4623 4623
263  
264 4623 ▶ $in_pod = ($1 ne 'cut') if m/^=(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=(\w+)/ 324 4299 4623
265 4623 ▶ next if $in_pod || m/^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod or /^\s*#/ 1235 3388 4623
Condition100%3/3
$in_pod or /^\s*#/
l!l&&r!l&&!r
10781573388
MC/DC100%2/2
$in_pod or /^\s*#/
$in_pod /^\s*#/
Truth table100%3/3
A or B
A= $in_podB= /^\s*#/
ABresult
1X1
011
000
266  
267 3388 ▶ $_ .= shift @lines
Branch: 1 branch
BranchTrueFalseTotal
@lines and /package|use|VERSION/ and not /[;{]/ and do { $_ .= shift @lines } 2 3388 3390
Condition100%6/6
@lines and /package|use|VERSION/ and not /[;{]/
!ll&&!rl&&r
32751132
@lines and /package|use|VERSION/
!ll&&!rl&&r
183257115
MC/DC100%3/3
@lines and /package|use|VERSION/ and not /[;{]/
@lines /package|use|VERSION/ not /[;{]/
Truth table100%4/4
A and B and not(C)
A= @linesB= /package|use|VERSION/C= not /[;{]/
ABCresult
0XX0
10X0
1100
1111
268 while @lines && m/package|use|VERSION/ && !m/[;{]/;
269  
270 3388 ▶ if( m/^\s* package \s* ((?:\w+\:\:)*\w+) (?:\s+ (\S*))? \s* [;{]/x )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s* package \s* ((?:\w+\:\:)*\w+) (?:\s+ (\S*))? \s* [;{]/x) 28 3360 3388
271 28 { my ($thispkg, $v) = ($1, $2);
272 28 my $thisversion;
273 28 ▶ if($v)
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 28 28
274 0 { $thisversion = eval {qv($v)};
275 0 ▶ alert __x"illegal version for {pkg}, found '{version}': {err}"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
276 , pkg => $thispkg, version => $v, err => $@ if $@;
277 }
278  
279 # second package in file?
280 28 ▶ register $package, $VERSION, $dist
Branch: 1 branch
BranchTrueFalseTotal
if defined $package 8 20 28
281 if defined $package;
282  
283 28 ($package, $VERSION) = ($thispkg, $thisversion);
284 28 trace "pkg $package from $fn";
285 }
286  
287 3388 ▶ if( m/^\s* \$ ${package}::VERSION \s* = \s* ["']?(\w+?)["']? \s* ;/x )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s* \$ $package::VERSION \s* = \s* ["']?(\w+?)["']? \s* ;/x) 0 3388 3388
288 0 { $VERSION = $1;
289 }
290  
291 3388 ▶ if( !$VERSION && m/^ (?:use\s+version\s*;\s*)?
Branch: 1 branch
BranchTrueFalseTotal
if (not $CPAN::Site::Index::VERSION and /^ (?:use\s+version\s*;\s*)? (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x) 7 3381 3388
Condition100%3/3
not $CPAN::Site::Index::VERSION and /^ (?:use\s+version\s*;\s*)? (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x
!ll&&!rl&&r
85525267
MC/DC100%2/2
not $CPAN::Site::Index::VERSION and /^ (?:use\s+version\s*;\s*)? (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x
not $CPAN::Site::Index::VERSION /^ (?:use\s+version\s*;\s*)? (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x
Truth table100%3/3
not(A) and B
A= not $CPAN::Site::Index::VERSIONB= /^ (?:use\s+version\s*;\s*)? (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x
ABresult
0X0
100
111
292 (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x )
293 7 ▶ { defined $2 or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 or next 0 7 7
294 7 my ($ns, $vers) = ($1, $2);
295  
296 # some versions of CPAN.pm do contain lines like "$VERSION =~ ..."
297 # which also need to be processed.
298 7 eval "\$VERSION =$vers";
299 7 ▶ if(defined $VERSION)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CPAN::Site::Index::VERSION) 7 0 7
300 7 ▶ { ($package = $ns) =~ s/\:\:$//
Branch: 1 branch
BranchTrueFalseTotal
if length $ns 3 4 7
301 if length $ns;
302 7 trace "pkg $package version $VERSION";
303 }
304 }
305 }
306  
307 20 ▶ $VERSION = $VERSION->numify if ref $VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if ref $CPAN::Site::Index::VERSION 0 20 20
308 20 ▶ register $package, $VERSION, $dist
Branch: 1 branch
BranchTrueFalseTotal
if defined $package 20 0 20
309 if defined $package;
310 }
311  
312 sub update_global_cpan($$)
313 0 ▶{ my ($mycpan, $globalcpan) = @_;
Subroutine update_global_cpan: not called CC=5 SCAR=34.0
Pod undocumented
314  
315 0 my $global = catdir $mycpan, 'global';
316 my ($mailrc, $globdetails, $modlist) =
317 0 map { catfile $global, $_ }
318 qw/01mailrc.txt.gz 02packages.details.txt.gz 03modlist.data.gz/;
319  
320 0 ▶ return $globdetails
Branch: 1 branch
BranchTrueFalseTotal
if -f $globdetails and -f $globdetails and -f $modlist and -M $globdetails < $cpan_update 0 0 0
Condition0%0/9
-f $globdetails and -f $globdetails and -f $modlist and -M $globdetails < $cpan_update
!ll&&!rl&&r
000
-f $globdetails and -f $globdetails and -f $modlist
!ll&&!rl&&r
000
-f $globdetails and -f $globdetails
!ll&&!rl&&r
000
MC/DC0%0/4
-f $globdetails and -f $globdetails and -f $modlist and -M $globdetails < $cpan_update
-f $globdetails -f $globdetails -f $modlist -M $globdetails < $cpan_update
Truth table0%0/5
A and B and C and D
A= -f $globdetailsB= -f $globdetailsC= -f $modlistD= -M $globdetails < $cpan_update
ABCDresult
0XXX0
10XX0
110X0
11100
11111
321 if -f $globdetails && -f $globdetails && -f $modlist
322 && -M $globdetails < $cpan_update;
323  
324 0 info "(re)loading global CPAN files";
325  
326 0 mkdirhier $global;
327 0 load_file "$globalcpan/authors/01mailrc.txt.gz", $mailrc;
328 0 load_file "$globalcpan/modules/02packages.details.txt.gz", $globdetails;
329 0 load_file "$globalcpan/modules/03modlist.data.gz", $modlist;
330 0 $globdetails;
331 }
332  
333 sub load_file($$)
334 0 ▶{ my ($from, $to) = @_;
Subroutine load_file: not called CC=2 SCAR=17.9
Pod undocumented
335 0 my $response = $ua->get($from, ':content_file' => $to);
336 0 ▶ return if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
337  
338 0 unlink $to;
339 0 error __x"failed to get {uri} for {to}: {err}"
340 , uri => $from, to => $to, err => $response->status_line;
341 }
342  
343 sub merge_global_cpan($$$)
344 0 ▶{ my ($mycpan, $pkgs, $globdetails) = @_;
Subroutine merge_global_cpan: not called CC=4 SCAR=30.0
Pod undocumented
345  
346 0 trace "merge packages with CPAN core list in $globdetails";
347 0 my $cpan_pkgs = read_details $globdetails;
348  
349 0 ▶ while(my ($cpandist, $cpanpkgs) = each %$cpan_pkgs)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$cpan_pkgs) 0 0 0
350 0 { foreach (@$cpanpkgs)
351 0 { my ($pkg, $version) = @$_;
352 0 ▶ next if exists $pkgs->{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
if exists $pkgs->{$pkg} 0 0 0
353 0 $pkgs->{$pkg} = [$version, $cpandist];
354 }
355 }
356 }
357  
358 sub create_details($$$$$)
359 0 ▶{ my ($details, $filename, $pkgs, $lazy, $undefs) = @_;
Subroutine create_details: not called CC=8 SCAR=42.8
Pod undocumented
360  
361 0 trace "creating package details in $filename";
362 0 ▶ my $fh = IO::Zlib->new($filename, 'wb')
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Zlib"->new($filename, "wb") or &fault(&__x("generating gzipped {fn}", "fn", $filename)) 0 0 0
363 or fault __x"generating gzipped {fn}", fn => $filename;
364  
365 0 my $lines = keys %$pkgs;
366 0 my $date = time2str time;
367 0 ▶ my $how = $lazy ? "lazy" : "full";
Branch: 1 branch
BranchTrueFalseTotal
$lazy ? : 0 0 0
368  
369 0 info "produced list of $lines packages $how";
370  
371 0 my $program = basename $0;
372 0 my $module = __PACKAGE__;
373 0 $fh->print (<<__HEADER);
374 File: 02packages.details.txt
375 URL: file://$details
376 Description: Packages listed in CPAN and local repository
377 Columns: package name, version, path
378 Intended-For: private CPAN
379 Line-Count: $lines
380 Written-By: $program with $module $CPAN::Site::Index::VERSION ($how)
381 Last-Updated: $date
382  
383 __HEADER
384  
385 0 foreach my $pkg (sort keys %$pkgs)
386 0 { my ($version, $path) = @{$pkgs->{$pkg}};
387  
388 0 ▶ $version = 'undef'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $version or $version eq "" 0 0 0
Condition0%0/3
not defined $version or $version eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $version or $version eq ""
not defined $version $version eq ""
Truth table0%0/3
not(A) or B
A= not defined $versionB= $version eq ""
ABresult
1X1
011
000
389 if !defined $version || $version eq '';
390  
391 next
392 0 ▶ if $version eq 'undef' && !$undefs;
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "undef" and not $undefs 0 0 0
Condition0%0/3
$version eq "undef" and not $undefs
!ll&&!rl&&r
000
MC/DC0%0/2
$version eq "undef" and not $undefs
$version eq "undef" not $undefs
Truth table0%0/3
A and not(B)
A= $version eq "undef"B= not $undefs
ABresult
0X0
100
111
393  
394 0 $path =~ s,\\,/,g;
395 0 $fh->printf("%-30s\t%s\t%s\n", $pkg, $version, $path);
396 }
397 }
398  
399 sub calculate_checksums($)
400 0 ▶{ my $dirs = shift;
Subroutine calculate_checksums: not called CC=3 SCAR=24.8
Pod undocumented
401 0 trace "updating checksums";
402  
403 0 foreach my $dir (keys %$dirs)
404 0 { trace "summing $dir";
405 0 ▶ CPAN::Checksums::updatedir($dir)
Branch: 1 branch
BranchTrueFalseTotal
&CPAN::Checksums::updatedir($dir) or &warning("failed calculating checksums in {dir}", "dir", $dir) 0 0 0
406 or warning 'failed calculating checksums in {dir}', dir => $dir;
407 }
408 }
409  
410 sub read_details($)
411 0 ▶{ my $fn = shift;
Subroutine read_details: not called CC=6 SCAR=37.4
Pod undocumented
412 0 ▶ -f $fn or return {};
Branch: 1 branch
BranchTrueFalseTotal
-f $fn or return {} 0 0 0
413 0 trace "collecting all details from $fn";
414  
415 0 ▶ my $fh = IO::Zlib->new($fn, 'rb')
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Zlib"->new($fn, "rb") or &fault(&__x("cannot read from {fn}", "fn", $fn)) 0 0 0
416 or fault __x"cannot read from {fn}", fn => $fn;
417  
418 0 my $line; # skip header, search first blank
419 0 ▶ do { $line = $fh->getline } until $line =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s*$/ or do { do { $line = $fh->getline } } 0 0 0
420  
421 0 my $time_last_update = (stat $fn)[9];
422 0 my %dists;
423  
424 0 ▶ while(my $line = $fh->getline)
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
425 0 { chomp $line;
426 0 my ($pkg, $version, $dist) = split ' ', $line, 3;
427  
428 0 ▶ unless($dist)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dist) 0 0 0
429 0 { warning "$fn error line=\n $line";
430 0 next;
431 }
432  
433 0 push @{$dists{$dist}}, [$pkg, $version];
434 }
435  
436 0 \%dists;
437 }
438  
439 sub remove_expired_details($$$)
440 0 ▶{ my ($mycpan, $dists, $newer) = @_;
Subroutine remove_expired_details: not called CC=4 SCAR=30.0
Pod undocumented
441 0 trace "extracting only existing local distributions";
442  
443 0 my $authors = catdir $mycpan, 'authors', 'id';
444 0 foreach my $dist (keys %$dists)
445 0 { my $fn = catfile $authors, $dist;
446 0 ▶ if(! -f $fn)
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $fn) { } 0 0 0
elsif (-M $fn < $newer) { } 0 0 0
447 { # removed local or a global dist
448 0 delete $dists->{$dist};
449 }
450 elsif(-M $fn < $newer)
451 0 { trace "dist $dist file updated, reindexing";
452 0 delete $dists->{$dist};
453 }
454 }
455 }
456  
457 sub mkdirhier(@)
458 0 ▶{ foreach my $dir (@_)
Subroutine mkdirhier: not called CC=4 SCAR=30.0
Pod undocumented
459 0 ▶ { next if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 0 0 0
460 0 mkdirhier dirname $dir;
461  
462 0 ▶ mkdir $dir, 0755
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dir, 493 or &fault(&__x("cannot create directory {dir}", "dir", $dir)) 0 0 0
463 or fault __x"cannot create directory {dir}", dir => $dir;
464  
465 0 trace "created $dir";
466 }
467 0 1;
468 }
469  
470 sub cpan_mirror($$$@)
471 0 ▶{ my ($mycpan, $globalcpan, $mods, %opts) = @_;
Subroutine cpan_mirror: not called CC=13 SCAR=52.0
Pod undocumented
472 0 ▶ @$mods or return;
Branch: 1 branch
BranchTrueFalseTotal
@$mods or return 0 0 0
473 0 my %need = map { ($_ => 1) } @$mods;
474 0 my $auth = catdir $mycpan, 'authors', 'id';
475  
476 0 ▶ unless($ua)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 0 0 0
477 0 { $ua = LWP::UserAgent->new;
478 0 ▶ $ua->env_proxy if $opts{env_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"env_proxy"} 0 0 0
479 }
480  
481 0 my $globdetails
482 = update_global_cpan $mycpan, $globalcpan;
483  
484 0 ▶ my $fh = IO::Zlib->new($globdetails, 'rb')
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Zlib"->new($globdetails, "rb") or &fault(&__x("cannot read from {fn}", "fn", $globdetails)) 0 0 0
485 or fault __x"cannot read from {fn}", fn => $globdetails;
486  
487 0 ▶ while(my $line = $fh->getline) # skip header, search first blank
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
488 0 ▶ { last if $line =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
489 }
490  
491 0 ▶ $ua ||= LWP::UserAgent->new;
Condition0%0/3
$ua ||= "LWP::UserAgent"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$ua ||= "LWP::UserAgent"->new
$ua "LWP::UserAgent"->new
Truth table0%0/3
A ||= B
A= $uaB= "LWP::UserAgent"->new
ABresult
1X1
011
000
492 0 ▶ while(my $line = $fh->getline)
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
493 0 { my ($pkg, $version, $dist) = split ' ', $line;
494 0 ▶ delete $need{$pkg} or next;
Branch: 1 branch
BranchTrueFalseTotal
delete $need{$pkg} or next 0 0 0
495  
496 0 my $to = catfile $auth, split m#/#, $dist;
497 0 ▶ if(-f $to)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $to) 0 0 0
498 0 { trace __x"package {pkg} present in distribution {dist}"
499 , pkg => $pkg, dist => $dist;
500 0 next;
501 }
502  
503 0 my $source = "$globalcpan/authors/id/$dist";
504 0 mkdirhier dirname $to;
505 0 my $response = $ua->get($source, ':content_file' => $to);
506 0 ▶ unless($response->is_success)
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
507 0 { unlink $to;
508 0 error __x"failed to get {uri} for {to}: {err}"
509 , uri => $source, to => $to, err => $response->status_line;
510 }
511  
512 0 info __x"got {pkg} in {dist}", pkg => $pkg, dist => $dist;
513 }
514  
515 warning __x"package {pkg} does not exist", pkg => $_
516 0 for sort keys %need;
517 }
518  
519 1 1;
↑ Summary Site.pm »