blib/lib/Alien/Build/Plugin/Core/Download.pm

filter: Statementstmt 81.9% 86 / 105 Branchbran 66.6% 28 / 42 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 79.5% 128 / 161 CC 26 SCAR 33.9
CC
26
Cov
78%
_hook
37.3
BEGIN
1.0
BEGIN
1.0
CRAP 29.6
« blib/lib/Alien/Build/Plugin/Fetch/Wget.pm ↑ Summary blib/lib/Alien/Build/Plugin/PkgConfig/CommandLine.pm »
1 package Alien::Build::Plugin::Core::Download;
2  
3 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 57 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 57 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 57 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 57 ▶use Alien::Build::Util qw( _mirror );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Core download plugin
11 57 our $VERSION = '2.88'; # VERSION
12  
13  
14 sub _hook
15 45 ▶{
Subroutine _hook: called CC=26 SCAR=36.2
16 45 my($build) = @_;
17  
18 45 my $res = $build->fetch;
19  
20 41 ▶ if($res->{type} =~ /^(?:html|dir_listing)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"type"} =~ /^(?:html|dir_listing)$/) 4 37 41
21 {
22 4 my $type = $res->{type};
23 4 $type =~ s/_/ /;
24 4 $build->log("decoding $type");
25 4 $res = $build->decode($res);
26 }
27  
28 41 ▶ if($res->{type} eq 'list')
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"type"} eq "list") 14 27 41
29 {
30 14 my $orig = $res;
31 14 $res = $build->prefer($res);
32  
33 14 my @exclude;
34 14 ▶ if($build->meta->prop->{start_url} =~ /^https:/)
Branch: 1 branch
BranchTrueFalseTotal
if ($build->meta->prop->{"start_url"} =~ /^https:/) 5 9 14
35 {
36 5 @{ $res->{list} } = grep {
37 307 ▶ $_->{url} =~ /https:/ ? 1 : do {
Branch: 1 branch
BranchTrueFalseTotal
$_->{'url'} =~ /https:/ ? : 305 2 307
38 2 push @exclude, $_->{url};
39 2 0;
40 }
41 5 } @{ $res->{list} };
42 }
43  
44 14 ▶ if(@{ $res->{list} } == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$res->{"list"};} == 0) 0 14 14
45 {
46 0 my @excluded = map { $_->{url} } @{ $orig->{list} };
47 0 ▶ if(@excluded)
Branch: 1 branch
BranchTrueFalseTotal
if (@excluded) { } 0 0 0
48 {
49 0 ▶ if(@excluded > 15)
Branch: 1 branch
BranchTrueFalseTotal
if (@excluded > 15) 0 0 0
50 {
51 0 splice @excluded , 14;
52 0 push @excluded, '...';
53 }
54 0 $build->log("These files were excluded by the filter stage:");
55 0 $build->log("excluded $_") for @excluded;
56 }
57 else
58 {
59 0 $build->log("No files found prior to the filter stage");
60 }
61 0 die "no matching files in listing";
62 }
63 14 my $version = $res->{list}->[0]->{version};
64 14 my($pick, @other) = map { $_->{url} } @{ $res->{list} };
65  
66 14 ▶ if(@other > 8)
Branch: 1 branch
BranchTrueFalseTotal
if (@other > 8) 3 11 14
67 {
68 3 splice @other, 7;
69 3 push @other, '...';
70 }
71 14 $build->log("candidate *$pick");
72 14 $build->log("candidate $_") for @other;
73  
74 14 ▶ if(@exclude)
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude) 2 12 14
75 {
76 2 ▶ if(@exclude > 8)
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude > 8) 0 2 2
77 {
78 0 splice @exclude, 7;
79 0 push @exclude, '...';
80 }
81 2 $build->log("excluded insecure URLs:");
82 2 $build->log($_) for @exclude;
83 }
84  
85 14 $res = $build->fetch($pick);
86  
87 14 ▶ if($version)
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 11 3 14
88 {
89 11 $version =~ s/\.+$//;
90 11 $build->log("setting version based on archive to $version");
91 11 $build->runtime_prop->{version} = $version;
92 }
93 }
94  
95 41 ▶ if($res->{type} eq 'file')
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"type"} eq "file") 41 0 41
96 {
97 41 my $alienfile = $res->{filename};
98 41 $build->log("downloaded $alienfile");
99 41 ▶ if($res->{content})
Branch: 2 branches
BranchTrueFalseTotal
if ($res->{'content'}) { } 28 13 41
elsif ($res->{'path'}) { } 13 0 13
100 {
101 28 my $tmp = Alien::Build::TempDir->new($build, "download");
102 28 my $path = Path::Tiny->new("$tmp/$alienfile");
103 28 $path->spew_raw($res->{content});
104 28 $build->install_prop->{download} = $path->stringify;
105 28 $build->install_prop->{complete}->{download} = 1;
106 28 ▶ $build->install_prop->{download_detail}->{"$path"}->{protocol} = $res->{protocol} if defined $res->{protocol};
Branch: 1 branch
BranchTrueFalseTotal
if defined $res->{"protocol"} 28 0 28
107 28 return $build;
108 }
109 elsif($res->{path})
110 {
111 13 ▶ if(defined $res->{tmp} && !$res->{tmp})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res->{'tmp'} and not $res->{'tmp'}) { } 11 2 13
Condition100%3/3
defined $res->{"tmp"} and not $res->{"tmp"}
!ll&&!rl&&r
1111
MC/DC100%2/2
defined $res->{"tmp"} and not $res->{"tmp"}
defined $res->{"tmp"} not $res->{"tmp"}
Truth table100%3/3
A and not(B)
A= defined $res->{"tmp"}B= not $res->{"tmp"}
ABresult
0X0
100
111
112 {
113 11 ▶ if(-e $res->{path})
Branch: 1 branch
BranchTrueFalseTotal
if (-e $res->{'path'}) { } 11 0 11
114 {
115 11 $build->install_prop->{download} = $res->{path};
116 11 $build->install_prop->{complete}->{download} = 1;
117 11 ▶ $build->install_prop->{download_detail}->{$res->{path}}->{protocol} = $res->{protocol} if defined $res->{protocol};
Branch: 1 branch
BranchTrueFalseTotal
if defined $res->{"protocol"} 11 0 11
118 }
119 else
120 {
121 0 die "not a file or directory: @{[ $res->{path} ]}";
122 }
123 }
124 else
125 {
126 2 my $from = Path::Tiny->new($res->{path});
127 2 my $tmp = Alien::Build::TempDir->new($build, "download");
128 2 my $to = Path::Tiny->new("$tmp/@{[ $from->basename ]}");
129 2 ▶ if(-d $res->{path})
Branch: 1 branch
BranchTrueFalseTotal
if (-d $res->{'path'}) { } 0 2 2
130 {
131 # Please note: _mirror and Alien::Build::Util are ONLY
132 # allowed to be used by core plugins. If you are writing
133 # a non-core plugin it may be removed. That is why it
134 # is private.
135 0 _mirror $from, $to;
136 }
137 else
138 {
139 2 require File::Copy;
140 2 ▶ File::Copy::copy(
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy("$from", "$to") or die "copy $from => $to failed: $!" 2 0 2
141 "$from" => "$to",
142 ) || die "copy $from => $to failed: $!";
143 }
144 2 $build->install_prop->{download} = $to->stringify;
145 2 $build->install_prop->{complete}->{download} = 1;
146 2 ▶ $build->install_prop->{download_detail}->{"$to"}->{protocol} = $res->{protocol} if defined $res->{protocol};
Branch: 1 branch
BranchTrueFalseTotal
if defined $res->{"protocol"} 2 0 2
147 }
148 13 return $build;
149 }
150 0 die "file without content or path";
151 }
152 0 die "unknown fetch response type: @{[ $res->{type} ]}";
153 }
154  
155 sub init
156 399 ▶{
Subroutine init: called CC=1 SCAR=0.0
Pod documented
157 399 my($self, $meta) = @_;
158  
159 399 $meta->default_hook(download => \&_hook);
160 }
161  
162 57 1;
163  
164 __END__
« blib/lib/Alien/Build/Plugin/Fetch/Wget.pm ↑ Summary blib/lib/Alien/Build/Plugin/PkgConfig/CommandLine.pm »