CPANAuthors/Utils.pm

filter: Statementstmt 58.8% 30 / 51 Branchbran 18.7% 3 / 16 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 75.0% 9 / 12 Podpod 100% 3 / 3 totaltotal 45.5% 46 / 101 CC 14 SCAR 38.0
CC
14
Cov
43%
_cpan_file
90.9
cpan_packages
6.0
cpan_authors
2.0
CRAP 44.7
↑ Summary CPANAuthors.pm »
1 package Acme::CPANAuthors::Utils;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $VERSION = '0.27'; # see RT #43388
10 7 our @EXPORT_OK = qw( cpan_authors cpan_packages );
11  
12 7 my $CPANFiles = {};
13  
14 0 ▶sub clear_cached_cpan_files () { $CPANFiles = {}; }
Subroutine clear_cached_cpan_files: not called CC=1 SCAR=6.9
Pod documented
15  
16 1 ▶sub cpan_authors () {
Subroutine cpan_authors: called CC=2 SCAR=7.0
Pod documented
17 1 ▶ unless ( $CPANFiles->{authors} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPANFiles->{"authors"}) 1 0 1
18 1 require Acme::CPANAuthors::Utils::Authors;
19 $CPANFiles->{authors} =
20 1 Acme::CPANAuthors::Utils::Authors->new( _cpan_authors_file() );
21 }
22 1 return $CPANFiles->{authors};
23 }
24  
25 0 ▶sub cpan_packages () {
Subroutine cpan_packages: not called CC=2 SCAR=17.9
Pod documented
26 0 ▶ unless ( $CPANFiles->{packages} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPANFiles->{"packages"}) 0 0 0
27 0 require Acme::CPANAuthors::Utils::Packages;
28 $CPANFiles->{packages} =
29 0 Acme::CPANAuthors::Utils::Packages->new( _cpan_packages_file() );
30 }
31 0 return $CPANFiles->{packages};
32 }
33  
34 1 ▶sub _cpan_authors_file () {
Subroutine _cpan_authors_file: called CC=1 SCAR=0.0
35 1 _cpan_file( authors => '01mailrc.txt.gz' );
36 }
37  
38 0 ▶sub _cpan_packages_file () {
Subroutine _cpan_packages_file: not called CC=1 SCAR=6.9
39 0 _cpan_file( modules => '02packages.details.txt.gz' );
40 }
41  
42 1 ▶sub _cpan_file {
Subroutine _cpan_file: called CC=12 SCAR=45.1
43 1 my ($dir, $basename) = @_;
44  
45 1 my $file;
46 1 ▶ if ($ENV{ACME_CPANAUTHORS_HOME}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ACME_CPANAUTHORS_HOME"}) 1 0 1
47 1 $file = _catfile($ENV{ACME_CPANAUTHORS_HOME}, $dir, $basename);
48 1 ▶ return $file if $file && -r $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file and -r $file 1 0 1
Condition33%1/3
$file and -r $file
!ll&&!rl&&r
001
MC/DC0%0/2
$file and -r $file
$file -r $file
Truth table33%1/3
A and B
A= $fileB= -r $file
ABresult
0X0
100
111
49 }
50 0 require File::Path;
51 0 for my $parent (File::Spec->tmpdir, '.') {
52 0 my $tmpdir = File::Spec->catdir($parent, '.acmecpanauthors', $dir);
53 0 eval { File::Path::mkpath($tmpdir) };
54 0 ▶ next unless -d $tmpdir && -r _;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $tmpdir and -r _ 0 0 0
Condition0%0/3
-d $tmpdir and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-d $tmpdir and -r _
-d $tmpdir -r _
Truth table0%0/3
A and B
A= -d $tmpdirB= -r _
ABresult
0X0
100
111
55 0 $file = _catfile($tmpdir, $basename);
56 0 my $how_old = -M $file;
57 0 ▶ if (!-r $file or !$how_old or $how_old > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -r $file && $how_old or $how_old > 1) 0 0 0
Condition0%0/6
not -r $file && $how_old or $how_old > 1
l!l&&r!l&&!r
000
-r $file && $how_old
!ll&&!rl&&r
000
MC/DC0%0/3
not -r $file && $how_old or $how_old > 1
-r $file $how_old $how_old > 1
Truth table0%0/4
not(A && B) or C
A= -r $fileB= $how_oldC= $how_old > 1
ABCresult
0XX1
10X1
1111
1100
58 0 require HTTP::Tiny;
59 0 my $ua = HTTP::Tiny->new(env_proxy => 1);
60 0 my $res = $ua->mirror('http://www.cpan.org/'.$dir.'/'.$basename, $file);
61 0 ▶ next unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
62 }
63 0 ▶ return $file if -r $file;
Branch: 1 branch
BranchTrueFalseTotal
if -r $file 0 0 0
64 }
65 0 croak "$basename not found";
66 }
67  
68 1 ▶sub _catfile { File::Spec->canonpath( File::Spec->catfile( @_ ) ); }
Subroutine _catfile: called CC=1 SCAR=0.0
69  
70 7 1;
71  
72 __END__
↑ Summary CPANAuthors.pm »