| 1 | package URI::PackageURL::Type; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use feature ':5.10'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use JSON::PP qw(decode_json); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use constant DEBUG => $ENV{PURL_DEBUG}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | our $VERSION = '2.26'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | my %DEFINITION_CACHE = (); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | my %ALGO_LENGTH = ('md5' => 32, 'sha1' => 40, 'sha256' => 64, 'sha384' => 96, 'sha512' => 128); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | my %CACHE = (); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2538 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 2538 | my ($class, $type, $definition) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2538 | ▶ | Carp::croak 'Missing PURL type' unless $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2538 | $type = lc $type; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2538 | ▶ | $definition = $DEFINITION_CACHE{$type} //= _load_definition($type); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$DEFINITION_CACHE{$type} //= _load_definition($type)
MC/DC100%2/2
$DEFINITION_CACHE{$type} //= _load_definition($type)
$DEFINITION_CACHE{$type}
_load_definition($type)
Truth table100%3/3
A //= B
A= $DEFINITION_CACHE{$type}B= _load_definition($type)
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2538 | ▶ | my $self = {type => $type, definition => $definition || {}}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$definition || {}
MC/DC100%1/1
$definition || {}
$definition
Truth table100%2/2
A
A= $definition
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2538 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 114 | ▶ | sub definition_dir { File::Spec->catfile(dirname(__FILE__), 'types') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
definition_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 114 | ▶ | sub _file_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_file_content: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 114 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 114 | ▶ | return unless -e $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 113 | ▶ | open my $fh, '<', $path or Carp::croak "Can't open file: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 113 | my $content = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 113 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 113 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 114 | ▶ | sub _load_definition { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_definition: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 114 | my $purl_type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 114 | ▶ | return $CACHE{$purl_type} if defined $CACHE{$purl_type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 114 | my $content = _file_content(File::Spec->catfile(definition_dir, "$purl_type-definition.json")); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 114 | ▶ | return unless $content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 113 | DEBUG and say STDERR "-- Loaded '$purl_type' definition schema"; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 113 | my $data = eval { decode_json($content) }; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 113 | ▶ | Carp::croak "Failed to decode '$purl_type' PURL type definition: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 113 | $CACHE{$purl_type} = $data; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 113 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 23660 | ▶ | sub definition { shift->{definition} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
definition: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 22116 | ▶ | sub _property { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_property: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 22116 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 22116 | my @filter = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 22116 | my $definition = $self->definition; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 22116 | ▶ | return unless $definition; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 22116 | foreach (@filter) { | |||||||||||||||||||||||||||||||||||||||||
| 85 | 36470 | ▶ | $definition = (defined $definition->{$_}) ? $definition->{$_} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 22116 | return $definition; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub schema_id { shift->_property('$id') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub type_name { shift->_property('type_name') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub description { shift->_property('description') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1859 | ▶ | sub default_repository_url { shift->_property('repository', 'default_repository_url') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_repository_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub examples { shift->_property('examples') || [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
examples: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub repository { shift->_property('repository') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
repository: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub note { shift->_property('note') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
note: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub reference_urls { shift->_property('reference_urls') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reference_urls: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub namespace_definition { shift->component_definition('namespace') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namespace_definition: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub name_definition { shift->component_definition('name') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_definition: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub version_definition { shift->component_definition('version') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version_definition: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1511 | ▶ | sub qualifiers_definition { shift->component_definition('qualifiers') || [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qualifiers_definition: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub subpath_definition { shift->component_definition('subpath') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subpath_definition: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 6251 | ▶ | sub component_have_definition { defined shift->component_definition(shift) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_have_definition: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 7762 | ▶ | sub component_definition { shift->_property(shift . '_definition') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_definition: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub component_case_sensitive { shift->_property(shift . '_definition', 'case_sensitive') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_case_sensitive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub component_is_case_sensitive { shift->component_case_sensitive(shift) == 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_is_case_sensitive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub component_is_optional { shift->component_requirement(shift) eq 'optional' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_is_optional: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 3219 | ▶ | sub component_is_prohibited { shift->component_requirement(shift) eq 'prohibited' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_is_prohibited: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1357 | ▶ | sub component_is_required { shift->component_requirement(shift) eq 'required' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_is_required: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub component_native_name { shift->_property(shift . '_definition', 'native_name') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_native_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub component_normalization_rules { shift->_property(shift . '_definition', 'normalization_rules') || [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_normalization_rules: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub component_note { shift->_property(shift . '_definition', 'note') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_note: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 3215 | ▶ | sub component_permitted_characters { shift->_property(shift . '_definition', 'permitted_characters') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_permitted_characters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 9303 | ▶ | sub component_requirement { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
component_requirement: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 9303 | my ($self, $component) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 9303 | ▶ | if ($component eq 'qualifiers') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 23 | foreach (@{$self->qualifiers_definition}) { | |||||||||||||||||||||||||||||||||||||||||
| 125 | 46 | my $requirement = $_->{requirement}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 46 | ▶ | next unless $requirement; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 28 | ▶ | return 'required' if ($requirement eq 'required'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 21 | return 'optional'; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 9280 | return $self->_property($component . '_definition', 'requirement'); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2469 | ▶ | sub normalize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize: called CC=19 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2469 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 2469 | my %components = ( | |||||||||||||||||||||||||||||||||||||||||
| 141 | type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | namespace => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | name => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | version => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | version => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | qualifiers => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | subpath => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # Common normalizations | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 2469 | $components{type} = lc $components{type}; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2469 | ▶ | if (grep { $_ eq $components{type} } qw(alpm apk bitbucket composer deb github gitlab hex npm oci pypi)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 127 | $components{name} = lc $components{name}; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 2469 | ▶ | if (defined $components{namespace}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 310 | ▶ | if (grep { $_ eq $components{type} } qw(alpm apk bitbucket composer deb github gitlab golang hex rpm)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 98 | $components{namespace} = lc $components{namespace}; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # Legacy CPAN spec: The namespace is the CPAN id of the author/publisher. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # It MUST be written uppercase and is required. | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 310 | ▶ | if ($components{type} eq 'cpan') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 34 | $components{namespace} = uc $components{namespace}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | # Force checksum into ARRAY | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 2469 | ▶ | if (defined $components{qualifiers}->{checksum} and ref $components{qualifiers}->{checksum} ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $components{"qualifiers"}{"checksum"} and ref $components{"qualifiers"}{"checksum"} ne "ARRAY"
MC/DC100%2/2
defined $components{"qualifiers"}{"checksum"} and ref $components{"qualifiers"}{"checksum"} ne "ARRAY"
defined $components{"qualifiers"}{"checksum"}
ref $components{"qualifiers"}{"checksum"} ne "ARRAY"
Truth table100%3/3
A and B
A= defined $components{"qualifiers"}{"checksum"}B= ref $components{"qualifiers"}{"checksum"} ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | $components{qualifiers}->{checksum} = [$components{qualifiers}->{checksum}]; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | # Force qualifier keys to lowercase | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 2469 | %{$components{qualifiers}} = map { lc $_ => $components{qualifiers}->{$_} } keys %{$components{qualifiers}}; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | # PURL type specific normalization | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 2469 | TYPE: for ($components{type}) { | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2469 | ▶ | if (/huggingface/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | # The version is the model revision Git commit hash. It is case insensitive and | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # must be lowercased in the package URL. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 18 | $components{version} = lc $components{version}; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 18 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 2451 | ▶ | if (/mlflow/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # The "name" case sensitivity depends on the server implementation: | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # - Azure ML: it is case sensitive and must be kept as-is in the package URL. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # - Databricks: it is case insensitive and must be lowercased in the package URL. | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 18 | ▶ | last TYPE unless $components{qualifiers}->{repository_url}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 18 | ▶ | if ($components{qualifiers}->{repository_url} =~ /azuredatabricks/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 11 | $components{name} = lc $components{name}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 18 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 2433 | ▶ | if (/pypi/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | # A PyPI package name must be lowercased and underscore "_" replaced with a dash "-". | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 18 | $components{name} =~ s/_/-/g; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 18 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 2415 | ▶ | if (/cpan/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 1931 | ▶ | if (defined $components{qualifiers}->{author}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # CPAN ID. It MUST be written uppercase. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 1892 | $components{qualifiers}->{author} = uc $components{qualifiers}->{author}; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 1931 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 484 | ▶ | if (/brew/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # namespace and name: It is not case sensitive and must be lowercased. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 25 | ▶ | $components{namespace} = lc($components{namespace}) if (defined $components{namespace}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 25 | $components{name} = lc($components{name}); | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 25 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 459 | ▶ | if (/git/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 20 | $components{namespace} = lc($components{namespace}); | |||||||||||||||||||||||||||||||||||||||||
| 236 | 20 | $components{name} = lc($components{name}); | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 20 | my @parts = split '/', $components{namespace}, 2; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 20 | $components{namespace} = join '/', shift @parts; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 20 | $components{name} = join '/', @parts, $components{name}; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 20 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 2469 | ▶ | return wantarray ? %components : \%components; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 1592 | ▶ | sub validate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=50 SCAR=45.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 1592 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 1592 | my %components = ( | |||||||||||||||||||||||||||||||||||||||||
| 257 | scheme => 'pkg', | ||||||||||||||||||||||||||||||||||||||||||
| 258 | type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | namespace => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | name => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | version => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 262 | qualifiers => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 263 | subpath => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 265 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 1592 | my $purl_type = $components{type}; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # Check PURL components requirements | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 1592 | ▶ | Carp::croak "Invalid PURL: '$components{scheme}' is not a valid scheme" unless ($components{scheme} eq 'pkg'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 1550 | foreach my $qualifier (keys %{$components{qualifiers}}) { | |||||||||||||||||||||||||||||||||||||||||
| 275 | 2250 | ▶ | Carp::croak "Invalid PURL: '$qualifier' is not a valid qualifier" if ($qualifier =~ /(\s|\%)/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 2247 | ▶ | Carp::croak "Invalid PURL: '$qualifier' qualifier not in lowercase" if ($qualifier =~ /([A-Z])/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # Check checksum qualifier | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 1544 | ▶ | if (defined $components{qualifiers}->{checksum} and ref $components{qualifiers}->{checksum} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $components{"qualifiers"}{"checksum"} and ref $components{"qualifiers"}{"checksum"} eq "ARRAY"
MC/DC100%2/2
defined $components{"qualifiers"}{"checksum"} and ref $components{"qualifiers"}{"checksum"} eq "ARRAY"
defined $components{"qualifiers"}{"checksum"}
ref $components{"qualifiers"}{"checksum"} eq "ARRAY"
Truth table100%3/3
A and B
A= defined $components{"qualifiers"}{"checksum"}B= ref $components{"qualifiers"}{"checksum"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | foreach (@{$components{qualifiers}->{checksum}}) { | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 8 | my ($algo, $checksum) = split ':', $_; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 8 | ▶ | if (defined $ALGO_LENGTH{$algo}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 8 | ▶ | if (length($checksum) != $ALGO_LENGTH{$algo}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | DEBUG and say STDERR "-- Malformed '$algo' checksum qualifier (invalid length)"; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 8 | ▶ | if ($checksum !~ m/^[0-9a-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | DEBUG and say STDERR "-- Malformed '$algo' checksum qualifier (invalid characters)"; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # Fallback | ||||||||||||||||||||||||||||||||||||||||||
| 299 | elsif ($checksum !~ /^[0-9a-f]{32,}$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | DEBUG and say STDERR "-- Malformed '$algo' checksum qualifier (invalid characters or length)"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # PURL type definition validation | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 1544 | ▶ | if (%{$self->definition}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # Check components using PURL type definition | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 1543 | for my $component (qw[namespace name version subpath]) { | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 6041 | ▶ | next unless $self->component_have_definition($component); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 4576 | my $requirement = $self->component_requirement($component); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 4576 | ▶ | next unless $requirement; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 4576 | DEBUG and say STDERR "-- Validation - $component is $requirement"; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 4576 | ▶ | if (defined $components{$component}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 3219 | ▶ | if ($self->component_is_prohibited($component)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | Carp::croak sprintf("Invalid PURL: '%s' is prohibited for '%s' PURL type", $component, $purl_type); | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 3215 | ▶ | if (my $permitted_characters = $self->component_permitted_characters($component)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 17 | DEBUG and say STDERR "-- Validation - $component permitted characters $permitted_characters"; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 17 | ▶ | if ($components{$component} !~ /$permitted_characters/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 4 | Carp::croak | |||||||||||||||||||||||||||||||||||||||||
| 333 | sprintf("Invalid PURL: '%s' invalid characters for '%s' PURL type", $component, $purl_type); | ||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 4568 | ▶ | if (!defined $components{$component} && $self->component_is_required($component)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $components{$component} and $self->component_is_required($component)
MC/DC100%2/2
not defined $components{$component} and $self->component_is_required($component)
not defined $components{$component}
$self->component_is_required($component)
Truth table100%3/3
not(A) and B
A= not defined $components{$component}B= $self->component_is_required($component)
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 47 | Carp::croak sprintf("Invalid PURL: '%s' is required for '%s' PURL type", $component, $purl_type); | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | # Default known qualifiers | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # TODO: "checksums" legacy qualifier | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 1488 | my @known_qualifiers = (qw[ | |||||||||||||||||||||||||||||||||||||||||
| 349 | vers | ||||||||||||||||||||||||||||||||||||||||||
| 350 | repository_url | ||||||||||||||||||||||||||||||||||||||||||
| 351 | download_url | ||||||||||||||||||||||||||||||||||||||||||
| 352 | vcs_url | ||||||||||||||||||||||||||||||||||||||||||
| 353 | file_name | ||||||||||||||||||||||||||||||||||||||||||
| 354 | checksum | ||||||||||||||||||||||||||||||||||||||||||
| 355 | checksums | ||||||||||||||||||||||||||||||||||||||||||
| 356 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1488 | foreach my $rule (@{$self->qualifiers_definition}) { | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 6574 | my $key = $rule->{key}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 6574 | push @known_qualifiers, $key; | |||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 6574 | my $requirement = $rule->{requirement}; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 6574 | ▶ | next unless $requirement; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 6369 | DEBUG and say STDERR "-- Validation - '$key' qualifier is $requirement"; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 6369 | ▶ | if (defined $components{qualifiers}->{$key} and $requirement eq 'prohibited') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $components{"qualifiers"}{$key} and $requirement eq "prohibited"
MC/DC0%0/2
defined $components{"qualifiers"}{$key} and $requirement eq "prohibited"
defined $components{"qualifiers"}{$key}
$requirement eq "prohibited"
Truth table66%2/3
A and B
A= defined $components{"qualifiers"}{$key}B= $requirement eq "prohibited"
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | Carp::croak sprintf("Invalid PURL: '%s' qualifier is prohibited for '%s' PURL type", $key, $purl_type); | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 6369 | ▶ | if (not defined $components{qualifiers}->{$key} and $requirement eq 'required') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $components{"qualifiers"}{$key} and $requirement eq "required"
MC/DC100%2/2
not defined $components{"qualifiers"}{$key} and $requirement eq "required"
not defined $components{"qualifiers"}{$key}
$requirement eq "required"
Truth table100%3/3
not(A) and B
A= not defined $components{"qualifiers"}{$key}B= $requirement eq "required"
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | Carp::croak sprintf("Invalid PURL: '%s' qualifier is required for '%s' PURL type", $key, $purl_type); | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | # Check unknown qualifiers | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 1487 | foreach my $key (keys %{$components{qualifiers}}) { | |||||||||||||||||||||||||||||||||||||||||
| 380 | DEBUG and say STDERR "-- '$key' is known qualifier for '$purl_type' PURL type" | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 2243 | ▶ | unless (first { $key eq $_ } @known_qualifiers); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | # PURL type specific validation | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 1488 | TYPE: for ($purl_type) { | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 1488 | ▶ | if (/conan/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 15 | ▶ | if (!$components{namespace} && defined $components{qualifiers}->{channel}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $components{"namespace"} and defined $components{"qualifiers"}{"channel"}
MC/DC0%0/2
not $components{"namespace"} and defined $components{"qualifiers"}{"channel"}
not $components{"namespace"}
defined $components{"qualifiers"}{"channel"}
Truth table66%2/3
not(A) and B
A= not $components{"namespace"}B= defined $components{"qualifiers"}{"channel"}
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | Carp::croak "Invalid PURL: Conan 'channel' qualifier without 'namespace'"; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 15 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 1473 | ▶ | if (/cpan/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | # Use legacy CPAN PURL type SPEC | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 1007 | ▶ | if ($ENV{PURL_LEGACY_CPAN_TYPE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ((defined $components{namespace} && defined $components{name}) && $components{namespace} =~ /\:/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $components{"namespace"} and defined $components{"name"} and $components{"namespace"} =~ /\:/
defined $components{"namespace"} and defined $components{"name"}
MC/DC0%0/3
defined $components{"namespace"} and defined $components{"name"} and $components{"namespace"} =~ /\:/
defined $components{"namespace"}
defined $components{"name"}
$components{"namespace"} =~ /\:/
Truth table0%0/4
A and B and C
A= defined $components{"namespace"}B= defined $components{"name"}C= $components{"namespace"} =~ /\:/
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | Carp::croak "Invalid PURL: CPAN 'namespace' component must have the distribution author"; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ((defined $components{namespace} && defined $components{name}) && $components{name} =~ /\:/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $components{"namespace"} and defined $components{"name"} and $components{"name"} =~ /\:/
defined $components{"namespace"} and defined $components{"name"}
MC/DC0%0/3
defined $components{"namespace"} and defined $components{"name"} and $components{"name"} =~ /\:/
defined $components{"namespace"}
defined $components{"name"}
$components{"name"} =~ /\:/
Truth table0%0/4
A and B and C
A= defined $components{"namespace"}B= defined $components{"name"}C= $components{"name"} =~ /\:/
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | Carp::croak "Invalid PURL: CPAN 'name' component must have the distribution name"; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if (!defined $components{namespace} && $components{name} =~ /\-/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $components{"namespace"} and $components{"name"} =~ /\-/
MC/DC0%0/2
not defined $components{"namespace"} and $components{"name"} =~ /\-/
not defined $components{"namespace"}
$components{"name"} =~ /\-/
Truth table0%0/3
not(A) and B
A= not defined $components{"namespace"}B= $components{"name"} =~ /\-/
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | Carp::croak "Invalid PURL: CPAN 'name' component must have the module name"; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 1007 | ▶ | if ($components{name} =~ /\:/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 5 | Carp::croak "Invalid PURL: The CPAN 'name' component must have the distribution name"; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 1002 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 466 | ▶ | if (/cran/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 12 | ▶ | Carp::croak "Invalid PURL: Cran 'version' is required" unless defined $components{version}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 12 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 454 | ▶ | if (/swift/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 11 | ▶ | if (defined $components{namespace}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 11 | my ($source, $user_org) = split '/', $components{namespace}; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 11 | ▶ | Carp::croak "Invalid PURL: Swift user/organization is required in 'namespace'" unless $user_org; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 9 | last TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 1481 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | __END__ | ||||||||||||||||||||||||||||||||||||||||||