| 1 | package URI::PackageURL::App; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use feature ':5.10'; | ||||||||||||||||||
|
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 utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use Data::Dumper (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use Getopt::Long qw(GetOptionsFromArray :config gnu_compat); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use JSON::PP (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use Pod::Text (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use Pod::Usage qw(pod2usage); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | use URI::PackageURL (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use URI::PackageURL::Type (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 2 | ▶ | use URI::PackageURL::Util qw(purl_types); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | our $VERSION = '2.25'; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | sub cli_error { | ||||||||||||||||||
|
Subroutine
cli_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 22 | 0 | my ($error) = @_; | |||||||||||||||||||
| 23 | 0 | $error =~ s/ at .* line \d+.*//; | |||||||||||||||||||
| 24 | 0 | say STDERR "ERROR: $error"; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 16 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: called CC=32 SCAR=53.0
Pod
documented
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 16 | my ($class, @args) = @_; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 16 | my %options = (format => 'json'); | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 16 | ▶ | GetOptionsFromArray( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | \@args, \%options, qw( | ||||||||||||||||||||
| 35 | help|h | ||||||||||||||||||||
| 36 | man | ||||||||||||||||||||
| 37 | v | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | download-url | ||||||||||||||||||||
| 40 | repository-url | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | validate | ||||||||||||||||||||
| 43 | quiet|q | ||||||||||||||||||||
| 44 | info=s | ||||||||||||||||||||
| 45 | list | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | type=s | ||||||||||||||||||||
| 48 | namespace=s | ||||||||||||||||||||
| 49 | name=s | ||||||||||||||||||||
| 50 | version=s | ||||||||||||||||||||
| 51 | qualifiers|qualifier=s% | ||||||||||||||||||||
| 52 | subpath=s | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | null|0 | ||||||||||||||||||||
| 55 | format=s | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | json | ||||||||||||||||||||
| 58 | yaml | ||||||||||||||||||||
| 59 | dumper | ||||||||||||||||||||
| 60 | env | ||||||||||||||||||||
| 61 | ) | ||||||||||||||||||||
| 62 | ) or pod2usage(-verbose => 0); | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 16 | ▶ | pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 16 | ▶ | pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 16 | ▶ | if (defined $options{v}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | (my $progname = $0) =~ s/.*\///; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | say <<"VERSION"; | |||||||||||||||||||
| 72 | $progname version $URI::PackageURL::VERSION | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Copyright 2022-2026, Giuseppe Di Terlizzi <gdt\@cpan.org> | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | This program is part of the "URI-PackageURL" distribution and is free software; | ||||||||||||||||||||
| 77 | you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Complete documentation for $progname can be found using 'man $progname' | ||||||||||||||||||||
| 80 | or on the internet at <https://metacpan.org/dist/URI-PackageURL>. | ||||||||||||||||||||
| 81 | VERSION | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | return 0; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 16 | ▶ | if (defined $options{info}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | return _definition_help(lc $options{info}); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 16 | ▶ | if (defined $options{list}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 0 | return _purl_list(); | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 16 | ▶ | if (defined $options{type}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 1 | my $purl = eval { | |||||||||||||||||||
| 98 | URI::PackageURL->new( | ||||||||||||||||||||
| 99 | type => $options{type}, | ||||||||||||||||||||
| 100 | namespace => $options{namespace}, | ||||||||||||||||||||
| 101 | name => $options{name}, | ||||||||||||||||||||
| 102 | version => $options{version}, | ||||||||||||||||||||
| 103 | qualifiers => $options{qualifiers}, | ||||||||||||||||||||
| 104 | subpath => $options{subpath}, | ||||||||||||||||||||
| 105 | 1 | ); | |||||||||||||||||||
| 106 | }; | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 1 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 0 | cli_error($@); | |||||||||||||||||||
| 110 | 0 | return 1; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | ▶ | print "$purl" . (defined $options{null} ? "\0" : "\n"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 1 | return 0; | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 15 | my ($purl_string) = @args; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 15 | ▶ | pod2usage(-verbose => 1) if !$purl_string; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 15 | ▶ | $options{format} = 'json' if defined $options{json}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 15 | ▶ | $options{format} = 'yaml' if defined $options{yaml}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | 15 | ▶ | $options{format} = 'dumper' if defined $options{dumper}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 15 | ▶ | $options{format} = 'env' if defined $options{env}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 15 | my $purl = eval { URI::PackageURL->from_string($purl_string) }; | |||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 15 | ▶ | if ($options{validate}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 14 | ▶ | unless ($options{quiet}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 0 | ▶ | say STDERR $purl ? 'true' : 'false'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 14 | ▶ | return $purl ? 0 : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 1 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | 0 | cli_error($@); | |||||||||||||||||||
| 141 | 0 | return 1; | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 1 | my $purl_urls = $purl->to_urls; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 1 | ▶ | if ($options{'download-url'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 0 | ▶ | return 2 unless defined $purl_urls->{download}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | ▶ | print $purl_urls->{download} . (defined $options{null} ? "\0" : "\n"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | 0 | return 0; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 1 | ▶ | if ($options{'repository-url'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | ▶ | return 2 unless defined $purl_urls->{repository}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 0 | ▶ | print $purl_urls->{repository} . ($options{null} ? "\0" : "\n"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 160 | 0 | return 0; | |||||||||||||||||||
| 161 | } | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 1 | ▶ | if ($options{format} eq 'json') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 1 | print JSON::PP->new->canonical->pretty(1)->convert_blessed(1)->encode($purl); | |||||||||||||||||||
| 165 | 1 | return 0; | |||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | ▶ | if ($options{format} eq 'dumper') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 169 | 0 | print Data::Dumper->new([$purl->to_hash])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump; | |||||||||||||||||||
| 170 | 0 | return 0; | |||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 0 | ▶ | if ($options{format} eq 'yaml') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 0 | ▶ | if (eval { require YAML::XS }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 176 | 0 | print YAML::XS::Dump($purl->to_hash); | |||||||||||||||||||
| 177 | 0 | return 0; | |||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | 0 | ▶ | if (eval { require YAML }) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 180 | 0 | print YAML::Dump($purl->to_hash); | |||||||||||||||||||
| 181 | 0 | return 0; | |||||||||||||||||||
| 182 | } | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 0 | cli_error 'YAML or YAML::XS module are missing'; | |||||||||||||||||||
| 185 | 0 | return 255; | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | } | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 0 | ▶ | if ($options{format} eq 'env') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 190 | 0 | return _purl_env($purl); | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | 0 | ▶ | sub _md_to_pod { | ||||||||||||||||||
|
Subroutine
_md_to_pod: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 0 | my $text = shift; | |||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 0 | $text =~ s/(``([^``]*)``)/C<$2>/gm; | |||||||||||||||||||
| 200 | 0 | $text =~ s/(`([^`]*)`)/C<$2>/gm; | |||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | 0 | return $text; | |||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | 0 | ▶ | sub _purl_env { | ||||||||||||||||||
|
Subroutine
_purl_env: not called CC=7 SCAR=40.3
| |||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | 0 | my $purl = shift; | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 0 | my $purl_urls = $purl->to_urls; | |||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | my %PURL_ENVS = ( | ||||||||||||||||||||
| 213 | PURL => $purl->to_string, | ||||||||||||||||||||
| 214 | PURL_TYPE => $purl->type, | ||||||||||||||||||||
| 215 | PURL_NAMESPACE => $purl->namespace, | ||||||||||||||||||||
| 216 | PURL_NAME => $purl->name, | ||||||||||||||||||||
| 217 | PURL_VERSION => $purl->version, | ||||||||||||||||||||
| 218 | PURL_SUBPATH => $purl->subpath, | ||||||||||||||||||||
| 219 | 0 | PURL_QUALIFIERS => (join ' ', sort keys %{$purl->qualifiers}), | |||||||||||||||||||
| 220 | ); | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | # Preserve order | ||||||||||||||||||||
| 223 | 0 | my @PURL_ENVS = qw(PURL PURL_TYPE PURL_NAMESPACE PURL_NAME PURL_VERSION PURL_SUBPATH PURL_QUALIFIERS); | |||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | 0 | my $qualifiers = $purl->qualifiers; | |||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | 0 | foreach my $qualifier (sort keys %{$qualifiers}) { | |||||||||||||||||||
| 228 | 0 | my $key = "PURL_QUALIFIER_$qualifier"; | |||||||||||||||||||
| 229 | 0 | push @PURL_ENVS, $key; | |||||||||||||||||||
| 230 | 0 | $PURL_ENVS{$key} = $qualifiers->{$qualifier}; | |||||||||||||||||||
| 231 | } | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | 0 | ▶ | if ($purl_urls) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 234 | 0 | ▶ | if (defined $purl_urls->{download}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 235 | 0 | push @PURL_ENVS, 'PURL_DOWNLOAD_URL'; | |||||||||||||||||||
| 236 | 0 | $PURL_ENVS{PURL_DOWNLOAD_URL} = $purl_urls->{download}; | |||||||||||||||||||
| 237 | } | ||||||||||||||||||||
| 238 | 0 | ▶ | if (defined $purl_urls->{repository}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 239 | 0 | push @PURL_ENVS, 'PURL_REPOSITORY_URL'; | |||||||||||||||||||
| 240 | 0 | $PURL_ENVS{PURL_REPOSITORY_URL} = $purl_urls->{repository}; | |||||||||||||||||||
| 241 | } | ||||||||||||||||||||
| 242 | } | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | 0 | foreach my $key (@PURL_ENVS) { | |||||||||||||||||||
| 245 | 0 | ▶ | print sprintf qq{%s="%s"\n}, $key, $PURL_ENVS{$key} || q{}; | ||||||||||||||||||
|
Condition0%0/2
$PURL_ENVS{$key} || ''
MC/DC0%0/1
$PURL_ENVS{$key} || ''
$PURL_ENVS{$key}
Truth table0%0/2
A
A= $PURL_ENVS{$key}
| |||||||||||||||||||||
| 246 | } | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 0 | return 0; | |||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | 0 | ▶ | sub _purl_list { | ||||||||||||||||||
|
Subroutine
_purl_list: not called CC=11 SCAR=48.8
| |||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | 0 | my @types = purl_types(); | |||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | 0 | my $pattern = "%15s | %10s | %10s | %10s | %10s | %s"; | |||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | 0 | say sprintf $pattern, 'TYPE', 'NAMESPACE', 'NAME', 'VERSION', 'SUBPATH', 'QUALIFIERS'; | |||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | 0 | say sprintf "%s-|-%s-|-%s-|-%s-|-%s-|-%s", '-' x 15, '-' x 10, '-' x 10, '-' x 10, '-' x 10, '-' x 10; | |||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | 0 | for my $type (@types) { | |||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | 0 | my $definition = URI::PackageURL::Type->new($type); | |||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | 0 | my $namespace = '-'; | |||||||||||||||||||
| 267 | 0 | my $name = '-'; | |||||||||||||||||||
| 268 | 0 | my $version = '-'; | |||||||||||||||||||
| 269 | 0 | my $subpath = '-'; | |||||||||||||||||||
| 270 | 0 | my $qualifiers = '-'; | |||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | 0 | ▶ | if ($definition->component_have_definition('namespace')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 273 | 0 | ▶ | $namespace = $definition->component_requirement('namespace') // '-'; | ||||||||||||||||||
|
Condition0%0/2
$definition->component_requirement("namespace") // "-"
MC/DC0%0/1
$definition->component_requirement("namespace") // "-"
$definition->component_requirement("namespace")
Truth table0%0/2
A
A= $definition->component_requirement("namespace")
| |||||||||||||||||||||
| 274 | } | ||||||||||||||||||||
| 275 | |||||||||||||||||||||
| 276 | 0 | ▶ | if ($definition->component_have_definition('name')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 277 | 0 | ▶ | $name = $definition->component_requirement('name') // '-'; | ||||||||||||||||||
|
Condition0%0/2
$definition->component_requirement("name") // "-"
MC/DC0%0/1
$definition->component_requirement("name") // "-"
$definition->component_requirement("name")
Truth table0%0/2
A
A= $definition->component_requirement("name")
| |||||||||||||||||||||
| 278 | } | ||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | 0 | ▶ | if ($definition->component_have_definition('version')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 281 | 0 | ▶ | $version = $definition->component_requirement('version') // '-'; | ||||||||||||||||||
|
Condition0%0/2
$definition->component_requirement("version") // "-"
MC/DC0%0/1
$definition->component_requirement("version") // "-"
$definition->component_requirement("version")
Truth table0%0/2
A
A= $definition->component_requirement("version")
| |||||||||||||||||||||
| 282 | } | ||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | 0 | ▶ | if ($definition->component_have_definition('subpath')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 285 | 0 | ▶ | $subpath = $definition->component_requirement('subpath') // '-'; | ||||||||||||||||||
|
Condition0%0/2
$definition->component_requirement("subpath") // "-"
MC/DC0%0/1
$definition->component_requirement("subpath") // "-"
$definition->component_requirement("subpath")
Truth table0%0/2
A
A= $definition->component_requirement("subpath")
| |||||||||||||||||||||
| 286 | } | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | 0 | ▶ | if (@{$definition->qualifiers_definition}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 289 | 0 | $qualifiers = join ", ", map { $_->{key} } @{$definition->qualifiers_definition}; | |||||||||||||||||||
| 290 | } | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | 0 | say sprintf $pattern, $type, $namespace, $name, $version, $subpath, $qualifiers; | |||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | } | ||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | 0 | return 0; | |||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | } | ||||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | 0 | ▶ | sub _definition_help { | ||||||||||||||||||
|
Subroutine
_definition_help: not called CC=28 SCAR=67.0
| |||||||||||||||||||||
| 302 | |||||||||||||||||||||
| 303 | 0 | my $type = shift; | |||||||||||||||||||
| 304 | |||||||||||||||||||||
| 305 | 0 | my $definition = URI::PackageURL::Type->new($type); | |||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | 0 | ▶ | unless (%{$definition->definition}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 308 | 0 | say "No known PURL type definition for '$type'"; | |||||||||||||||||||
| 309 | 0 | exit 1; | |||||||||||||||||||
| 310 | } | ||||||||||||||||||||
| 311 | |||||||||||||||||||||
| 312 | 0 | my $type_name = $definition->type_name; | |||||||||||||||||||
| 313 | 0 | my $description = $definition->description; | |||||||||||||||||||
| 314 | 0 | my $reference_urls = $definition->reference_urls; | |||||||||||||||||||
| 315 | 0 | my $examples = $definition->examples; | |||||||||||||||||||
| 316 | 0 | my $note = $definition->note; | |||||||||||||||||||
| 317 | 0 | my $repository = $definition->repository; | |||||||||||||||||||
| 318 | 0 | my $schema_id = $definition->schema_id; | |||||||||||||||||||
| 319 | |||||||||||||||||||||
| 320 | 0 | my $qualifiers_definition = $definition->qualifiers_definition; | |||||||||||||||||||
| 321 | |||||||||||||||||||||
| 322 | 0 | ▶ | my $have_ns = ($definition->component_is_required('namespace') || $definition->component_is_optional('namespace')); | ||||||||||||||||||
|
Condition0%0/3
$definition->component_is_required('namespace') || $definition->component_is_optional('namespace')
MC/DC0%0/2
$definition->component_is_required('namespace') || $definition->component_is_optional('namespace')
$definition->component_is_required('namespace')
$definition->component_is_optional('namespace')
Truth table0%0/3
A || B
A= $definition->component_is_required('namespace')B= $definition->component_is_optional('namespace')
| |||||||||||||||||||||
| 323 | |||||||||||||||||||||
| 324 | 0 | my $purl_syntax = "pkg:$type"; | |||||||||||||||||||
| 325 | 0 | ▶ | $purl_syntax .= '/E<lt>namespaceE<gt>' if $have_ns; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 326 | 0 | $purl_syntax .= '/E<lt>nameE<gt>@E<lt>versionE<gt>?E<lt>qualifiersE<gt>#E<lt>subpathE<gt>'; | |||||||||||||||||||
| 327 | |||||||||||||||||||||
| 328 | 0 | my $man = <<"MAN"; | |||||||||||||||||||
| 329 | =head1 NAME | ||||||||||||||||||||
| 330 | |||||||||||||||||||||
| 331 | $type - $type_name | ||||||||||||||||||||
| 332 | |||||||||||||||||||||
| 333 | =head1 DESCRIPTION | ||||||||||||||||||||
| 334 | |||||||||||||||||||||
| 335 | $description | ||||||||||||||||||||
| 336 | |||||||||||||||||||||
| 337 | =head1 SYNTAX | ||||||||||||||||||||
| 338 | |||||||||||||||||||||
| 339 | The structure of a PURL for this package type is: | ||||||||||||||||||||
| 340 | |||||||||||||||||||||
| 341 | C<$purl_syntax> | ||||||||||||||||||||
| 342 | |||||||||||||||||||||
| 343 | MAN | ||||||||||||||||||||
| 344 | |||||||||||||||||||||
| 345 | 0 | foreach my $component (qw[namespace name version subpath]) { | |||||||||||||||||||
| 346 | |||||||||||||||||||||
| 347 | 0 | ▶ | next unless $definition->component_have_definition($component); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 348 | |||||||||||||||||||||
| 349 | 0 | my $requirement = $definition->component_requirement($component); | |||||||||||||||||||
| 350 | 0 | my $permitted_characters = $definition->component_permitted_characters($component); | |||||||||||||||||||
| 351 | 0 | my $normalization_rules = $definition->component_normalization_rules($component); | |||||||||||||||||||
| 352 | 0 | my $case_sensitive = $definition->component_case_sensitive($component); | |||||||||||||||||||
| 353 | 0 | my $native_name = $definition->component_native_name($component); | |||||||||||||||||||
| 354 | 0 | my $note = $definition->component_note($component); | |||||||||||||||||||
| 355 | |||||||||||||||||||||
| 356 | 0 | $man .= sprintf "=head2 %s\n\n", ucfirst $component; | |||||||||||||||||||
| 357 | 0 | $man .= "=over 2\n\n"; | |||||||||||||||||||
| 358 | |||||||||||||||||||||
| 359 | 0 | ▶ | if ($requirement) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 360 | 0 | $man .= sprintf "=item B<Requirement>: %s\n\n", ucfirst($requirement); | |||||||||||||||||||
| 361 | } | ||||||||||||||||||||
| 362 | |||||||||||||||||||||
| 363 | 0 | ▶ | if ($permitted_characters) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 364 | 0 | $man .= sprintf "=item B<Permitted Characters>: %s\n\n", ucfirst($permitted_characters); | |||||||||||||||||||
| 365 | } | ||||||||||||||||||||
| 366 | |||||||||||||||||||||
| 367 | 0 | ▶ | if ($case_sensitive) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 368 | 0 | ▶ | $man .= sprintf "=item B<Is Case Sensitive>: %s\n\n", ($case_sensitive ? 'Yes' : 'No'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 369 | } | ||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | 0 | ▶ | if (@{$normalization_rules}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 372 | |||||||||||||||||||||
| 373 | 0 | $man .= "=item B<Normalization Rules>:\n\n"; | |||||||||||||||||||
| 374 | 0 | $man .= "=over 2\n\n"; | |||||||||||||||||||
| 375 | |||||||||||||||||||||
| 376 | 0 | foreach (@{$normalization_rules}) { | |||||||||||||||||||
| 377 | 0 | $man .= sprintf "=item * %s\n\n", $_; | |||||||||||||||||||
| 378 | } | ||||||||||||||||||||
| 379 | |||||||||||||||||||||
| 380 | 0 | $man .= "=back\n\n"; | |||||||||||||||||||
| 381 | |||||||||||||||||||||
| 382 | } | ||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | 0 | ▶ | if ($native_name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 385 | 0 | $man .= "=item B<Native Label>: $native_name\n\n"; | |||||||||||||||||||
| 386 | } | ||||||||||||||||||||
| 387 | |||||||||||||||||||||
| 388 | 0 | $man .= "=back\n\n"; | |||||||||||||||||||
| 389 | |||||||||||||||||||||
| 390 | 0 | ▶ | if ($note) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 391 | 0 | $man .= sprintf "%s\n\n", _md_to_pod($note); | |||||||||||||||||||
| 392 | } | ||||||||||||||||||||
| 393 | } | ||||||||||||||||||||
| 394 | |||||||||||||||||||||
| 395 | 0 | ▶ | if (@{$qualifiers_definition}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 396 | |||||||||||||||||||||
| 397 | 0 | $man .= "=head2 Qualifiers\n\n"; | |||||||||||||||||||
| 398 | 0 | $man .= "=over 2\n\n"; | |||||||||||||||||||
| 399 | |||||||||||||||||||||
| 400 | 0 | foreach my $qualifier (@{$qualifiers_definition}) { | |||||||||||||||||||
| 401 | |||||||||||||||||||||
| 402 | 0 | $man .= sprintf "=item C<%s>\n\n", $qualifier->{key}; | |||||||||||||||||||
| 403 | |||||||||||||||||||||
| 404 | 0 | ▶ | if (my $requirement = $qualifier->{requirement}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 405 | 0 | $man .= sprintf "Requirement: %s\n\n", ucfirst($requirement); | |||||||||||||||||||
| 406 | } | ||||||||||||||||||||
| 407 | |||||||||||||||||||||
| 408 | 0 | ▶ | if (my $native_name = $qualifier->{native_name}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 409 | 0 | $man .= sprintf "Native name: %s\n\n", $native_name; | |||||||||||||||||||
| 410 | } | ||||||||||||||||||||
| 411 | |||||||||||||||||||||
| 412 | 0 | ▶ | if (my $default_value = $qualifier->{default_value}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 413 | 0 | $man .= sprintf "Default value: %s\n\n", $default_value; | |||||||||||||||||||
| 414 | } | ||||||||||||||||||||
| 415 | |||||||||||||||||||||
| 416 | 0 | $man .= sprintf "%s\n\n", _md_to_pod($qualifier->{description}); | |||||||||||||||||||
| 417 | |||||||||||||||||||||
| 418 | } | ||||||||||||||||||||
| 419 | |||||||||||||||||||||
| 420 | 0 | $man .= "=back\n\n"; | |||||||||||||||||||
| 421 | |||||||||||||||||||||
| 422 | } | ||||||||||||||||||||
| 423 | |||||||||||||||||||||
| 424 | 0 | ▶ | if ($repository) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 425 | |||||||||||||||||||||
| 426 | 0 | ▶ | my $use_repository = $repository->{use_repository} ? 'Yes' : 'No'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 427 | 0 | my $default_repository_url = $repository->{default_repository_url}; | |||||||||||||||||||
| 428 | |||||||||||||||||||||
| 429 | 0 | $man .= "=head1 REPOSITORY\n\n"; | |||||||||||||||||||
| 430 | 0 | $man .= "=over\n\n"; | |||||||||||||||||||
| 431 | 0 | ▶ | $man .= sprintf "=item B<Use repository>: %s\n\n", $repository->{use_repository} ? 'Yes' : 'No'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 432 | 0 | ▶ | $man .= sprintf "=item B<Default repository URL>: %s\n\n", $repository->{default_repository_url} || '(none)'; | ||||||||||||||||||
|
Condition0%0/2
$repository->{'default_repository_url'} || '(none)'
MC/DC0%0/1
$repository->{'default_repository_url'} || '(none)'
$repository->{'default_repository_url'}
Truth table0%0/2
A
A= $repository->{'default_repository_url'}
| |||||||||||||||||||||
| 433 | 0 | $man .= "=back\n\n"; | |||||||||||||||||||
| 434 | |||||||||||||||||||||
| 435 | 0 | ▶ | if (my $note = $repository->{note}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 436 | 0 | $man .= sprintf "%s\n\n", _md_to_pod($note); | |||||||||||||||||||
| 437 | } | ||||||||||||||||||||
| 438 | |||||||||||||||||||||
| 439 | } | ||||||||||||||||||||
| 440 | |||||||||||||||||||||
| 441 | 0 | ▶ | if (@{$examples}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | 0 | $man .= "=head1 EXAMPLES\n\n"; | |||||||||||||||||||
| 444 | 0 | $man .= "=over 2\n\n"; | |||||||||||||||||||
| 445 | |||||||||||||||||||||
| 446 | 0 | foreach (@{$examples}) { | |||||||||||||||||||
| 447 | 0 | $man .= sprintf "=item * %s\n\n", $_; | |||||||||||||||||||
| 448 | } | ||||||||||||||||||||
| 449 | |||||||||||||||||||||
| 450 | 0 | $man .= "=back\n\n"; | |||||||||||||||||||
| 451 | |||||||||||||||||||||
| 452 | } | ||||||||||||||||||||
| 453 | |||||||||||||||||||||
| 454 | 0 | ▶ | if ($note) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 455 | 0 | $man .= "=head1 NOTES\n\n"; | |||||||||||||||||||
| 456 | 0 | $man .= sprintf "$note\n\n"; | |||||||||||||||||||
| 457 | } | ||||||||||||||||||||
| 458 | |||||||||||||||||||||
| 459 | 0 | $man .= "=head1 REFERENCES\n\n"; | |||||||||||||||||||
| 460 | 0 | $man .= "=over 2\n\n"; | |||||||||||||||||||
| 461 | |||||||||||||||||||||
| 462 | 0 | $man .= sprintf "=item * %s schema ID, L<%s>\n\n", $type_name, $schema_id; | |||||||||||||||||||
| 463 | |||||||||||||||||||||
| 464 | 0 | foreach (@{$reference_urls}) { | |||||||||||||||||||
| 465 | 0 | $man .= sprintf "=item * %s reference, L<%s>\n\n", $type_name, $_; | |||||||||||||||||||
| 466 | } | ||||||||||||||||||||
| 467 | |||||||||||||||||||||
| 468 | 0 | $man .= "=item * PURL specification, L<https://github.com/package-url/purl-spec>\n\n"; | |||||||||||||||||||
| 469 | 0 | $man .= "=item * VERS specification, L<https://github.com/package-url/vers-spec>\n\n"; | |||||||||||||||||||
| 470 | |||||||||||||||||||||
| 471 | 0 | $man .= "=back\n\n"; | |||||||||||||||||||
| 472 | |||||||||||||||||||||
| 473 | 0 | Pod::Text->new->parse_string_document($man, \my $output); | |||||||||||||||||||
| 474 | |||||||||||||||||||||
| 475 | 0 | exit; | |||||||||||||||||||
| 476 | |||||||||||||||||||||
| 477 | } | ||||||||||||||||||||
| 478 | |||||||||||||||||||||
| 479 | 2 | 1; | |||||||||||||||||||
| 480 | |||||||||||||||||||||
| 481 | __END__ | ||||||||||||||||||||