| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 300 | ▶ | my $scheme = lc( $uri->scheme // 'http' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$uri->scheme // "http"
MC/DC0%0/1
$uri->scheme // "http"
$uri->scheme
Truth table50%1/2
A
A= $uri->scheme
| |||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC100%1/1
$ssl //= $scheme eq "https"
$ssl
Truth table100%2/2
A
A= $ssl
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 300 | ▶ | my $target = $uri->can('host_port') && defined $uri->host && length $uri->host | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$uri->can("host_port") and defined $uri->host and length $uri->host
$uri->can("host_port") and defined $uri->host
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
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | ? $scheme.'://'.$uri->host_port | ||||||||||||||||||||||||||||||||||||||||||
| 26 | : $scheme.' URL'; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 300 | ▶ | for my $need ( \@CONNECTOR, $ssl ? \@SSL : () ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||