| 1 | package PDL::ML::Hub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $VERSION = '0.012'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=20.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $cache_dir = $args{cache_dir} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | || $ENV{PDL_ML_HUB_CACHE} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | || File::Spec->catdir($ENV{XDG_CACHE_HOME} || File::Spec->catdir($ENV{HOME} || '/tmp', '.cache'), 'pdl-ml-hub'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition54%6/11
$args{'cache_dir'} || $ENV{'PDL_ML_HUB_CACHE'} || 'File::Spec'->catdir($ENV{'XDG_CACHE_HOME'} || 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache'), 'pdl-ml-hub')
$args{"cache_dir"} or $ENV{"PDL_ML_HUB_CACHE"}
$ENV{'XDG_CACHE_HOME'} || 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache')
$ENV{'HOME'} || '/tmp'
MC/DC0%0/3
$args{'cache_dir'} || $ENV{'PDL_ML_HUB_CACHE'} || 'File::Spec'->catdir($ENV{'XDG_CACHE_HOME'} || 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache'), 'pdl-ml-hub')
$args{"cache_dir"}
$ENV{"PDL_ML_HUB_CACHE"}
'File::Spec'->catdir($ENV{'XDG_CACHE_HOME'} || 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache'), 'pdl-ml-hub')
MC/DC0%0/2
$ENV{'XDG_CACHE_HOME'} || 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache')
$ENV{'XDG_CACHE_HOME'}
'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache')
MC/DC0%0/1
$ENV{'HOME'} || '/tmp'
$ENV{'HOME'}
Truth table50%2/4
A or B || C
A= $args{"cache_dir"}B= $ENV{"PDL_ML_HUB_CACHE"}C= 'File::Spec'->catdir($ENV{'XDG_CACHE_HOME'} || 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache'), 'pdl-ml-hub')
Truth table33%1/3
A || B
A= $ENV{'XDG_CACHE_HOME'}B= 'File::Spec'->catdir($ENV{'HOME'} || '/tmp', '.cache')
Truth table50%1/2
A
A= $ENV{'HOME'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | cache_dir => $cache_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | http => $args{http} || HTTP::Tiny->new(agent => "PDL-ML-Hub/$VERSION"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'http'} || 'HTTP::Tiny'->new('agent', "PDL-ML-Hub/$PDL::ML::Hub::VERSION")
MC/DC0%0/2
$args{'http'} || 'HTTP::Tiny'->new('agent', "PDL-ML-Hub/$PDL::ML::Hub::VERSION")
$args{'http'}
'HTTP::Tiny'->new('agent', "PDL-ML-Hub/$PDL::ML::Hub::VERSION")
Truth table66%2/3
A || B
A= $args{'http'}B= 'HTTP::Tiny'->new('agent', "PDL-ML-Hub/$PDL::ML::Hub::VERSION")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub cache_dir { $_[0]->{cache_dir} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub parse_uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_uri: called CC=10 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | my ($self, $uri) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | croak 'URI required' unless defined $uri && length $uri; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $uri and length $uri
MC/DC0%0/2
defined $uri and length $uri
defined $uri
length $uri
Truth table33%1/3
A and B
A= defined $uriB= length $uri
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | if ($uri =~ m{^kaggle://([^/]+)/([^/]+)/([^/]+)/([^/]+)(?:/(.+))?$}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | return { provider => 'kaggle', owner => $1, model => $2, framework => $3, variation => $4, file => $5 || '' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$5 || ''
MC/DC0%0/1
$5 || ''
$5
Truth table50%1/2
A
A= $5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | if ($uri =~ m{^gs://([^/]+)/(.+)$}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | return { provider => 'gcs', bucket => $1, object => $2 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if ($uri =~ m{^hf://([^/]+/[^/]+?)(?:\@([^/]+))?/(.+)$}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | return { provider => 'huggingface', repo => $1, revision => $2 || 'main', file => $3 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$2 || 'main'
MC/DC0%0/1
$2 || 'main'
$2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($uri =~ m{^oci://([^/]+)/(.+)$}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return { provider => 'oci', registry => $1, ref => $2 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($uri =~ m{^https?://}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return { provider => 'http', url => $uri }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | croak "Unsupported model hub URI: $uri"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub resolve_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_url: called CC=7 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | my ($self, $uri) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | my $p = ref($uri) eq 'HASH' ? $uri : $self->parse_uri($uri); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | if ($p->{provider} eq 'kaggle') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $base = "https://www.kaggle.com/api/v1/models/$p->{owner}/$p->{model}/$p->{framework}/$p->{variation}/1/download"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | return $p->{file} ? "$base/$p->{file}" : $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if ($p->{provider} eq 'gcs') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | return "https://storage.googleapis.com/$p->{bucket}/$p->{object}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if ($p->{provider} eq 'huggingface') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | return "https://huggingface.co/$p->{repo}/resolve/$p->{revision}/$p->{file}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($p->{provider} eq 'http') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $p->{url}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | croak "resolve_url not supported directly for provider '$p->{provider}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub auth_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auth_headers: called CC=8 SCAR=30.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my ($self, $provider) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if ($provider eq 'kaggle' && $ENV{KAGGLE_USERNAME} && $ENV{KAGGLE_KEY}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%2/6
$provider eq "kaggle" and $ENV{"KAGGLE_USERNAME"} and $ENV{"KAGGLE_KEY"}
$provider eq "kaggle" and $ENV{"KAGGLE_USERNAME"}
MC/DC0%0/3
$provider eq "kaggle" and $ENV{"KAGGLE_USERNAME"} and $ENV{"KAGGLE_KEY"}
$provider eq "kaggle"
$ENV{"KAGGLE_USERNAME"}
$ENV{"KAGGLE_KEY"}
Truth table25%1/4
A and B and C
A= $provider eq "kaggle"B= $ENV{"KAGGLE_USERNAME"}C= $ENV{"KAGGLE_KEY"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $tok = encode_base64("$ENV{KAGGLE_USERNAME}:$ENV{KAGGLE_KEY}", ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $h{Authorization} = "Basic $tok"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ▶ | } elsif ($provider eq 'huggingface' && $ENV{HF_TOKEN}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$provider eq "huggingface" and $ENV{"HF_TOKEN"}
MC/DC0%0/2
$provider eq "huggingface" and $ENV{"HF_TOKEN"}
$provider eq "huggingface"
$ENV{"HF_TOKEN"}
Truth table33%1/3
A and B
A= $provider eq "huggingface"B= $ENV{"HF_TOKEN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $h{Authorization} = "Bearer $ENV{HF_TOKEN}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ▶ | } elsif ($provider eq 'gcs' && $ENV{GCS_ACCESS_TOKEN}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$provider eq "gcs" and $ENV{"GCS_ACCESS_TOKEN"}
MC/DC0%0/2
$provider eq "gcs" and $ENV{"GCS_ACCESS_TOKEN"}
$provider eq "gcs"
$ENV{"GCS_ACCESS_TOKEN"}
Truth table33%1/3
A and B
A= $provider eq "gcs"B= $ENV{"GCS_ACCESS_TOKEN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $h{Authorization} = "Bearer $ENV{GCS_ACCESS_TOKEN}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | return \%h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | ▶ | sub _validate_segment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_segment: called CC=8 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my ($seg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | croak 'Invalid empty path segment in model hub URI' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $seg and length $seg
MC/DC0%0/2
defined $seg and length $seg
defined $seg
length $seg
Truth table33%1/3
A and B
A= defined $segB= length $seg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if !defined $seg || !length $seg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | croak 'Invalid path segment containing NUL or backslash' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | if $seg =~ /[\0\\]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | croak "Path traversal segment '$seg' not allowed in model hub URI" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$seg eq "." or $seg eq ".." or $seg =~ m[^/]u or $seg =~ /^[A-Za-z]:/u
$seg eq "." or $seg eq ".." or $seg =~ m[^/]u
$seg eq "." or $seg eq ".."
MC/DC0%0/4
$seg eq "." or $seg eq ".." or $seg =~ m[^/]u or $seg =~ /^[A-Za-z]:/u
$seg eq "."
$seg eq ".."
$seg =~ m[^/]u
$seg =~ /^[A-Za-z]:/u
Truth table20%1/5
A or B or C or D
A= $seg eq "."B= $seg eq ".."C= $seg =~ m[^/]uD= $seg =~ /^[A-Za-z]:/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | if $seg eq '.' || $seg eq '..' || $seg =~ m{^/} || $seg =~ m{^[A-Za-z]:}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | return $seg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub cache_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_path: called CC=10 SCAR=36.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my ($self, $uri) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | my $p = ref($uri) eq 'HASH' ? $uri : $self->parse_uri($uri); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | ▶ | if ($p->{provider} eq 'kaggle') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my @file_parts = length($p->{file}) ? split(m{/}, $p->{file}, -1) : ('archive.tar.gz'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | @parts = ('kaggle', $p->{owner}, $p->{model}, $p->{framework}, $p->{variation}, @file_parts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } elsif ($p->{provider} eq 'gcs') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | @parts = ('gcs', $p->{bucket}, split(m{/}, $p->{object}, -1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } elsif ($p->{provider} eq 'huggingface') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | @parts = ('hf', split(m{/}, $p->{repo}, -1), $p->{revision}, split(m{/}, $p->{file}, -1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $raw = ref($uri) eq 'HASH' ? ($p->{url} // '') : $uri; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$p->{"url"} // ""
MC/DC0%0/1
$p->{"url"} // ""
$p->{"url"}
Truth table0%0/2
A
A= $p->{"url"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | (my $safe = $raw) =~ s{[^A-Za-z0-9._-]+}{_}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | @parts = ('http', $safe || 'download'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$safe || 'download'
MC/DC0%0/1
$safe || 'download'
$safe
Truth table0%0/2
A
A= $safe
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | _validate_segment($_) for @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | return File::Spec->catfile($self->{cache_dir}, @parts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=11 SCAR=28.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my ($self, $uri, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my $parsed = $self->parse_uri($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | my $dest = $opts{dest} || $self->cache_path($parsed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'dest'} || $self->cache_path($parsed)
MC/DC0%0/2
$opts{'dest'} || $self->cache_path($parsed)
$opts{'dest'}
$self->cache_path($parsed)
Truth table33%1/3
A || B
A= $opts{'dest'}B= $self->cache_path($parsed)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | return $dest if -f $dest && !$opts{force}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $dest and not $opts{"force"}
MC/DC0%0/2
-f $dest and not $opts{"force"}
-f $dest
not $opts{"force"}
Truth table33%1/3
A and not(B)
A= -f $destB= not $opts{"force"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my $dest_dir = dirname($dest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | make_path($dest_dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | if (!$opts{dest}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | make_path($self->{cache_dir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my $abs_cache = abs_path($self->{cache_dir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | my $abs_dir = abs_path($dest_dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | croak "Resolved cache path '$abs_dir' escapes cache_dir '$abs_cache'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%4/12
defined $abs_cache and defined $abs_dir and $abs_dir eq $abs_cache || index($abs_dir, "$abs_cache/") == 0 || index($abs_dir, "$abs_cache\\") == 0
defined $abs_cache and defined $abs_dir
$abs_dir eq $abs_cache or index($abs_dir, "$abs_cache/") == 0 or index($abs_dir, "$abs_cache\\") == 0
$abs_dir eq $abs_cache or index($abs_dir, "$abs_cache/") == 0
MC/DC0%0/5
defined $abs_cache and defined $abs_dir and $abs_dir eq $abs_cache || index($abs_dir, "$abs_cache/") == 0 || index($abs_dir, "$abs_cache\\") == 0
defined $abs_cache
defined $abs_dir
$abs_dir eq $abs_cache
index($abs_dir, "$abs_cache/") == 0
index($abs_dir, "$abs_cache\\") == 0
Truth table16%1/6
A and B and C or D or E
A= defined $abs_cacheB= defined $abs_dirC= $abs_dir eq $abs_cacheD= index($abs_dir, "$abs_cache/") == 0E= index($abs_dir, "$abs_cache\\") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | unless defined $abs_cache && defined $abs_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | && ($abs_dir eq $abs_cache || index($abs_dir, "$abs_cache/") == 0 || index($abs_dir, "$abs_cache\\") == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $url = $self->resolve_url($parsed); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my $headers = $self->auth_headers($parsed->{provider}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my $res = $self->{http}->mirror($url, $dest, { headers => $headers }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | croak "Failed to fetch $uri ($url): $res->{status} $res->{reason}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | unless $res->{success}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | return $dest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||