« /usr/local/lib/perl5/site_perl/5.44.0/Moo/sification.pm
↑ Summary
/usr/local/lib/perl5/5.44.0/x86_64-linux/mro.pm »
| 1 | package Skilletor::Probe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The probe of `skilletor add` for a generic host – git ls-remote, then a HEAD on the tarball | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 108 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 108 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 108 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 108 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 108 | ▶ | use Skilletor::FSUtil qw( encode_text ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 108 | ▶ | use Skilletor::GitEnv qw( git_env ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 108 | ▶ | use Skilletor::Process qw( run_command ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 108 | ▶ | use Skilletor::URL qw( parse_url ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 108 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 108 | our @EXPORT_OK = qw( make_probe ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 108 | ▶ | use constant TIMEOUT_MS => 5_000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # The headers Node's fetch sends with a HEAD (as Skilletor::Source::Url's requests carry them), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # so a host answers the probe as it answers the reference's. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 108 | my %FETCH_HEADERS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | accept => '*/*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'accept-language' => '*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 'sec-fetch-mode' => 'cors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'accept-encoding' => 'gzip, deflate', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 15 | ▶ | sub make_probe { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_probe: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | my ( %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 15 | ▶ | my $timeout_ms = $args{timeout_ms} // TIMEOUT_MS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"timeout_ms"} // 5000
MC/DC100%1/1
$args{"timeout_ms"} // 5000
$args{"timeout_ms"}
Truth table100%2/2
A
A= $args{"timeout_ms"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | my $http = $args{http} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 15 | ▶ | // HTTP::Tiny->new( agent => 'node', timeout => $timeout_ms / 1000, verify_SSL => 1, max_redirect => 20 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"http"} // "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
MC/DC0%0/2
$args{"http"} // "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
$args{"http"}
"HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
Truth table33%1/3
A // B
A= $args{"http"}B= "HTTP::Tiny"->new("agent", "node", "timeout", $timeout_ms / 1000, "verify_SSL", 1, "max_redirect", 20)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 80 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 80 | my ( $base ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 80 | ▶ | return { git => 1 } if _ls_remote( $base, $timeout_ms ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 57 | ▶ | return { tarball => 1 } if _head_ok( $http, $base.'.tar.gz' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 37 | return {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Does git list the address's refs within the timeout? The address goes after `--`, never an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # option (k85); git runs in git's environment, never steered by an exported GIT_DIR (k91). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 80 | ▶ | sub _ls_remote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ls_remote: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 80 | my ( $url, $timeout_ms ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 80 | my $r = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 80 | run_command( cmd => [ 'git', 'ls-remote', '--', encode_text($url) ], env => git_env(), timeout_ms => $timeout_ms ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 69 | ▶ | return $r && !$r->{timed_out} && !$r->{spawn_error} && defined $r->{code} && $r->{code} == 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%10/12
$r and not $r->{"timed_out"} and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0
$r and not $r->{"timed_out"} and not $r->{"spawn_error"} and defined $r->{"code"}
$r and not $r->{"timed_out"} and not $r->{"spawn_error"}
$r and not $r->{"timed_out"}
MC/DC60%3/5
$r and not $r->{"timed_out"} and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0
$r
not $r->{"timed_out"}
not $r->{"spawn_error"}
defined $r->{"code"}
$r->{"code"} == 0
Truth table66%4/6
A and not(B) and not(C) and D and E
A= $rB= not $r->{"timed_out"}C= not $r->{"spawn_error"}D= defined $r->{"code"}E= $r->{"code"} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Does a HEAD on the URL answer 2xx, redirects followed? What fetch refuses to send – no URL to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # `new URL`, another scheme than http(s), credentials in the URL – is no answer; the URL goes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # out as fetch sends it (the host IDNA-encoded, the path percent-encoded, no fragment). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 57 | ▶ | sub _head_ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_head_ok: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 57 | my ( $http, $url ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 57 | my $u = parse_url($url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 57 | ▶ | return 0 unless $u && $u->{protocol} =~ /\Ahttps?:\z/ && $u->{username} eq '' && $u->{password} eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq "" and $u->{"password"} eq ""
$u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq ""
$u and $u->{"protocol"} =~ /\Ahttps?:\z/
MC/DC75%3/4
$u and $u->{"protocol"} =~ /\Ahttps?:\z/ and $u->{"username"} eq "" and $u->{"password"} eq ""
$u
$u->{"protocol"} =~ /\Ahttps?:\z/
$u->{"username"} eq ""
$u->{"password"} eq ""
Truth table80%4/5
A and B and C and D
A= $uB= $u->{"protocol"} =~ /\Ahttps?:\z/C= $u->{"username"} eq ""D= $u->{"password"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 36 | ▶ | my $href = $u->{protocol}.'//'.$u->{hostname}.( length $u->{port} ? ':'.$u->{port} : '' ).$u->{pathname}.$u->{search}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 36 | my $res = eval { $http->request( 'HEAD', encode_text($href), { headers => {%FETCH_HEADERS} } ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 36 | ▶ | return $res && $res->{success} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$res and $res->{"success"}
MC/DC50%1/2
$res and $res->{"success"}
$res
$res->{"success"}
Truth table66%2/3
A and B
A= $resB= $res->{"success"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 108 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||