dist/t9vPd3GCmf/Foo-Bar-0.01/inc/Module/Install/Fetch.pm

filter: Statementstmt 18.8% 13 / 69 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 12.5% 17 / 136 CC 24 SCAR 62.4
CC
24
Cov
11%
get_file
600.0
BEGIN
1.0
BEGIN
1.0
CRAP 514.4
↑ Summary inc/Module/Install/Fetch.pm »
1 #line 1
2 #line 1
3 1 ▶package Module::Install::Fetch;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use strict;
6 1 ▶use Module::Install::Base ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 use vars qw{$VERSION @ISA $ISCORE};
9 1 BEGIN {
10 1 $VERSION = '1.17';
11 @ISA = 'Module::Install::Base';
12 $ISCORE = 1;
13 0 ▶}
Subroutine get_file: not called CC=24 SCAR=64.0
Pod undocumented
14 0  
15 sub get_file {
16 0 ▶ my ($self, %args) = @_;
Branch: 1 branch
BranchTrueFalseTotal
() = $args{"url"} =~ m[^(\w+)://([^/]+)(.+)/(.+)] or return 0 0 0
17 my ($scheme, $host, $path, $file) =
18 0 ▶ $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme eq "http" and not eval { do { require LWP::Simple; 1 } }) 0 0 0
Condition0%0/3
$scheme eq "http" and not eval { do { require LWP::Simple; 1 } }
!ll&&!rl&&r
000
MC/DC0%0/2
$scheme eq "http" and not eval { do { require LWP::Simple; 1 } }
$scheme eq "http" not eval { do { require LWP::Simple; 1 } }
Truth table0%0/3
A and not(B)
A= $scheme eq "http"B= not eval { do { require LWP::Simple; 1 } }
ABresult
0X0
100
111
19  
20 0 ▶ if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
$args{"url"} = $args{"ftp_url"} or warn("LWP support unavailable!\n"), return 0 0 0
21 $args{url} = $args{ftp_url}
22 0 ▶ or (warn("LWP support unavailable!\n"), return);
Branch: 1 branch
BranchTrueFalseTotal
() = $args{"url"} =~ m[^(\w+)://([^/]+)(.+)/(.+)] or return 0 0 0
23 ($scheme, $host, $path, $file) =
24 $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
25 0 }
26 0  
27 $|++;
28 0 ▶ print "Fetching '$file' from $host... ";
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Socket; Socket::inet_aton($host) } }) 0 0 0
29 0  
30 0 unless (eval { require Socket; Socket::inet_aton($host) }) {
31 warn "'$host' resolve failed!\n";
32 return;
33 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme eq "ftp" or $scheme eq "http" 0 0 0
Condition0%0/3
$scheme eq "ftp" or $scheme eq "http"
l!l&&r!l&&!r
000
MC/DC0%0/2
$scheme eq "ftp" or $scheme eq "http"
$scheme eq "ftp" $scheme eq "http"
Truth table0%0/3
A or B
A= $scheme eq "ftp"B= $scheme eq "http"
ABresult
1X1
011
000
34  
35 0 return unless $scheme eq 'ftp' or $scheme eq 'http';
36 0  
37 0 ▶ require Cwd;
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"local_dir"} 0 0 0
Condition0%0/5
exists $args{'local_dir'} && (chdir $args{'local_dir'} || (return))
!ll&&!rl&&r
000
chdir $args{"local_dir"} or return
l!l
00
MC/DC0%0/2
exists $args{'local_dir'} && (chdir $args{'local_dir'} || (return))
exists $args{'local_dir'} chdir $args{"local_dir"}
Truth table0%0/3
A && B
A= exists $args{'local_dir'}B= chdir $args{"local_dir"}
ABresult
0X0
100
111
38 my $dir = Cwd::getcwd();
39 0 ▶ chdir $args{local_dir} or return if exists $args{local_dir};
Branch: 3 branches
BranchTrueFalseTotal
if (eval { do { require LWP::Simple; 1 } }) { } 0 0 0
elsif (eval { do { require Net::FTP; 1 } }) { } 0 0 0
elsif (my $ftp = $self->can_run('ftp')) { } 0 0 0
40 0  
41 if (eval { require LWP::Simple; 1 }) {
42 0 LWP::Simple::mirror($args{url}, $file);
43 }
44 0 elsif (eval { require Net::FTP; 1 }) { eval {
45 0 # use Net::FTP to get past firewall
46 0 my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600);
47 0 $ftp->login("anonymous", 'anonymous@example.com');
48 0 ▶ $ftp->cwd($path);
Branch: 1 branch
BranchTrueFalseTotal
$ftp->get($file) or warn("$!\n"), return 0 0 0
49 0 $ftp->binary;
50 $ftp->get($file) or (warn("$!\n"), return);
51 0 $ftp->quit;
52 } }
53 0 elsif (my $ftp = $self->can_run('ftp')) { eval {
54 0 # no Net::FTP, fallback to ftp.exe
55 require FileHandle;
56 0 my $fh = FileHandle->new;
57 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh->open("|$ftp -n")) 0 0 0
58 0 local $SIG{CHLD} = 'IGNORE';
59 0 unless ($fh->open("|$ftp -n")) {
60 warn "Couldn't open ftp: $!\n";
61 chdir $dir; return;
62 0 }
63  
64 my @dialog = split(/\n/, <<"END_FTP");
65 open $host
66 user anonymous anonymous\@example.com
67 cd $path
68 binary
69 get $file $file
70 0 quit
71 0 END_FTP
72 foreach (@dialog) { $fh->print("$_\n") }
73 $fh->close;
74 0 } }
75 0 else {
76 warn "No working 'ftp' program available!\n";
77 chdir $dir; return;
78 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 0 0
79 0  
80 0 unless (-f $file) {
81 warn "Fetching failed: $@\n";
82 chdir $dir; return;
83 0 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"size"} and -s $file != $args{"size"} 0 0 0
Condition0%0/3
exists $args{"size"} and -s $file != $args{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"size"} and -s $file != $args{"size"}
exists $args{"size"} -s $file != $args{"size"}
Truth table0%0/3
A and B
A= exists $args{"size"}B= -s $file != $args{"size"}
ABresult
0X0
100
111
84 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"run"} 0 0 0
85 0 ▶ return if exists $args{size} and -s $file != $args{size};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"remove"} 0 0 0
86 system($args{run}) if exists $args{run};
87 unlink($file) if $args{remove};
88 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
!exists $args{'check_for'} || -e $args{'check_for'} ? : 0 0 0
Condition0%0/3
not exists $args{"check_for"} or -e $args{"check_for"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $args{"check_for"} or -e $args{"check_for"}
not exists $args{"check_for"} -e $args{"check_for"}
Truth table0%0/3
not(A) or B
A= not exists $args{"check_for"}B= -e $args{"check_for"}
ABresult
1X1
011
000
89 0 print(((!exists $args{check_for} or -e $args{check_for})
90 ? "done!" : "failed! ($!)"), "\n");
91 chdir $dir; return !$?;
92 1 }
93  
94 1;
↑ Summary inc/Module/Install/Fetch.pm »