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