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

filter: Statementstmt 78.9% 75 / 95 Branchbran 74.0% 40 / 54 Conditioncond 66.6% 12 / 18 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 75.7% 144 / 190 CC 36 SCAR 27.4
CC
36
Cov
76%
init
23.3
_pick
16.6
_pick_decoder
8.7
CRAP 15.4
« blib/lib/Test/Alien/Diag.pm ↑ Summary blib/lib/Alien/Build/Plugin/Fetch/CurlCommand.pm »
1 package Alien::Build::Plugin::Download::Negotiate;
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 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Alien::Build::Util qw( _has_ssl );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Download negotiation plugin
11 7 our $VERSION = '2.88'; # VERSION
12  
13  
14 7 has '+url' => undef;
15  
16  
17 7 has 'filter' => undef;
18  
19  
20 7 has 'version' => undef;
21  
22  
23 7 has 'ssl' => 0;
24  
25  
26 7 has 'passive' => 0;
27  
28 7 has 'scheme' => undef;
29  
30  
31 7 has 'bootstrap_ssl' => 0;
32  
33  
34 7 has 'prefer' => 1;
35  
36  
37 7 has 'decoder' => undef;
38  
39  
40 sub pick
41 27 ▶{
Subroutine pick: called CC=3 SCAR=11.0
Pod documented
42 27 my($self) = @_;
43 27 my($fetch, @decoders) = $self->_pick;
44 27 ▶ if($self->decoder)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->decoder) 2 25 27
45 {
46 2 ▶ @decoders = ref $self->decoder ? @{ $self->decoder } : ($self->decoder);
Branch: 1 branch
BranchTrueFalseTotal
ref $self->decoder ? : 1 1 2
47 }
48 27 ($fetch, @decoders);
49 }
50  
51 sub _pick_decoder
52 5 ▶{
Subroutine _pick_decoder: called CC=4 SCAR=21.7
53 5 my($self) = @_;
54  
55 5 ▶ if(eval { require Mojo::DOM58; Mojo::DOM58->VERSION(1.00); 1 })
Branch: 3 branches
BranchTrueFalseTotal
if (eval { do { require Mojo::DOM58; 'Mojo::DOM58'->VERSION(1.0); 1 } }) { } 5 0 5
elsif (eval { do { require Mojo::DOM; require Mojolicious; 'Mojolicious'->VERSION('7.00'); 1 } }) { } 0 0 0
elsif (eval { do { require HTML::LinkExtor; 1 } }) { } 0 0 0
56 5 { return "Decode::Mojo" }
57 0 elsif(eval { require Mojo::DOM; require Mojolicious; Mojolicious->VERSION('7.00'); 1 })
58 0 { return "Decode::Mojo" }
59 0 elsif(eval { require HTML::LinkExtor; 1; })
60 0 { return "Decode::HTML" }
61 else
62 0 { return "Decode::Mojo" }
63 }
64  
65 sub _pick
66 27 ▶{
Subroutine _pick: called CC=15 SCAR=28.1
67 27 my($self) = @_;
68  
69 27 ▶ $self->scheme(
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->scheme 27 0 27
!($self->url =~ /(ftps?|https?|file):/i) ? : 11 16 27
70 $self->url !~ m!(ftps?|https?|file):!i
71 ? 'file'
72 : $self->url =~ m!^([a-z]+):!i
73 ) unless defined $self->scheme;
74  
75 27 ▶ if($self->scheme eq 'https' || ($self->scheme eq 'http' && $self->ssl))
Branch: 4 branches
BranchTrueFalseTotal
if ($self->scheme eq 'https' or $self->scheme eq 'http' and $self->ssl) { } 7 20 27
elsif ($self->scheme eq 'http') { } 6 14 20
elsif ($self->scheme eq 'ftp') { } 2 12 14
elsif ($self->scheme eq 'file') { } 12 0 12
Condition66%4/6
$self->scheme eq "https" or $self->scheme eq "http" and $self->ssl
l!l&&r!l&&!r
7020
$self->scheme eq "http" and $self->ssl
!ll&&!rl&&r
1460
MC/DC33%1/3
$self->scheme eq "https" or $self->scheme eq "http" and $self->ssl
$self->scheme eq "https" $self->scheme eq "http" $self->ssl
Truth table75%3/4
A or B and C
A= $self->scheme eq "https"B= $self->scheme eq "http"C= $self->ssl
ABCresult
1XX1
0111
00X0
0100
76 {
77 7 ▶ if($self->bootstrap_ssl && ! _has_ssl)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->bootstrap_ssl and not _has_ssl()) { } 1 6 7
elsif (_has_ssl()) { } 5 1 6
Condition100%3/3
$self->bootstrap_ssl and not _has_ssl()
!ll&&!rl&&r
421
MC/DC100%2/2
$self->bootstrap_ssl and not _has_ssl()
$self->bootstrap_ssl not _has_ssl()
Truth table100%3/3
A and not(B)
A= $self->bootstrap_sslB= not _has_ssl()
ABresult
0X0
100
111
78 {
79 1 return (['Fetch::CurlCommand','Fetch::Wget'], __PACKAGE__->_pick_decoder);
80 }
81 elsif(_has_ssl)
82 {
83 5 return ('Fetch::HTTPTiny', __PACKAGE__->_pick_decoder);
84 }
85 #elsif(do { require Alien::Build::Plugin::Fetch::CurlCommand; Alien::Build::Plugin::Fetch::CurlCommand->protocol_ok('https') })
86 #{
87 # return ('Fetch::CurlCommand', __PACKAGE__->_pick_decoder);
88 #}
89 else
90 {
91 1 return ('Fetch::HTTPTiny', __PACKAGE__->_pick_decoder);
92 }
93 }
94 elsif($self->scheme eq 'http')
95 {
96 6 return ('Fetch::HTTPTiny', __PACKAGE__->_pick_decoder);
97 }
98 elsif($self->scheme eq 'ftp')
99 {
100 2 ▶ if($ENV{ftp_proxy} || $ENV{all_proxy})
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'ftp_proxy'} or $ENV{'all_proxy'}) { } 1 1 2
Condition66%2/3
$ENV{"ftp_proxy"} or $ENV{"all_proxy"}
l!l&&r!l&&!r
101
MC/DC50%1/2
$ENV{"ftp_proxy"} or $ENV{"all_proxy"}
$ENV{"ftp_proxy"} $ENV{"all_proxy"}
Truth table66%2/3
A or B
A= $ENV{"ftp_proxy"}B= $ENV{"all_proxy"}
ABresult
1X1
011
000
101 {
102 1 ▶ return $self->scheme =~ /^ftps?/
Branch: 1 branch
BranchTrueFalseTotal
$self->scheme =~ /^ftps?/ ? : 1 0 1
103 ? ('Fetch::LWP', 'Decode::DirListing', __PACKAGE__->_pick_decoder)
104 : ('Fetch::LWP', __PACKAGE__->_pick_decoder);
105 }
106 else
107 {
108 1 return ('Fetch::NetFTP');
109 }
110 }
111 elsif($self->scheme eq 'file')
112 {
113 12 return ('Fetch::Local');
114 }
115 else
116 {
117 0 die "do not know how to handle scheme @{[ $self->scheme ]} for @{[ $self->url ]}";
118 }
119 }
120  
121 sub init
122 15 ▶{
Subroutine init: called CC=17 SCAR=31.5
Pod documented
123 15 my($self, $meta) = @_;
124  
125 15 ▶ unless(defined $self->url)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->url) 5 10 15
126 {
127 5 ▶ if(defined $meta->prop->{start_url})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta->prop->{'start_url'}) { } 5 0 5
128 {
129 5 $self->url($meta->prop->{start_url});
130 }
131 else
132 {
133 0 Carp::croak "url is a required property unless you use the start_url directive";
134 }
135 }
136  
137 15 ▶ if($self->url =~ /^http.*github.com.*releases$/ && !$meta->has_requires('configure', 'Download::GitHub'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->url =~ /^http.*github.com.*releases$/ and not $meta->has_requires("configure", "Download::GitHub")) 0 15 15
Condition33%1/3
$self->url =~ /^http.*github.com.*releases$/ and not $meta->has_requires("configure", "Download::GitHub")
!ll&&!rl&&r
1500
MC/DC0%0/2
$self->url =~ /^http.*github.com.*releases$/ and not $meta->has_requires("configure", "Download::GitHub")
$self->url =~ /^http.*github.com.*releases$/ not $meta->has_requires("configure", "Download::GitHub")
Truth table33%1/3
A and not(B)
A= $self->url =~ /^http.*github.com.*releases$/B= not $meta->has_requires("configure", "Download::GitHub")
ABresult
0X0
100
111
138 {
139 0 Alien::Build->log('!! WARNING !! WARNING !!');
140 0 Alien::Build->log('!! WARNING !! It looks like this alien is using the regular download negotiator');
141 0 Alien::Build->log('plugin on a GitHub release page. This will typically not work due to changes');
142 0 Alien::Build->log('in the way GitHub release page works now. The Alien should instead be updated');
143 0 Alien::Build->log('to use the Download::GitHub plugin, which uses the GitHub API to find available');
144 0 Alien::Build->log('releases. See: https://metacpan.org/pod/Alien::Build::Plugin::Download::GitHub');
145 0 Alien::Build->log('!! WARNING !! WARNING !!');
146 }
147  
148 15 ▶ $meta->add_requires('share' => 'Alien::Build::Plugin::Download::Negotiate' => '0.61')
Branch: 1 branch
BranchTrueFalseTotal
if $self->passive 0 15 15
149 if $self->passive;
150  
151 15 $meta->prop->{plugin_download_negotiate_default_url} = $self->url;
152  
153 15 my($fetch, @decoders) = $self->pick;
154  
155 15 ▶ $fetch = [ $fetch ] unless ref $fetch;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fetch 15 0 15
156  
157 15 foreach my $fetch (@$fetch)
158 {
159 15 my @args;
160 15 push @args, ssl => $self->ssl;
161 # For historical reasons, we pass the URL into older fetch plugins, because
162 # this used to be the interface. Using start_url is now preferred!
163 15 ▶ push @args, url => $self->url if $fetch =~ /^Fetch::(HTTPTiny|LWP|Local|LocalDir|NetFTP|CurlCommand)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $fetch =~ /^Fetch::(HTTPTiny|LWP|Local|LocalDir|NetFTP|CurlCommand)$/ 15 0 15
164 15 ▶ push @args, passive => $self->passive if $fetch eq 'Fetch::NetFTP';
Branch: 1 branch
BranchTrueFalseTotal
if $fetch eq "Fetch::NetFTP" 0 15 15
165 15 ▶ push @args, bootstrap_ssl => $self->bootstrap_ssl if $self->bootstrap_ssl;
Branch: 1 branch
BranchTrueFalseTotal
if $self->bootstrap_ssl 1 14 15
166  
167 15 $meta->apply_plugin($fetch, @args);
168 }
169  
170 15 ▶ if($self->version)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version) 8 7 15
171 {
172 8 $meta->apply_plugin($_) for @decoders;
173  
174 8 ▶ if(defined $self->prefer && ref($self->prefer) eq 'CODE')
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->prefer and ref $self->prefer eq 'CODE') { } 1 7 8
elsif ($self->prefer) { } 6 1 7
Condition66%2/3
defined $self->prefer and ref $self->prefer eq "CODE"
!ll&&!rl&&r
071
MC/DC50%1/2
defined $self->prefer and ref $self->prefer eq "CODE"
defined $self->prefer ref $self->prefer eq "CODE"
Truth table66%2/3
A and B
A= defined $self->preferB= ref $self->prefer eq "CODE"
ABresult
0X0
100
111
175 {
176 1 $meta->add_requires('share' => 'Alien::Build::Plugin::Download::Negotiate' => '1.30');
177 1 $meta->register_hook(
178 prefer => $self->prefer,
179 );
180 }
181 elsif($self->prefer)
182 {
183 6 ▶ $meta->apply_plugin('Prefer::SortVersions',
Branch: 1 branch
BranchTrueFalseTotal
defined $self->filter ? : 2 4 6
184 (defined $self->filter ? (filter => $self->filter) : ()),
185 version => $self->version,
186 );
187 }
188 else
189 {
190 1 $meta->add_requires('share' => 'Alien::Build::Plugin::Download::Negotiate' => '1.30');
191 }
192 }
193 }
194  
195 7 1;
196  
197 __END__
« blib/lib/Test/Alien/Diag.pm ↑ Summary blib/lib/Alien/Build/Plugin/Fetch/CurlCommand.pm »