| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | $file = _catfile($ENV{ACME_CPANAUTHORS_HOME}, $dir, $basename); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | return $file if $file && -r $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file and -r $file
MC/DC0%0/2
$file and -r $file
$file
-r $file
Truth table33%1/3
A and B
A= $fileB= -r $file
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
-d $tmpdir and -r _
MC/DC0%0/2
-d $tmpdir and -r _
-d $tmpdir
-r _
Truth table0%0/3
A and B
A= -d $tmpdirB= -r _
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
not -r $file && $how_old or $how_old > 1
-r $file && $how_old
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return $file if -r $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||