| 1 | package Skilletor::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Resolve an add shorthand (owner/repo, a forge link, a URL, a path) to a source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use Skilletor::Entry qw( is_source_name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use Skilletor::Error::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 35 | ▶ | use Skilletor::JSON qw( js_stringify ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 35 | ▶ | use Skilletor::JSString qw( js_lc js_trim js_blank js_ws_re ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 35 | ▶ | use Skilletor::URL qw( parse_url ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 35 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 35 | our @EXPORT_OK = qw( resolve_spec decode_uri_component normalize_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 35 | ▶ | use constant WIN32 => $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # The known forges (never probed), by host, with the name their errors use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 35 | my %FORGES = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'github.com' => 'GitHub', 'gitlab.com' => 'GitLab', 'codeberg.org' => 'Codeberg', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'hf.co' => 'Hugging Face', 'huggingface.co' => 'Hugging Face', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 35 | my $DEFAULT_REPO = 'skills'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 35 | my $FALLBACK_NAME = 'source'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 35 | my $FORMS = 'expected a local path (/path, ./path, ../path, ~/path), scheme://..., transport::address, user@host:path, ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | .'github:owner[/repo], owner[/repo] or host.tld[/path]'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 35 | my $SCHEME = qr/\A[a-z][a-z0-9+.\-]*:(?=\/\/)/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 35 | my $TRANSPORT = qr/\A[A-Za-z][A-Za-z0-9+.\-]*::/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 35 | my $WS = js_ws_re(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 35 | my $NOT_IN_SEGMENT = qr/(?:$WS|\p{Cc}|[:\@])/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 182 | ▶ | sub _fail { Skilletor::Error::Spec->throw( $_[0] ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 450 | ▶ | sub normalize_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 450 | my ( $raw ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 450 | my $s = js_lc($raw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 450 | $s =~ s/\.git\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 450 | $s =~ s/[^a-z0-9-]+/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 450 | $s =~ s/\A-+|-+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 450 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 21 | ▶ | sub _basename { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_basename: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 21 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 21 | my @parts = grep { length } split( WIN32 ? qr{[\\/]} : qr{/}, $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 21 | ▶ | return @parts ? $parts[-1] : $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 563 | ▶ | sub _is_local { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_local: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 563 | my ( $spec ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 563 | ▶ | return 1 if $spec =~ m{\A(?:/|\./|\.\./|~)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 544 | return WIN32 && ( $spec =~ m{\A[A-Za-z]:[\\/]} || $spec =~ m{\A\\\\} || $spec =~ m{\A\.\.?\\} ) ? 1 : 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 544 | ▶ | sub _has_scheme { $_[0] =~ $SCHEME ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_scheme: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 180 | ▶ | sub _lower_scheme { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lower_scheme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 180 | my ( $spec ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 180 | ( my $s = $spec ) =~ s/($SCHEME)/lc $1/e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 180 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 544 | ▶ | sub _helper_address { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_helper_address: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 544 | my ( $spec ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 544 | ▶ | return undef unless $spec =~ /($TRANSPORT)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 22 | my $len = length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 22 | ▶ | return length($spec) > $len ? substr( $spec, $len ) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 245 | ▶ | sub _check_github { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_github: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 245 | my ( $spec, $owner, $repo ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 245 | ▶ | unless ( $owner =~ /\A[A-Za-z0-9-]+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 48 | _fail( 'cannot resolve "'.$spec.'": GitHub owner "'.$owner.'" may only contain ASCII letters, digits and "-"; '.$FORMS ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 197 | ▶ | if ( defined $repo && $repo !~ /\A[A-Za-z0-9._-]+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $repo and not $repo =~ /\A[A-Za-z0-9._-]+\z/
MC/DC100%2/2
defined $repo and not $repo =~ /\A[A-Za-z0-9._-]+\z/
defined $repo
not $repo =~ /\A[A-Za-z0-9._-]+\z/
Truth table100%3/3
A and not(B)
A= defined $repoB= not $repo =~ /\A[A-Za-z0-9._-]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | _fail( 'cannot resolve "'.$spec.'": GitHub repo "'.$repo.'" may only contain ASCII letters, digits, ".", "_" and "-"; '.$FORMS ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 56 | ▶ | sub _check_forge { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_forge: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 56 | my ( $spec, $forge, $owner, $repo ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 56 | for my $pair ( [ owner => $owner ], [ repo => $repo ] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 110 | my ( $what, $seg ) = @$pair; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 110 | ▶ | if ( $seg =~ $NOT_IN_SEGMENT ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | _fail( 'cannot resolve "'.$spec.'": '.$forge.' '.$what.' "'.$seg | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | .'" must not contain whitespace, control characters, ":" or "@"; '.$FORMS ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 517 | ▶ | sub _is_scp_like { $_[0] =~ m{\A[^\@/]+\@[^:/]+:} ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_scp_like: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 180 | ▶ | sub _is_tarball { $_[0] =~ /\.(?:tar\.gz|tgz)\z/i ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_tarball: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 282 | ▶ | sub _repo_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_repo_name: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 282 | my ( $owner, $repo ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 282 | ▶ | my $name = defined $repo ? normalize_name($repo) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 282 | ▶ | return ( length $name && $name ne $DEFAULT_REPO ) ? $name : normalize_name($owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $name and $name ne $DEFAULT_REPO
MC/DC100%2/2
length $name and $name ne $DEFAULT_REPO
length $name
$name ne $DEFAULT_REPO
Truth table100%3/3
A and B
A= length $nameB= $name ne $DEFAULT_REPO
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 118 | ▶ | sub _name_from_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name_from_path: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 118 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 118 | my @segs = grep { length } split m{/}, $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 118 | ▶ | return normalize_name($path) unless @segs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 118 | ▶ | return _repo_name( $segs[0], @segs > 1 ? $segs[-1] : undef ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 155 | ▶ | sub _name_from_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name_from_url: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 155 | my ( $spec, $kind ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 155 | ▶ | if ( _is_scp_like($spec) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | my $path = substr $spec, index( $spec, ':' ) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 11 | ▶ | return _name_from_path($path) if $kind eq 'git'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | my ($first) = split m{/}, $path, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | return normalize_name( _basename( $first // '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$first // ""
MC/DC0%0/1
$first // ""
$first
Truth table50%1/2
A
A= $first
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 144 | my $u = parse_url($spec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 144 | ▶ | return normalize_name($spec) unless $u; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 142 | my @segs = grep { length } split m{/}, $u->{pathname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 142 | ▶ | return _name_from_path( $u->{pathname} ) if $kind eq 'git' && @segs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind eq "git" and @segs
MC/DC100%2/2
$kind eq "git" and @segs
$kind eq "git"
@segs
Truth table100%3/3
A and B
A= $kind eq "git"B= @segs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 40 | return normalize_name( $u->{hostname} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 20 | ▶ | sub _name_from_helper { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name_from_helper: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 20 | my ( $address ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 20 | ▶ | return ( _has_scheme($address) || _is_scp_like($address) ) ? _name_from_url( $address, 'git' ) : _name_from_path($address); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_has_scheme($address) or _is_scp_like($address)
MC/DC100%2/2
_has_scheme($address) or _is_scp_like($address)
_has_scheme($address)
_is_scp_like($address)
Truth table100%3/3
A or B
A= _has_scheme($address)B= _is_scp_like($address)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # decodeURIComponent: %XX runs must be UTF-8 of a scalar value; undef where it throws URIError. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 102 | ▶ | sub decode_uri_component { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_uri_component: called CC=20 SCAR=30.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 102 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 102 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 102 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 102 | my $len = length $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 102 | ▶ | while ( $i < $len ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 444 | my $c = substr $s, $i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 444 | ▶ | if ( $c ne '%' ) { $out .= $c; $i++; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 22 | my $byte = _hex_at( $s, $i ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 22 | ▶ | return undef unless defined $byte; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 17 | $i += 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 17 | ▶ | if ( $byte < 0x80 ) { $out .= chr $byte; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | ▶ | my $n = $byte >= 0xC0 && $byte < 0xE0 ? 2 : $byte >= 0xE0 && $byte < 0xF0 ? 3 : $byte >= 0xF0 && $byte < 0xF8 ? 4 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition55%5/9
$byte >= 192 and $byte < 224
$byte >= 224 and $byte < 240
$byte >= 240 and $byte < 248
MC/DC50%1/2
$byte >= 192 and $byte < 224
$byte >= 192
$byte < 224
MC/DC50%1/2
$byte >= 224 and $byte < 240
$byte >= 224
$byte < 240
MC/DC0%0/2
$byte >= 240 and $byte < 248
$byte >= 240
$byte < 248
Truth table66%2/3
A and B
A= $byte >= 192B= $byte < 224
Truth table66%2/3
A and B
A= $byte >= 224B= $byte < 240
Truth table33%1/3
A and B
A= $byte >= 240B= $byte < 248
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | ▶ | return undef unless $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | my @bytes = ($byte); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | for ( 2 .. $n ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | return undef unless substr( $s, $i, 1 ) eq '%'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | my $cont = _hex_at( $s, $i ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | ▶ | return undef unless defined $cont && ( $cont & 0xC0 ) == 0x80; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cont and ($cont & 192) == 128
MC/DC100%2/2
defined $cont and ($cont & 192) == 128
defined $cont
($cont & 192) == 128
Truth table100%3/3
A and B
A= defined $contB= ($cont & 192) == 128
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | push @bytes, $cont; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | $i += 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | my $copy = pack 'C*', @bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | my $char = eval { Encode::decode( 'UTF-8', $copy, Encode::FB_CROAK() ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | ▶ | return undef unless defined $char && length $char == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $char and length $char == 1
MC/DC50%1/2
defined $char and length $char == 1
defined $char
length $char == 1
Truth table66%2/3
A and B
A= defined $charB= length $char == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my $cp = ord $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | return undef if $cp >= 0xD800 && $cp <= 0xDFFF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cp >= 55296 and $cp <= 57343
MC/DC0%0/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296
$cp <= 57343
Truth table33%1/3
A and B
A= $cp >= 55296B= $cp <= 57343
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | $out .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 91 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 30 | ▶ | sub _hex_at { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hex_at: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 30 | my ( $s, $i ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 30 | my $h = substr $s, $i + 1, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 30 | ▶ | return undef unless length $h == 2 && $h =~ /\A[0-9A-Fa-f]{2}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $h == 2 and $h =~ /\A[0-9A-Fa-f]{2}\z/
MC/DC100%2/2
length $h == 2 and $h =~ /\A[0-9A-Fa-f]{2}\z/
length $h == 2
$h =~ /\A[0-9A-Fa-f]{2}\z/
Truth table100%3/3
A and B
A= length $h == 2B= $h =~ /\A[0-9A-Fa-f]{2}\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 24 | return hex $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 246 | ▶ | sub _forge_link { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_forge_link: called CC=53 SCAR=39.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 246 | my ( $spec, $written, $rest, $explicit ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 246 | my $host = js_lc($written); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 246 | my $forge = $FORGES{$host}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 246 | my ($before) = $rest =~ /\A([^?#]*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 246 | my @segs = grep { length } split m{/}, $before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 246 | ▶ | my $hf = ( $forge eq 'Hugging Face' && @segs && ( $segs[0] eq 'datasets' || $segs[0] eq 'spaces' ) ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$forge eq "Hugging Face" and @segs and $segs[0] eq "datasets" || $segs[0] eq "spaces"
$forge eq "Hugging Face" and @segs
$segs[0] eq "datasets" or $segs[0] eq "spaces"
MC/DC75%3/4
$forge eq "Hugging Face" and @segs and $segs[0] eq "datasets" || $segs[0] eq "spaces"
$forge eq "Hugging Face"
@segs
$segs[0] eq "datasets"
$segs[0] eq "spaces"
Truth table80%4/5
A and B and C or D
A= $forge eq "Hugging Face"B= @segsC= $segs[0] eq "datasets"D= $segs[0] eq "spaces"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 246 | ▶ | my @prefix = $hf ? ( shift @segs ) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 246 | my $owner = $segs[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 246 | ▶ | if ( !defined $owner || js_blank($owner) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $owner or js_blank($owner)
MC/DC100%2/2
not defined $owner or js_blank($owner)
not defined $owner
js_blank($owner)
Truth table100%3/3
not(A) or B
A= not defined $ownerB= js_blank($owner)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | return { kind => 'git', value => $explicit, derivedName => _name_from_url( $explicit, 'git' ) } if defined $explicit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | _fail( 'cannot resolve "'.$spec.'": expected '.$written.'/'.join( '', map { $_.'/' } @prefix ).'owner[/repo]' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 242 | my @tail = grep { !js_blank($_) } @segs[ 1 .. $#segs ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 242 | my ( @repo_path, @view ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 242 | ▶ | if ( $host eq 'gitlab.com' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 35 | my ($dash) = grep { $tail[$_] eq '-' } 0 .. $#tail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 35 | ▶ | if ( defined $dash ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 11 | @repo_path = @tail[ 0 .. $dash - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 11 | @view = @tail[ $dash + 1 .. $#tail ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 24 | @repo_path = @tail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 207 | ▶ | @repo_path = @tail ? ( $tail[0] ) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 207 | @view = @tail[ 1 .. $#tail ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 242 | ▶ | my $repo = @repo_path ? $repo_path[-1] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 242 | ▶ | if ( defined $explicit && !@view ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $explicit and not @view
MC/DC100%2/2
defined $explicit and not @view
defined $explicit
not @view
Truth table100%3/3
A and not(B)
A= defined $explicitB= not @view
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 50 | return { kind => 'git', value => $explicit, derivedName => _name_from_url( $explicit, 'git' ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 192 | ▶ | if ( $host eq 'github.com' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 139 | _check_github( $spec, $owner, $repo ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 53 | ▶ | _check_forge( $spec, $written, $owner, $_ ) for ( @repo_path ? @repo_path : ($DEFAULT_REPO) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 164 | ▶ | my $value = 'https://'.$host.'/'.join( '/', @prefix, $owner, ( @repo_path ? @repo_path : ($DEFAULT_REPO) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 164 | my %resolved = ( kind => 'git', value => $value, derivedName => _repo_name( $owner, $repo ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 164 | ▶ | return \%resolved unless @view; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 91 | ▶ | my $fail = sub { _fail( 'cannot resolve "'.$spec.'": '.$_[0] ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 91 | ▶ | my $page = sub { $fail->( 'a '.$forge.' '.js_stringify( join '/', @view ).' page is not a source; add '.$value ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 93 | ▶ | my $decode = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 93 | my ( $seg ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 93 | my $d = decode_uri_component($seg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 93 | ▶ | $fail->( js_stringify($seg).' in the link is not a valid %-escape' ) unless defined $d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 90 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 91 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 54 | ▶ | my $tree = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 54 | my ( $at ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 54 | ▶ | $fail->( 'a '.$forge.' tree link without a ref; add '.$value ) unless defined $view[$at]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 50 | my %link = ( %resolved, ref => $decode->( $view[$at] ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 48 | my @sub = map { $decode->($_) } @view[ $at + 1 .. $#view ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 47 | ▶ | $link{path} = join '/', @sub if @sub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 47 | return \%link; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 91 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 15 | ▶ | my $pin = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 15 | my ( $at, $what ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 15 | ▶ | unless ( defined $view[$at] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | $fail->( 'a '.$forge.' '.$what.' link without a '.( $what eq 'release' ? 'tag' : 'commit' ).'; add '.$value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 13 | ▶ | $page->() if @view > $at + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 12 | return { %resolved, ref => $decode->( $view[$at] ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 91 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | ▶ | my $file = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | my ( $at, $tree_of ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 7 | my $ref = $view[$at]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | ▶ | my $pinned = defined $ref ? ', or '.$tree_of->($ref).' to pin ref "'.$ref.'"' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | $fail->( 'a '.$forge.' file link; a source is a repository, not a file: add '.$value.$pinned ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 91 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 91 | my ( $v0, $v1 ) = @view; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 91 | ▶ | $v1 //= undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$v1 //= undef
MC/DC100%1/1
$v1 //= undef
$v1
Truth table100%2/2
A
A= $v1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 91 | ▶ | if ( $forge eq 'GitHub' || $forge eq 'Hugging Face' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$forge eq "GitHub" or $forge eq "Hugging Face"
MC/DC100%2/2
$forge eq "GitHub" or $forge eq "Hugging Face"
$forge eq "GitHub"
$forge eq "Hugging Face"
Truth table100%3/3
A or B
A= $forge eq "GitHub"B= $forge eq "Hugging Face"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 69 | ▶ | return $tree->(1) if $v0 eq 'tree'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 26 | ▶ | if ( $v0 eq 'blob' || ( $forge eq 'Hugging Face' && ( $v0 eq 'resolve' || $v0 eq 'raw' ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$v0 eq "blob" or $forge eq "Hugging Face" and $v0 eq "resolve" || $v0 eq "raw"
$forge eq "Hugging Face" and $v0 eq "resolve" || $v0 eq "raw"
$v0 eq "resolve" or $v0 eq "raw"
MC/DC75%3/4
$v0 eq "blob" or $forge eq "Hugging Face" and $v0 eq "resolve" || $v0 eq "raw"
$v0 eq "blob"
$forge eq "Hugging Face"
$v0 eq "resolve"
$v0 eq "raw"
Truth table80%4/5
A or B and C or D
A= $v0 eq "blob"B= $forge eq "Hugging Face"C= $v0 eq "resolve"D= $v0 eq "raw"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | $file->( 1, sub { $value.'/tree/'.$_[0] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 21 | ▶ | return $pin->( 1, 'commit' ) if $v0 eq 'commit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 16 | ▶ | return $pin->( 2, 'release' ) if $forge eq 'GitHub' && $v0 eq 'releases' && defined $v1 && $v1 eq 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$forge eq "GitHub" and $v0 eq "releases" and defined $v1 and $v1 eq "tag"
$forge eq "GitHub" and $v0 eq "releases" and defined $v1
$forge eq "GitHub" and $v0 eq "releases"
MC/DC100%4/4
$forge eq "GitHub" and $v0 eq "releases" and defined $v1 and $v1 eq "tag"
$forge eq "GitHub"
$v0 eq "releases"
defined $v1
$v1 eq "tag"
Truth table100%5/5
A and B and C and D
A= $forge eq "GitHub"B= $v0 eq "releases"C= defined $v1D= $v1 eq "tag"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 11 | $page->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 22 | ▶ | if ( $forge eq 'GitLab' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 11 | ▶ | return $tree->(1) if $v0 eq 'tree'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | ▶ | $file->( 1, sub { $value.'/-/tree/'.$_[0] } ) if $v0 eq 'blob' || $v0 eq 'raw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$v0 eq "blob" or $v0 eq "raw"
MC/DC50%1/2
$v0 eq "blob" or $v0 eq "raw"
$v0 eq "blob"
$v0 eq "raw"
Truth table66%2/3
A or B
A= $v0 eq "blob"B= $v0 eq "raw"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | return $pin->( 1, 'commit' ) if $v0 eq 'commit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | return $pin->( 1, 'release' ) if $v0 eq 'tags' || $v0 eq 'releases'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v0 eq "tags" or $v0 eq "releases"
MC/DC100%2/2
$v0 eq "tags" or $v0 eq "releases"
$v0 eq "tags"
$v0 eq "releases"
Truth table100%3/3
A or B
A= $v0 eq "tags"B= $v0 eq "releases"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | $page->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Codeberg (Forgejo): src|raw|media/branch|tag|commit/<ref> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 11 | my %kinds = map { $_ => 1 } qw( branch tag commit ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 11 | ▶ | return $tree->(2) if $v0 eq 'src' && defined $v1 && $kinds{$v1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$v0 eq "src" and defined $v1 and $kinds{$v1}
$v0 eq "src" and defined $v1
MC/DC66%2/3
$v0 eq "src" and defined $v1 and $kinds{$v1}
$v0 eq "src"
defined $v1
$kinds{$v1}
Truth table75%3/4
A and B and C
A= $v0 eq "src"B= defined $v1C= $kinds{$v1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 5 | ▶ | $fail->( 'a '.$forge.' tree link without a ref; add '.$value ) if $v0 eq 'src' && !defined $v1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$v0 eq "src" and not defined $v1
MC/DC0%0/2
$v0 eq "src" and not defined $v1
$v0 eq "src"
not defined $v1
Truth table66%2/3
A and not(B)
A= $v0 eq "src"B= not defined $v1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 5 | ▶ | if ( ( $v0 eq 'raw' || $v0 eq 'media' ) && defined $v1 && $kinds{$v1} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$v0 eq "raw" || $v0 eq "media" and defined $v1 and $kinds{$v1}
$v0 eq "raw" || $v0 eq "media" and defined $v1
$v0 eq "raw" or $v0 eq "media"
MC/DC25%1/4
$v0 eq "raw" || $v0 eq "media" and defined $v1 and $kinds{$v1}
$v0 eq "raw"
$v0 eq "media"
defined $v1
$kinds{$v1}
Truth table28%2/7
A or B and C and D
A= $v0 eq "raw"B= $v0 eq "media"C= defined $v1D= $kinds{$v1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | $file->( 2, sub { $value.'/src/'.$v1.'/'.$_[0] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | ▶ | return $pin->( 1, 'commit' ) if $v0 eq 'commit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | return $pin->( 2, 'release' ) if $v0 eq 'releases' && defined $v1 && $v1 eq 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$v0 eq "releases" and defined $v1 and $v1 eq "tag"
$v0 eq "releases" and defined $v1
MC/DC33%1/3
$v0 eq "releases" and defined $v1 and $v1 eq "tag"
$v0 eq "releases"
defined $v1
$v1 eq "tag"
Truth table50%2/4
A and B and C
A= $v0 eq "releases"B= defined $v1C= $v1 eq "tag"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | $page->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 575 | ▶ | sub resolve_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_spec: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 575 | my ( $spec, $probe ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 575 | my $r = _resolve_address( $spec, $probe ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 392 | ▶ | return is_source_name( $r->{derivedName} ) ? $r : { %$r, derivedName => $FALLBACK_NAME }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 575 | ▶ | sub _resolve_address { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_address: called CC=25 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 575 | my ( $spec, $probe ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 575 | my $s = js_trim($spec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # An empty spec would be a bare word; an address kept verbatim must not reach git as an option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 575 | ▶ | _fail( 'cannot resolve "'.$spec.'": empty source; '.$FORMS ) if $s eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 571 | ▶ | _fail( 'cannot resolve "'.$spec.'": a source must not start with "-"' ) if $s =~ /\A-/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # 1. Local paths. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 563 | ▶ | return { kind => 'local', value => $s, derivedName => normalize_name( _basename($s) ) } if _is_local($s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # 2. Explicit URLs, scp-like and transport::address forms: kept verbatim, but a lower-case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # scheme; an https:// link to a known forge reads as in 4. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 544 | my $address = _helper_address($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 544 | ▶ | return { kind => 'git', value => $s, derivedName => _name_from_helper($address) } if defined $address; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 524 | ▶ | if ( _has_scheme($s) || _is_scp_like($s) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_has_scheme($s) or _is_scp_like($s)
MC/DC100%2/2
_has_scheme($s) or _is_scp_like($s)
_has_scheme($s)
_is_scp_like($s)
Truth table100%3/3
A or B
A= _has_scheme($s)B= _is_scp_like($s)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 180 | my $value = _lower_scheme($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 180 | ▶ | my $kind = _is_tarball($value) ? 'url' : 'git'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 180 | ▶ | if ( $kind eq 'git' && $value =~ m{\A(https://([^/?#]+)/)} && exists $FORGES{ js_lc($2) } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$kind eq "git" and $value =~ m[\A(https://([^/?#]+)/)] and exists $FORGES{js_lc($2)}
$kind eq "git" and $value =~ m[\A(https://([^/?#]+)/)]
MC/DC100%3/3
$kind eq "git" and $value =~ m[\A(https://([^/?#]+)/)] and exists $FORGES{js_lc($2)}
$kind eq "git"
$value =~ m[\A(https://([^/?#]+)/)]
exists $FORGES{js_lc($2)}
Truth table100%4/4
A and B and C
A= $kind eq "git"B= $value =~ m[\A(https://([^/?#]+)/)]C= exists $FORGES{js_lc($2)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 88 | my ( $whole, $host ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 88 | my ($explicit) = $value =~ /\A([^?#]*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 88 | return _forge_link( $spec, $host, substr( $value, length $whole ), $explicit ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 92 | return { kind => $kind, value => $value, derivedName => _name_from_url( $value, $kind ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # 3. github:owner/repo, in any case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 344 | ▶ | if ( $s =~ /\Agithub:/i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 33 | my $path = substr $s, length 'github:'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 33 | my ($first) = $path =~ m{\A([^/?#]*)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 33 | ▶ | _fail( 'cannot resolve "'.$spec.'": expected github:owner[/repo]' ) if js_blank($first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 26 | return _forge_link( $spec, 'github.com', $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 311 | my $slash = index $s, '/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 311 | ▶ | my $first_seg = $slash == -1 ? $s : substr( $s, 0, $slash ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 311 | ▶ | my $rest = $slash == -1 ? '' : substr( $s, $slash + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # 4. A known forge with an owner (never probed). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 311 | ▶ | return _forge_link( $spec, $first_seg, $rest ) if exists $FORGES{ js_lc($first_seg) } && $slash != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $FORGES{js_lc($first_seg)} and $slash != -1
MC/DC100%2/2
exists $FORGES{js_lc($first_seg)} and $slash != -1
exists $FORGES{js_lc($first_seg)}
$slash != -1
Truth table100%3/3
A and B
A= exists $FORGES{js_lc($first_seg)}B= $slash != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # 5. and 6. take a first segment without a dot as a GitHub owner, which has no colon. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 224 | my $colon = index $first_seg, ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 224 | ▶ | if ( $colon != -1 && index( $first_seg, '.' ) == -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$colon != -1 and index($first_seg, ".") == -1
MC/DC100%2/2
$colon != -1 and index($first_seg, ".") == -1
$colon != -1
index($first_seg, ".") == -1
Truth table100%3/3
A and B
A= $colon != -1B= index($first_seg, ".") == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 43 | _fail( 'cannot resolve "'.$spec.'": unknown prefix "'.substr( $first_seg, 0, $colon + 1 ).'"; '.$FORMS ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # 5. and 7. take a colon after a dotted host as its port, a number. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 181 | my $host_port = substr $first_seg, rindex( $first_seg, '@' ) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 181 | my $port_at = index $host_port, ':'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 181 | ▶ | if ( $port_at != -1 && substr( $host_port, $port_at + 1 ) !~ /\A[0-9]+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$port_at != -1 and not substr($host_port, $port_at + 1) =~ /\A[0-9]+\z/
MC/DC100%2/2
$port_at != -1 and not substr($host_port, $port_at + 1) =~ /\A[0-9]+\z/
$port_at != -1
not substr($host_port, $port_at + 1) =~ /\A[0-9]+\z/
Truth table100%3/3
A and not(B)
A= $port_at != -1B= not substr($host_port, $port_at + 1) =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 6 | _fail( 'cannot resolve "'.$spec.'": port "'.substr( $host_port, $port_at + 1 ).'" of ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | .substr( $host_port, 0, $port_at ).' is not a number; '.$FORMS ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # 5. A single token. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 175 | ▶ | if ( $slash == -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 120 | ▶ | if ( index( $first_seg, '.' ) == -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 106 | _check_github( $spec, $first_seg, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 74 | return { kind => 'git', value => 'https://github.com/'.$first_seg.'/'.$DEFAULT_REPO, derivedName => normalize_name($first_seg) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 14 | return _probe_generic( 'https://'.$first_seg.'/'.$DEFAULT_REPO, $first_seg, $spec, $probe ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # 6. owner/repo, the first segment without a dot: GitHub, read as a github.com link. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 55 | ▶ | return _forge_link( $spec, 'github.com', $s ) if index( $first_seg, '.' ) == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # 7. host.tld[/path]: a generic host, probed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 10 | ( my $path = $rest ) =~ s{/+\z}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 10 | ▶ | my $base = length $path ? 'https://'.$first_seg.'/'.$path : 'https://'.$first_seg.'/'.$DEFAULT_REPO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 10 | return _probe_generic( $base, $first_seg, $spec, $probe ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 24 | ▶ | sub _probe_generic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_probe_generic: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 24 | my ( $base, $host, $original, $probe ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 24 | ▶ | my $result = $probe->($base) // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
&$probe($base) // {}
MC/DC0%0/1
&$probe($base) // {}
&$probe($base)
Truth table50%1/2
A
A= &$probe($base)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 23 | ▶ | return { kind => 'git', value => $base, derivedName => normalize_name($host) } if $result->{git}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 20 | ▶ | return { kind => 'url', value => $base.'.tar.gz', derivedName => normalize_name($host) } if $result->{tarball}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 18 | _fail( 'cannot resolve "'.$original.'": neither '.$base.' (git) nor '.$base.'.tar.gz (tarball) responded' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 35 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||