| 1 | package Langertha::Raider::ConnectCheck; | ||||||||||||||
| 2 | # ABSTRACT: Internal check that Net::Async::HTTP can open a connection to a URL | ||||||||||||||
| 3 | 118 | our $VERSION = '0.503'; | |||||||||||||
| 4 | |||||||||||||||
| 5 | 118 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 118 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 118 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 118 | ▶ | use URI; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 118 | ▶ | use Exporter 'import'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 118 | our @EXPORT_OK = qw( connect_error ); | |||||||||||||
| 12 | |||||||||||||||
| 13 | |||||||||||||||
| 14 | 124 | ▶ | sub connect_error { | ||||||||||||
|
Subroutine
connect_error: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||
| 15 | 124 | my ( $url ) = @_; | |||||||||||||
| 16 | 124 | my $uri = URI->new($url); | |||||||||||||
| 17 | 124 | ▶ | 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
| |||||||||||||||
| 18 | # Scheme, host and port only: a query or userinfo may carry a key. | ||||||||||||||
| 19 | 124 | ▶ | my $target = !$uri->can('host') ? $url | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 20 | : defined $uri->host ? $scheme.'://'.$uri->host_port | ||||||||||||||
| 21 | : $scheme.' URLs'; | ||||||||||||||
| 22 | 124 | my @needed = ( [ 'IO::Async::Internals::Connector', 'every HTTP connection needs it' ] ); | |||||||||||||
| 23 | 124 | ▶ | push @needed, [ 'IO::Async::SSL', 'https needs it, with IO::Socket::SSL, Net::SSLeay and the system libssl' ] | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | if $scheme eq 'https'; | ||||||||||||||
| 25 | 124 | for my $need (@needed) { | |||||||||||||
| 26 | 233 | my ( $module, $why ) = @$need; | |||||||||||||
| 27 | 233 | ▶ | next if eval { use_module($module); 1 }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 9 | my ( $reason ) = split /\n/, $@; | |||||||||||||
| 29 | 9 | return 'Cannot connect to '.$target.': '.$module.' failed to load ('.$reason.'); '.$why; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | 115 | return; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 118 | 1; | |||||||||||||
| 35 | |||||||||||||||
| 36 | __END__ | ||||||||||||||
| 37 | |||||||||||||||
| 38 | =pod | ||||||||||||||
| 39 | |||||||||||||||
| 40 | =encoding UTF-8 | ||||||||||||||
| 41 | |||||||||||||||
| 42 | =head1 NAME | ||||||||||||||
| 43 | |||||||||||||||
| 44 | Langertha::Raider::ConnectCheck - Internal check that Net::Async::HTTP can open a connection to a URL | ||||||||||||||
| 45 | |||||||||||||||
| 46 | =head1 VERSION | ||||||||||||||
| 47 | |||||||||||||||
| 48 | version 0.503 | ||||||||||||||
| 49 | |||||||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||||||
| 51 | |||||||||||||||
| 52 | B<Internal module.> Its interface may change without notice. | ||||||||||||||
| 53 | |||||||||||||||
| 54 | L<Net::Async::HTTP> loads some modules only when it opens a connection: | ||||||||||||||
| 55 | L<IO::Async::Internals::Connector> for every connection, L<IO::Async::SSL> | ||||||||||||||
| 56 | (with L<IO::Socket::SSL>, L<Net::SSLeay> and the system's libssl) for https. | ||||||||||||||
| 57 | When such a load dies, Net::Async::HTTP 0.50 keeps the connection slot for | ||||||||||||||
| 58 | that host taken, and every later request to the host waits forever (karr | ||||||||||||||
| 59 | k107). Raider asks this module before it sends, so a missing module is an | ||||||||||||||
| 60 | error with its name instead of a hang. | ||||||||||||||
| 61 | |||||||||||||||
| 62 | =head2 connect_error | ||||||||||||||
| 63 | |||||||||||||||
| 64 | my $error = connect_error('https://api.example.com/v1'); | ||||||||||||||
| 65 | |||||||||||||||
| 66 | Returns C<undef> when the modules a connection to the URL needs load, else | ||||||||||||||
| 67 | a one-line message that names the target (scheme, host and port), the | ||||||||||||||
| 68 | module and the first line of its load error. A URL without a scheme counts | ||||||||||||||
| 69 | as http; a bare scheme (C<https:>) checks what any URL of it needs. | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =head1 SUPPORT | ||||||||||||||
| 72 | |||||||||||||||
| 73 | =head2 Issues | ||||||||||||||
| 74 | |||||||||||||||
| 75 | Please report bugs and feature requests on GitHub at | ||||||||||||||
| 76 | L<https://github.com/Getty/langertha-raider/issues>. | ||||||||||||||
| 77 | |||||||||||||||
| 78 | =head2 IRC | ||||||||||||||
| 79 | |||||||||||||||
| 80 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||
| 81 | |||||||||||||||
| 82 | =head1 CONTRIBUTING | ||||||||||||||
| 83 | |||||||||||||||
| 84 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||
| 85 | |||||||||||||||
| 86 | =head1 AUTHOR | ||||||||||||||
| 87 | |||||||||||||||
| 88 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||||||||||||||
| 89 | |||||||||||||||
| 90 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 91 | |||||||||||||||
| 92 | This software is copyright (c) 2026 by Torsten Raudssus. | ||||||||||||||
| 93 | |||||||||||||||
| 94 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 95 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 96 | |||||||||||||||
| 97 | =cut | ||||||||||||||