blib/lib/Langertha/HTTP/ConnectCheck.pm

filter: Statementstmt 100% 30 / 30 Branchbran 90.0% 9 / 10 Conditioncond 50.0% 5 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 83.3% 50 / 60 CC 11 SCAR 22.3
CC
11
Cov
88%
connect_error
11.5
BEGIN
1.0
BEGIN
1.0
CRAP 9.3
« blib/lib/Langertha/Request/SyncHTTP.pm ↑ Summary blib/lib/Langertha/ModelProbe.pm »
1 package Langertha::HTTP::ConnectCheck;
2 # ABSTRACT: Check that the modules Net::Async::HTTP loads at connect time load
3 27 our $VERSION = '0.505';
4 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 # Private to IO::Async (IO::Async::Loop->connect loads it via __new_feature);
10 # see the POD above for the assumption and when this check can go.
11 27 my @CONNECTOR = ( 'IO::Async::Internals::Connector', undef,
12 'every HTTP connection needs it' );
13 # Net::Async::HTTP 0.50 requires 0.12 (the ->connect(handle) fix) after loading.
14 27 my @SSL = ( 'IO::Async::SSL', '0.12',
15 'an SSL (https) connection needs it, with IO::Socket::SSL, Net::SSLeay and the system libssl' );
16  
17 300 ▶sub connect_error {
Subroutine connect_error: called CC=11 SCAR=24.4
Pod documented
18 300 my ( $uri, $ssl ) = @_;
19 300 ▶ $uri = URI->new("$uri") unless ref $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $uri 38 262 300
20 300 ▶ my $scheme = lc( $uri->scheme // 'http' );
Condition50%1/2
$uri->scheme // "http"
l!l
3000
MC/DC0%0/1
$uri->scheme // "http"
$uri->scheme
Truth table50%1/2
A
A= $uri->scheme
Aresult
11
00
21 # Net::Async::HTTP 0.50 (_do_request) derives SSL from the scheme, but passes
22 # the caller's own SSL option after it, so an explicit one wins.
23 300 ▶ $ssl //= $scheme eq 'https';
Condition100%2/2
$ssl //= $scheme eq "https"
l!l
4296
MC/DC100%1/1
$ssl //= $scheme eq "https"
$ssl
Truth table100%2/2
A
A= $ssl
Aresult
11
00
24 300 ▶ my $target = $uri->can('host_port') && defined $uri->host && length $uri->host
Branch: 1 branch
BranchTrueFalseTotal
$uri->can('host_port') && defined $uri->host && length $uri->host ? : 300 0 300
Condition33%2/6
$uri->can("host_port") and defined $uri->host and length $uri->host
!ll&&!rl&&r
00300
$uri->can("host_port") and defined $uri->host
!ll&&!rl&&r
00300
MC/DC0%0/3
$uri->can("host_port") and defined $uri->host and length $uri->host
$uri->can("host_port") defined $uri->host length $uri->host
Truth table25%1/4
A and B and C
A= $uri->can("host_port")B= defined $uri->hostC= length $uri->host
ABCresult
0XX0
10X0
1100
1111
25 ? $scheme.'://'.$uri->host_port
26 : $scheme.' URL';
27 300 ▶ for my $need ( \@CONNECTOR, $ssl ? \@SSL : () ) {
Branch: 1 branch
BranchTrueFalseTotal
$ssl ? : 17 283 300
28 316 my ( $module, $min_version, $why ) = @{$need};
29 316 ( my $file = "$module.pm" ) =~ s{::}{/}g;
30 316 local $@;
31 316 ▶ next if eval { require $file; $module->VERSION($min_version) if defined $min_version; 1 };
Branch: 2 branches
BranchTrueFalseTotal
if eval { do { require $file; $module->VERSION($min_version) if defined $min_version; 1 } } 310 6 316
if defined $min_version 13 297 310
32 6 my ($reason) = split /\n/, $@;
33 6 return "cannot connect to $target: $module failed to load ($reason); $why";
34 }
35 294 return;
36 }
37  
38 27 1;
39  
40 __END__
« blib/lib/Langertha/Request/SyncHTTP.pm ↑ Summary blib/lib/Langertha/ModelProbe.pm »