Site/Index.pm

filter: Statementstmt 66.5% 195 / 293 Branchbran 42.2% 60 / 142 Conditioncond 57.1% 32 / 56 MC/DCmcdc 37.5% 12 / 32 Subroutinesub 85.2% 29 / 34 Podpod 0.0% 0 / 18 totaltotal 57.0% 328 / 575 CC 100 SCAR 34.7
CC
100
Cov
58%
cpan_mirror
182.0
inspect_zip_archive
42.0
read_details
42.0
CRAP 32.2
↑ Summary Site.pm »
1 # Copyrights 1998,2005-2022 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.03.
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 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 $VERSION = '1.17';
11  
12 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 our @EXPORT_OK = qw/cpan_index cpan_mirror/;
18 2 our $VERSION; # required in test-env
19  
20 2 ▶use Log::Report 'cpan-site', syntax => 'SHORT';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use File::Find qw/find/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use File::Copy qw/copy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use File::Basename qw/basename dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use HTTP::Date qw/time2str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use File::Spec::Functions qw/catfile catdir splitdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use LWP::UserAgent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use Archive::Tar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use CPAN::Checksums qw(updatedir); # horrible function name
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use IO::Zlib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 2 my $tar_gz = qr/ \.tar\.gz$ | \.tar\.Z$ | \.tgz$/xi;
35 2 my $zip = qr/ \.zip$ /xi;
36 2 my $cpan_update = 0.04; # days between reload of full CPAN index
37 2 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 2 ▶{ my ($from, $to) = @_;
Subroutine safe_copy: called CC=2 SCAR=7.1
Pod undocumented
60 2 trace "copy $from to $to";
61 2 ▶ copy $from, $to
Branch: 1 branch
BranchTrueFalseTotal
copy($from, $to) or &fault(&__x("cannot copy {from} to {to}", "from", $from, "to", $to)) 2 0 2
62 or fault __x"cannot copy {from} to {to}", from => $from, to => $to;
63 }
64  
65 sub cpan_index($@)
66 1 ▶{ my ($mycpan, $globalcpan, %opts) = @_;
Subroutine cpan_index: called CC=12 SCAR=27.4
Pod undocumented
67 1 my $lazy = $opts{lazy};
68 1 my $fallback = $opts{fallback};
69 1 ▶ my $undefs = exists $opts{undefs} ? $opts{undefs} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'undefs'} ? : 1 0 1
70  
71 1 ▶ unless($ua)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 1 0 1
72 1 { $ua = LWP::UserAgent->new;
73 1 ▶ $ua->env_proxy if $opts{env_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"env_proxy"} 0 1 1
74 }
75  
76 1 ▶ -d $mycpan
Branch: 1 branch
BranchTrueFalseTotal
-d $mycpan or &error(&__x("archive top '{dir}' is not a directory", "dir", $mycpan)) 1 0 1
77 or error __x"archive top '{dir}' is not a directory"
78 , dir => $mycpan;
79  
80 1 my $program = basename $0;
81 1 ▶ $VERSION ||= 'undef'; # test env at home
Condition50%1/2
$CPAN::Site::Index::VERSION ||= "undef"
l!l
10
MC/DC0%0/1
$CPAN::Site::Index::VERSION ||= "undef"
$CPAN::Site::Index::VERSION
Truth table50%1/2
A
A= $CPAN::Site::Index::VERSION
Aresult
11
00
82 1 trace "$program version $VERSION";
83  
84 1 my $global = catdir $mycpan, 'global';
85 1 my $mods = catdir $mycpan, 'modules';
86 1 my $authors = catdir $mycpan, 'authors';
87 1 mkdirhier $global, $mods, $authors;
88  
89 1 my $globdetails = update_global_cpan $mycpan, $globalcpan;
90  
91 # Create mailrc and modlist
92  
93 1 safe_copy catfile($global, '01mailrc.txt.gz')
94 , catfile($authors, '01mailrc.txt.gz');
95  
96 1 safe_copy catfile($global, '03modlist.data.gz')
97 , catfile($mods, '03modlist.data.gz');
98  
99 # Create packages details
100  
101 1 my $details = catfile $mods, '02packages.details.txt.gz';
102 1 my $newlist = catfile $mods, '02packages.details.tmp.gz';
103 1 my $newer;
104  
105 1 my $reuse_dists = {};
106 1 ▶ if($lazy && -f $details)
Branch: 1 branch
BranchTrueFalseTotal
if ($lazy and -f $details) 0 1 1
Condition33%1/3
$lazy and -f $details
!ll&&!rl&&r
100
MC/DC0%0/2
$lazy and -f $details
$lazy -f $details
Truth table33%1/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 1 my ($mypkgs, $distdirs)
113 = package_inventory $mycpan, $reuse_dists, $newer;
114  
115 1 ▶ merge_global_cpan $mycpan, $mypkgs, $globdetails
Branch: 1 branch
BranchTrueFalseTotal
if $fallback 0 1 1
116 if $fallback;
117  
118 1 create_details $details, $newlist, $mypkgs, $lazy, $undefs;
119  
120 1 ▶ if(-f $details)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $details) 0 1 1
121 0 { trace "backup old details file to $details.bak";
122 0 safe_copy $details, "$details.bak";
123 }
124  
125 1 ▶ if(-f $newlist)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $newlist) 1 0 1
126 1 { trace "promoting $newlist to current";
127 1 ▶ rename $newlist, $details
Branch: 1 branch
BranchTrueFalseTotal
rename $newlist, $details or &error(&__x("cannot rename '{from}' in '{to}'", "from", $newlist, "to", $details)) 1 0 1
128 or error __x"cannot rename '{from}' in '{to}'"
129 , from => $newlist, to => $details;
130 }
131  
132 1 calculate_checksums $distdirs, catdir($mycpan, 'authors', 'id');
133 }
134  
135 #
136 # Package Inventory
137 #
138  
139 # global variables for testing purposes (sorry)
140 2 our ($topdir, $findpkgs, %finddirs, $olddists, $index_age);
141  
142 sub register($$$)
143 31 ▶{ 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 31 ▶ if(ref $this_version)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $this_version) 0 31 31
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 31 ▶ my $registered_version = exists $findpkgs->{$package} ? $findpkgs->{$package}[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $CPAN::Site::Index::findpkgs->{$package} ? : 0 31 31
157 31 ▶ $this_version =~ s/^v// if $this_version;
Branch: 1 branch
BranchTrueFalseTotal
if $this_version 10 21 31
158  
159 31 ▶ return if defined $registered_version
Branch: 1 branch
BranchTrueFalseTotal
if defined $registered_version and $registered_version > $this_version 0 31 31
Condition33%1/3
defined $registered_version and $registered_version > $this_version
!ll&&!rl&&r
3100
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 31 $findpkgs->{$package} = [ $this_version, $dist ];
163 }
164  
165 sub package_inventory($$;$)
166 1 ▶{ (my $mycpan, $olddists, $index_age) = @_; #!!! see "my"
Subroutine package_inventory: called CC=1 SCAR=0.0
Pod undocumented
167 1 $topdir = catdir $mycpan, 'authors', 'id';
168 1 mkdirhier $topdir;
169  
170 1 $findpkgs = {};
171 1 trace "creating inventory from $topdir";
172  
173 1 find {wanted => \&inspect_archive, no_chdir => 1}, $topdir;
174 1 ($findpkgs, \%finddirs);
175 }
176  
177 sub package_on_usual_location($)
178 23 ▶{ my $file = shift;
Subroutine package_on_usual_location: called CC=3 SCAR=11.0
Pod undocumented
179 23 my ($top, $subdir, @rest) = splitdir $file;
180 23 ▶ defined $subdir or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $subdir or return 0 23 0 23
181  
182 !@rest # path is at top-level of distro
183 23 ▶ || $subdir eq 'lib'; # inside lib
Branch: 1 branch
BranchTrueFalseTotal
not @rest or $subdir eq "lib" 1 22 23
184 }
185  
186 sub inspect_archive
187 8 ▶{ my $fn = $File::Find::name;
Subroutine inspect_archive: called CC=10 SCAR=34.0
Pod undocumented
188 8 ▶ return unless -f $fn && ($fn =~ $tar_gz || $fn =~ $zip);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn and $fn =~ /$tar_gz/xi || $fn =~ /$zip/ 4 4 8
Condition50%3/6
-f $fn and $fn =~ /$tar_gz/xi || $fn =~ /$zip/
!ll&&!rl&&r
404
$fn =~ /$tar_gz/xi or $fn =~ /$zip/
l!l&&r!l&&!r
400
MC/DC33%1/3
-f $fn and $fn =~ /$tar_gz/xi || $fn =~ /$zip/
-f $fn $fn =~ /$tar_gz/xi $fn =~ /$zip/
Truth table50%2/4
A and B or C
A= -f $fnB= $fn =~ /$tar_gz/xiC= $fn =~ /$zip/
ABCresult
0XX0
1000
11X1
1011
189  
190 4 (my $dist = $fn) =~ s!^\Q$topdir\E[\\/]!!;
191  
192 4 ▶ 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 4 4
Condition33%1/3
defined $CPAN::Site::Index::index_age and -M $fn > $CPAN::Site::Index::index_age
!ll&&!rl&&r
400
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 4 trace "inspecting archive $fn";
208 4 $finddirs{$File::Find::dir}++;
209  
210 4 ▶ return inspect_tar_archive $dist, $fn
Branch: 1 branch
BranchTrueFalseTotal
if $fn =~ /$tar_gz/xi 4 0 4
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 4 ▶{ my ($dist, $fn) = @_;
Subroutine inspect_tar_archive: called CC=6 SCAR=17.9
Pod undocumented
219  
220 4 my $arch = Archive::Tar->new;
221 4 ▶ $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)) 4 0 4
222 or error __x"no files in tar archive '{fn}': {err}"
223 , fn => $fn, err => $arch->error;
224  
225 4 foreach my $file ($arch->get_files)
226 64 { my $fn = $file->full_path;
227 64 ▶ $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 21 43 64
Condition100%6/6
$file->is_file and $fn =~ /\.pm$/i and &package_on_usual_location($fn)
!ll&&!rl&&r
41221
$file->is_file and $fn =~ /\.pm$/i
!ll&&!rl&&r
192223
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 21 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 21 ▶{ my ($fn, $dist) = (shift, shift);
Subroutine collect_package_details: called CC=21 SCAR=31.4
Pod undocumented
255 21 my @lines = split /\r?\n/, ${shift()};
256 21 my $in_pod = 0;
257 21 my $package;
258 21 local $VERSION = undef; # may get destroyed by eval
259  
260 21 ▶ while(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 4650 21 4671
261 4650 { local $_ = shift @lines;
262 4650 ▶ last if m/^__(?:END|DATA)__$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^__(?:END|DATA)__$/ 0 4650 4650
263  
264 4650 ▶ $in_pod = ($1 ne 'cut') if m/^=(\w+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=(\w+)/ 324 4326 4650
265 4650 ▶ next if $in_pod || m/^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod or /^\s*#/ 1241 3409 4650
Condition100%3/3
$in_pod or /^\s*#/
l!l&&r!l&&!r
10781633409
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 3409 ▶ $_ .= shift @lines
Branch: 1 branch
BranchTrueFalseTotal
@lines and /package|use|VERSION/ and not /[;{]/ and do { $_ .= shift @lines } 4 3409 3413
Condition100%6/6
@lines and /package|use|VERSION/ and not /[;{]/
!ll&&!rl&&r
32901194
@lines and /package|use|VERSION/
!ll&&!rl&&r
193271123
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 3409 ▶ 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) 31 3378 3409
271 31 { my ($thispkg, $v) = ($1, $2);
272 31 my $thisversion;
273 31 ▶ if($v)
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 31 31
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 31 ▶ register $package, $VERSION, $dist
Branch: 1 branch
BranchTrueFalseTotal
if defined $package 10 21 31
281 if defined $package;
282  
283 31 ($package, $VERSION) = ($thispkg, $thisversion);
284 31 trace "pkg $package from $fn";
285 }
286  
287 3409 ▶ if( m/^\s* \$ ${package}::VERSION \s* = \s* ["']?(\w+?)["']? \s* ;/x )
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s* \$ $package::VERSION \s* = \s* ["']?(\w+?)["']? \s* ;/x) 0 3409 3409
288 0 { $VERSION = $1;
289 }
290  
291 3409 ▶ 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) 10 3399 3409
Condition100%3/3
not $CPAN::Site::Index::VERSION and /^ (?:use\s+version\s*;\s*)? (?:our)? \s* \$ ((?: \w+\:\:)*) VERSION \s* \= (.*)/x
!ll&&!rl&&r
866253310
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 10 ▶ { defined $2 or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 or next 10 0 10
294 10 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 10 eval "\$VERSION =$vers";
299 10 ▶ if(defined $VERSION)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CPAN::Site::Index::VERSION) 10 0 10
300 10 ▶ { ($package = $ns) =~ s/\:\:$//
Branch: 1 branch
BranchTrueFalseTotal
if length $ns 6 4 10
301 if length $ns;
302 10 trace "pkg $package version $VERSION";
303 }
304 }
305 }
306  
307 21 ▶ $VERSION = $VERSION->numify if ref $VERSION;
Branch: 1 branch
BranchTrueFalseTotal
if ref $CPAN::Site::Index::VERSION 0 21 21
308 21 ▶ register $package, $VERSION, $dist
Branch: 1 branch
BranchTrueFalseTotal
if defined $package 21 0 21
309 if defined $package;
310 }
311  
312 sub update_global_cpan($$)
313 1 ▶{ my ($mycpan, $globalcpan) = @_;
Subroutine update_global_cpan: called CC=5 SCAR=17.6
Pod undocumented
314  
315 1 my $global = catdir $mycpan, 'global';
316 my ($mailrc, $globdetails, $modlist) =
317 1 map { catfile $global, $_ }
318 qw/01mailrc.txt.gz 02packages.details.txt.gz 03modlist.data.gz/;
319  
320 1 ▶ return $globdetails
Branch: 1 branch
BranchTrueFalseTotal
if -f $globdetails and -f $globdetails and -f $modlist and -M $globdetails < $cpan_update 0 1 1
Condition33%3/9
-f $globdetails and -f $globdetails and -f $modlist and -M $globdetails < $cpan_update
!ll&&!rl&&r
100
-f $globdetails and -f $globdetails and -f $modlist
!ll&&!rl&&r
100
-f $globdetails and -f $globdetails
!ll&&!rl&&r
100
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 table20%1/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 1 info "(re)loading global CPAN files";
325  
326 1 mkdirhier $global;
327 1 load_file "$globalcpan/authors/01mailrc.txt.gz", $mailrc;
328 1 load_file "$globalcpan/modules/02packages.details.txt.gz", $globdetails;
329 1 load_file "$globalcpan/modules/03modlist.data.gz", $modlist;
330 1 $globdetails;
331 }
332  
333 sub load_file($$)
334 3 ▶{ my ($from, $to) = @_;
Subroutine load_file: called CC=2 SCAR=8.4
Pod undocumented
335 3 my $response = $ua->get($from, ':content_file' => $to);
336 3 ▶ return if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 3 0 3
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 2 ▶{ my ($details, $filename, $pkgs, $lazy, $undefs) = @_;
Subroutine create_details: called CC=8 SCAR=20.9
Pod undocumented
360  
361 2 trace "creating package details in $filename";
362 2 ▶ 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)) 2 0 2
363 or fault __x"generating gzipped {fn}", fn => $filename;
364  
365 2 my $lines = keys %$pkgs;
366 2 my $date = time2str time;
367 2 ▶ my $how = $lazy ? "lazy" : "full";
Branch: 1 branch
BranchTrueFalseTotal
$lazy ? : 1 1 2
368  
369 2 info "produced list of $lines packages $how";
370  
371 2 my $program = basename $0;
372 2 my $module = __PACKAGE__;
373 2 $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 2 foreach my $pkg (sort { lc($a) cmp lc($b) } keys %$pkgs)
386 32 { my ($version, $path) = @{$pkgs->{$pkg}};
387  
388 32 ▶ $version = 'undef'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $version or $version eq "" 21 11 32
Condition66%2/3
not defined $version or $version eq ""
l!l&&r!l&&!r
21011
MC/DC50%1/2
not defined $version or $version eq ""
not defined $version $version eq ""
Truth table66%2/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 32 ▶ if $version eq 'undef' && !$undefs;
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "undef" and not $undefs 0 32 32
Condition66%2/3
$version eq "undef" and not $undefs
!ll&&!rl&&r
11210
MC/DC0%0/2
$version eq "undef" and not $undefs
$version eq "undef" not $undefs
Truth table66%2/3
A and not(B)
A= $version eq "undef"B= not $undefs
ABresult
0X0
100
111
393  
394 32 $path =~ s,\\,/,g;
395 32 $fh->printf("%-30s\t%s\t%s\n", $pkg, $version, $path);
396 }
397 }
398  
399 sub calculate_checksums($$)
400 1 ▶{ my $dirs = shift;
Subroutine calculate_checksums: called CC=3 SCAR=11.0
Pod undocumented
401 1 my $root = shift;
402 1 trace "updating checksums";
403  
404 1 foreach my $dir (keys %$dirs)
405 1 { trace "summing $dir";
406 1 ▶ updatedir($dir, $root)
Branch: 1 branch
BranchTrueFalseTotal
&updatedir($dir, $root) or &warning("failed calculating checksums in {dir}", "dir", $dir) 1 0 1
407 or warning 'failed calculating checksums in {dir}', dir => $dir;
408 }
409 }
410  
411 sub read_details($)
412 0 ▶{ my $fn = shift;
Subroutine read_details: not called CC=6 SCAR=37.4
Pod undocumented
413 0 ▶ -f $fn or return {};
Branch: 1 branch
BranchTrueFalseTotal
-f $fn or return {} 0 0 0
414 0 trace "collecting all details from $fn";
415  
416 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
417 or fault __x"cannot read from {fn}", fn => $fn;
418  
419 0 my $line; # skip header, search first blank
420 0 ▶ do { $line = $fh->getline } until $line =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s*$/ or do { do { $line = $fh->getline } } 0 0 0
421  
422 0 my $time_last_update = (stat $fn)[9];
423 0 my %dists;
424  
425 0 ▶ while(my $line = $fh->getline)
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
426 0 { chomp $line;
427 0 my ($pkg, $version, $dist) = split ' ', $line, 3;
428  
429 0 ▶ unless($dist)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dist) 0 0 0
430 0 { warning "$fn error line=\n $line";
431 0 next;
432 }
433  
434 0 push @{$dists{$dist}}, [$pkg, $version];
435 }
436  
437 0 \%dists;
438 }
439  
440 sub remove_expired_details($$$)
441 0 ▶{ my ($mycpan, $dists, $newer) = @_;
Subroutine remove_expired_details: not called CC=4 SCAR=30.0
Pod undocumented
442 0 trace "extracting only existing local distributions";
443  
444 0 my $authors = catdir $mycpan, 'authors', 'id';
445 0 foreach my $dist (keys %$dists)
446 0 { my $fn = catfile $authors, $dist;
447 0 ▶ if(! -f $fn)
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $fn) { } 0 0 0
elsif (-M $fn < $newer) { } 0 0 0
448 { # removed local or a global dist
449 0 delete $dists->{$dist};
450 }
451 elsif(-M $fn < $newer)
452 0 { trace "dist $dist file updated, reindexing";
453 0 delete $dists->{$dist};
454 }
455 }
456 }
457  
458 sub mkdirhier(@)
459 5 ▶{ foreach my $dir (@_)
Subroutine mkdirhier: called CC=4 SCAR=13.9
Pod undocumented
460 7 ▶ { next if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 5 2 7
461 2 mkdirhier dirname $dir;
462  
463 2 ▶ mkdir $dir, 0755
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dir, 493 or &fault(&__x("cannot create directory {dir}", "dir", $dir)) 2 0 2
464 or fault __x"cannot create directory {dir}", dir => $dir;
465  
466 2 trace "created $dir";
467 }
468 5 1;
469 }
470  
471 sub cpan_mirror($$$@)
472 0 ▶{ my ($mycpan, $globalcpan, $mods, %opts) = @_;
Subroutine cpan_mirror: not called CC=13 SCAR=52.0
Pod undocumented
473 0 ▶ @$mods or return;
Branch: 1 branch
BranchTrueFalseTotal
@$mods or return 0 0 0
474 0 my %need = map { ($_ => 1) } @$mods;
475 0 my $auth = catdir $mycpan, 'authors', 'id';
476  
477 0 ▶ unless($ua)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 0 0 0
478 0 { $ua = LWP::UserAgent->new;
479 0 ▶ $ua->env_proxy if $opts{env_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"env_proxy"} 0 0 0
480 }
481  
482 0 my $globdetails
483 = update_global_cpan $mycpan, $globalcpan;
484  
485 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
486 or fault __x"cannot read from {fn}", fn => $globdetails;
487  
488 0 ▶ while(my $line = $fh->getline) # skip header, search first blank
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
489 0 ▶ { last if $line =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
490 }
491  
492 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
493 0 ▶ while(my $line = $fh->getline)
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
494 0 { my ($pkg, $version, $dist) = split ' ', $line;
495 0 ▶ delete $need{$pkg} or next;
Branch: 1 branch
BranchTrueFalseTotal
delete $need{$pkg} or next 0 0 0
496  
497 0 my $to = catfile $auth, split m#/#, $dist;
498 0 ▶ if(-f $to)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $to) 0 0 0
499 0 { trace __x"package {pkg} present in distribution {dist}"
500 , pkg => $pkg, dist => $dist;
501 0 next;
502 }
503  
504 0 my $source = "$globalcpan/authors/id/$dist";
505 0 mkdirhier dirname $to;
506 0 my $response = $ua->get($source, ':content_file' => $to);
507 0 ▶ unless($response->is_success)
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
508 0 { unlink $to;
509 0 error __x"failed to get {uri} for {to}: {err}"
510 , uri => $source, to => $to, err => $response->status_line;
511 }
512  
513 0 info __x"got {pkg} in {dist}", pkg => $pkg, dist => $dist;
514 }
515  
516 warning __x"package {pkg} does not exist", pkg => $_
517 0 for sort keys %need;
518 }
519  
520 2 1;
↑ Summary Site.pm »