PackageURL.pm

filter: Statementstmt 97.1% 169 / 174 Branchbran 85.2% 58 / 68 Conditioncond 60.7% 34 / 56 MC/DCmcdc 39.3% 13 / 33 Subroutinesub 91.4% 32 / 35 Podpod 100% 20 / 20 totaltotal 84.4% 326 / 386 CC 57 SCAR 26.8
CC
57
Cov
88%
from_string
31.6
to_string
18.8
new
8.0
CRAP 14.6
« VersionRange/Util.pm ↑ Summary PackageURL/Util.pm »
1 package URI::PackageURL;
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 Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use URI::PackageURL::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use URI::PackageURL::Util qw(purl_to_urls);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use URI::VersionRange ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 ▶BEGIN { *PURL:: = *URI::PackageURL:: }
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 10 ▶use constant DEBUG => $ENV{PURL_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 10 ▶use overload '""' => 'to_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 10 our $VERSION = '2.26';
22 10 our @EXPORT = qw(encode_purl decode_purl is_purl);
23  
24 10 my $PURL_TYPE_REGEXP = qr{[a-z][a-z0-9\.\-]*};
25 10 my $PURL_REGEXP = qr{^pkg:(([/]{1,})?)([A-Za-z][A-Za-z0-9\.\-]*)([/]{1,}).+};
26  
27 2508 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
28  
29 2508 my ($class, %params) = @_;
30  
31 2508 my $type = delete $params{type};
32 2508 my $namespace = delete $params{namespace};
33 2508 ▶ my $name = delete $params{name} or Carp::croak "Invalid PURL: 'name' component is required";
Branch: 1 branch
BranchTrueFalseTotal
my $name = delete $params{"name"} or Carp::croak("Invalid PURL: 'name' component is required") 2500 8 2508
34 2500 my $version = delete $params{version};
35 2500 ▶ my $qualifiers = delete $params{qualifiers} // {};
Condition100%2/2
delete $params{"qualifiers"} // {}
l!l
2143357
MC/DC100%1/1
delete $params{"qualifiers"} // {}
delete $params{"qualifiers"}
Truth table100%2/2
A
A= delete $params{"qualifiers"}
Aresult
11
00
36 2500 my $subpath = delete $params{subpath};
37  
38 2500 ▶ Carp::croak "Invalid PURL: 'type' component is required" unless defined $type && length $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length $type 4 2496 2500
Condition66%2/3
defined $type and length $type
!ll&&!rl&&r
402496
MC/DC50%1/2
defined $type and length $type
defined $type length $type
Truth table66%2/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
39 2496 ▶ Carp::croak "Invalid PURL: invalid 'type' component '$type'" unless lc($type) =~ /\A$PURL_TYPE_REGEXP\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless lc($type) =~ /\A$PURL_TYPE_REGEXP\z/ 0 2496 2496
40  
41 2496 ▶ my $validate = delete $params{validate} // 1;
Condition100%2/2
delete $params{"validate"} // 1
l!l
13621134
MC/DC100%1/1
delete $params{"validate"} // 1
delete $params{"validate"}
Truth table100%2/2
A
A= delete $params{"validate"}
Aresult
11
00
42  
43 2496 my %components = (
44 scheme => 'pkg', # The scheme is a constant with the value "pkg".
45 type => $type,
46 namespace => $namespace,
47 name => $name,
48 version => $version,
49 qualifiers => $qualifiers,
50 subpath => $subpath,
51 );
52  
53 2496 my $definition = URI::PackageURL::Type->new($type);
54  
55 2496 ▶ $definition->validate(%components) if $validate;
Branch: 1 branch
BranchTrueFalseTotal
if $validate 1508 988 2496
56  
57 2469 my $self = {components => \%{$definition->normalize(%components)}, definition => $definition};
58  
59 2469 return bless $self, $class;
60  
61 }
62  
63 1859 ▶sub definition { shift->{definition} }
Subroutine definition: called CC=1 SCAR=0.0
Pod documented
64  
65 0 ▶sub scheme {'pkg'} # The scheme is a constant with the value "pkg".
Subroutine scheme: not called CC=1 SCAR=6.9
Pod documented
66 6233 ▶sub type { shift->_component('type', @_) }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
67 4787 ▶sub namespace { shift->_component('namespace', @_) }
Subroutine namespace: called CC=1 SCAR=0.0
Pod documented
68 4395 ▶sub name { shift->_component('name', @_) }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
69 8929 ▶sub version { shift->_component('version', @_) }
Subroutine version: called CC=1 SCAR=0.0
Pod documented
70 9577 ▶sub qualifiers { shift->_component('qualifiers', @_) }
Subroutine qualifiers: called CC=1 SCAR=0.0
Pod documented
71 2562 ▶sub subpath { shift->_component('subpath', @_) }
Subroutine subpath: called CC=1 SCAR=0.0
Pod documented
72  
73 5 ▶sub encode_purl { __PACKAGE__->new(@_)->to_string }
Subroutine encode_purl: called CC=1 SCAR=0.0
Pod documented
74 6 ▶sub decode_purl { __PACKAGE__->from_string(@_) }
Subroutine decode_purl: called CC=1 SCAR=0.0
Pod documented
75 459 ▶sub is_purl { ($_[0] =~ /$PURL_REGEXP/) ? 1 : undef }
Subroutine is_purl: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /$PURL_REGEXP/ ? : 442 17 459
76  
77 927 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
78 927 my $self = shift;
79 927 return ref($self)->new(%{$self->to_hash}, validate => 0);
80 }
81  
82 1 ▶sub to_urls { purl_to_urls(shift) }
Subroutine to_urls: called CC=1 SCAR=0.0
Pod documented
83 0 ▶sub download_url { shift->to_urls->{download} }
Subroutine download_url: not called CC=1 SCAR=6.9
Pod documented
84 0 ▶sub repository_url { shift->to_urls->{repository} }
Subroutine repository_url: not called CC=1 SCAR=6.9
Pod documented
85  
86 459 ▶sub from_string {
Subroutine from_string: called CC=28 SCAR=34.5
Pod documented
87  
88 459 my ($class, $string, %options) = @_;
89  
90 459 utf8::encode($string);
91  
92 459 DEBUG and say STDERR "-- INPUT: $string";
93 459 DEBUG and say STDERR "-- REGEXP: $PURL_REGEXP";
94  
95 # Strip slash / after scheme
96 459 ▶ while ($string =~ m{^pkg:/}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ m[^pkg:/]) 14 459 473
97 14 $string =~ s{^pkg:/}{pkg:};
98 }
99  
100 459 ▶ unless (is_purl($string)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_purl($string)) 17 442 459
101 17 Carp::croak 'Malformed PURL string';
102 }
103  
104 442 my %components = ();
105  
106  
107 # Split the purl string once from right on '#'
108 # The left side is the 'remainder'
109 # Strip the right side from leading and trailing '/'
110 # Split this on '/'
111 # Discard any empty string segment from that split
112 # Discard any '.' or '..' segment from that split
113 # Percent-decode each segment
114 # UTF-8-decode each segment if needed in your programming language
115 # Join segments back with a '/'
116 # This is the 'subpath'
117  
118 442 my @s1 = split(/#([^#]+)$/, $string);
119  
120 442 ▶ if (defined $s1[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s1[1]) 40 402 442
121 40 $s1[1] =~ s/(^\/|\/$)//;
122 40 ▶ my @subpath = map { _percent_decode($_) } grep { $_ ne '' && $_ ne '.' && $_ ne '..' } split /\//, $s1[1];
Condition33%2/6
$_ ne '' && $_ ne '.' && $_ ne '..'
!ll&&!rl&&r
0086
$_ ne "" and $_ ne "."
!ll&&!rl&&r
0086
MC/DC0%0/3
$_ ne '' && $_ ne '.' && $_ ne '..'
$_ ne "" $_ ne "." $_ ne '..'
Truth table25%1/4
A and B && C
A= $_ ne ""B= $_ ne "."C= $_ ne '..'
ABCresult
0XX0
10X0
1100
1111
123 40 $components{subpath} = join '/', @subpath;
124 }
125  
126  
127 # Split the 'remainder' once from right on '?'
128 # The left side is the 'remainder'
129 # The right side is the 'qualifiers' string
130 # Split the 'qualifiers' on '&'. Each part is a 'key=value' pair
131 # For each pair, split the 'key=value' once from left on '=':
132 # The 'key' is the lowercase left side
133 # The 'value' is the percent-decoded right side
134 # UTF-8-decode the value if needed in your programming language
135 # Discard any key/value pairs where the value is empty
136 # If the 'key' is 'checksum', split the 'value' on ',' to create a list of checksum
137 # This list of key/value is the 'qualifiers' object
138  
139 442 my @s2 = split(/\?([^\?]+)$/, $s1[0]);
140  
141 442 ▶ if (defined $s2[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s2[1]) 186 256 442
142  
143 186 my @qualifiers = split('&', $s2[1]);
144  
145 186 foreach my $qualifier (@qualifiers) {
146  
147 295 my ($key, $value) = ($qualifier =~ /^([^=]+)(?:=(.*))?$/);
148  
149 # Discard any key/value pairs where the value is empty
150 295 ▶ next unless defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 295 295
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
00295
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
151 295 $value = _percent_decode($value);
152  
153 295 ▶ if ($key eq 'checksums' || $key eq 'checksum') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "checksums" or $key eq "checksum") 5 290 295
Condition66%2/3
$key eq "checksums" or $key eq "checksum"
l!l&&r!l&&!r
05290
MC/DC50%1/2
$key eq "checksums" or $key eq "checksum"
$key eq "checksums" $key eq "checksum"
Truth table66%2/3
A or B
A= $key eq "checksums"B= $key eq "checksum"
ABresult
1X1
011
000
154 5 ▶ Carp::carp "Detected 'checksums' qualifier. Use 'checksum' qualifier instead." if ($key eq 'checksums');
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "checksums" 0 5 5
155 5 $value = [split(',', $value)];
156 }
157  
158 295 ▶ if ($key eq 'vers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "vers") 1 294 295
159 1 $value = URI::VersionRange->from_string($value);
160 }
161  
162 295 $components{qualifiers}->{$key} = $value;
163  
164 }
165  
166 }
167  
168  
169 # Split the 'remainder' once from left on ':'
170 # The left side lowercased is the 'scheme'
171 # The right side is the 'remainder'
172  
173 442 my @s3 = split(':', $s2[0], 2);
174  
175 442 ▶ Carp::croak 'Invalid PURL: Missing "scheme"' unless $s3[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $s3[0] 0 442 442
176 442 ▶ Carp::croak 'Invalid PURL' unless $s3[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $s3[1] 0 442 442
177  
178 442 $components{scheme} = lc $s3[0];
179  
180 # Strip all leading '/' characters (e.g., '/', '//', '///' and so on) from the 'remainder'
181 # Split this once from left on '/'
182 # The left side lowercased is the 'type'
183 # The right side is the 'remainder'
184  
185 442 ▶ while ($s3[1] =~ m|^//|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s3[1] =~ m[^//]) 0 442 442
186 0 $s3[1] =~ s|^//|/|;
187 }
188  
189 442 $s3[1] =~ s|^/||; # Strip leading '/' character
190  
191 442 my @s4 = split('/', $s3[1], 2);
192 442 $components{type} = lc $s4[0];
193  
194 442 ▶ Carp::croak 'Invalid PURL: Invalid "type"' if $components{type} !~ /\A$PURL_TYPE_REGEXP\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $components{"type"} =~ /\A$PURL_TYPE_REGEXP\z/ 0 442 442
195 442 ▶ Carp::croak 'Invalid PURL' unless $s4[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $s4[1] 0 442 442
196  
197  
198 # Split the 'remainder' once from right on '@'
199 # The left side is the 'remainder'
200 # Percent-decode the right side. This is the 'version'.
201 # UTF-8-decode the 'version' if needed in your programming language
202 # This is the 'version'
203  
204 442 my @s5 = split(/@([^@]+)$/, $s4[1]);
205  
206 # NPM purl MAY have a namespace starting with "@"
207 # so we need to handle this case separately
208  
209 442 ▶ if ($components{type} eq 'npm' and $s4[1] =~ /^@/ and $s4[1] !~ /@.*@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($components{"type"} eq "npm" and $s4[1] =~ /^@/ and not $s4[1] =~ /\@.*@/) 2 440 442
Condition83%5/6
$components{"type"} eq "npm" and $s4[1] =~ /^@/ and not $s4[1] =~ /\@.*@/
!ll&&!rl&&r
44002
$components{"type"} eq "npm" and $s4[1] =~ /^@/
!ll&&!rl&&r
426142
MC/DC66%2/3
$components{"type"} eq "npm" and $s4[1] =~ /^@/ and not $s4[1] =~ /\@.*@/
$components{"type"} eq "npm" $s4[1] =~ /^@/ not $s4[1] =~ /\@.*@/
Truth table75%3/4
A and B and not(C)
A= $components{"type"} eq "npm"B= $s4[1] =~ /^@/C= not $s4[1] =~ /\@.*@/
ABCresult
0XX0
10X0
1100
1111
210 2 @s5 = ($s4[1]);
211 }
212  
213 442 ▶ $components{version} = _percent_decode($s5[1]) if (defined $s5[1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s5[1] 394 48 442
214  
215  
216 # Strip all trailing '/' characters (e.g., '/', '//', '///' and so on) from the 'remainder'
217 # The left side is the 'remainder'
218 # Percent-decode the right side. This is the 'name'
219 # UTF-8-decode this 'name' if needed in your programming language
220 # Apply type-specific normalization to the 'name' if needed
221 # This is the 'name'
222  
223 442 ▶ while ($s5[0] =~ m|//$|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s5[0] =~ m[//$]) 0 442 442
224 0 $s5[0] =~ s|//$|/|;
225 }
226  
227 442 $s5[0] =~ s|/$||; # Strip trailing '/' character
228  
229 442 my @s6 = split('/', $s5[0], -1);
230 442 $components{name} = _percent_decode(pop @s6);
231  
232 441 ▶ Carp::croak 'Invalid PURL: Missing "name"' unless defined $components{name} && length $components{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $components{"name"} and length $components{"name"} 6 435 441
Condition66%2/3
defined $components{"name"} and length $components{"name"}
!ll&&!rl&&r
60435
MC/DC50%1/2
defined $components{"name"} and length $components{"name"}
defined $components{"name"} length $components{"name"}
Truth table66%2/3
A and B
A= defined $components{"name"}B= length $components{"name"}
ABresult
0X0
100
111
233  
234  
235 # Split the 'remainder' on '/'
236 # Discard any empty segment from that split
237 # Percent-decode each segment
238 # UTF-8-decode the each segment if needed in your programming language
239 # Apply type-specific normalization to each segment if needed
240 # Join segments back with a '/'
241 # This is the 'namespace'
242  
243 435 ▶ if (@s6) {
Branch: 1 branch
BranchTrueFalseTotal
if (@s6) 229 206 435
244 229 $components{namespace} = join '/', map { _percent_decode($_) } @s6;
245 }
246  
247  
248 435 if (DEBUG) {
249 say STDERR "-- S1: @s1";
250 say STDERR "-- S2: @s2";
251 say STDERR "-- S3: @s3";
252 say STDERR "-- S4: @s4";
253 say STDERR "-- S5: @s5";
254 say STDERR "-- S6: @s6";
255 }
256  
257 435 ▶ return $class->new(%components, validate => ($options{validate} // 1));
Condition100%2/2
$options{"validate"} // 1
l!l
39342
MC/DC100%1/1
$options{"validate"} // 1
$options{"validate"}
Truth table100%2/2
A
A= $options{"validate"}
Aresult
11
00
258  
259 }
260  
261 2313 ▶sub to_string {
Subroutine to_string: called CC=17 SCAR=29.3
Pod documented
262  
263 2313 my $self = shift;
264  
265 2313 my @purl = ('pkg', ':', $self->type, '/');
266  
267 # Namespace
268 2313 ▶ if (defined $self->namespace && length $self->namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->namespace and length $self->namespace) 215 2098 2313
Condition66%2/3
defined $self->namespace and length $self->namespace
!ll&&!rl&&r
20980215
MC/DC50%1/2
defined $self->namespace and length $self->namespace
defined $self->namespace length $self->namespace
Truth table66%2/3
A and B
A= defined $self->namespaceB= length $self->namespace
ABresult
0X0
100
111
269 215 my @ns = map { _percent_encode($_) } split(/\//, $self->namespace);
270 215 push @purl, (join('/', @ns), '/');
271 }
272  
273 # Name
274 2313 push @purl, _percent_encode($self->name, '^A-Za-z0-9\-._~:\/'); # Default percent encoding + excluding slash
275  
276 # Version
277 2313 ▶ push @purl, ('@', _percent_encode($self->version)) if (defined $self->version && length $self->version);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->version and length $self->version 2270 43 2313
Condition66%2/3
defined $self->version and length $self->version
!ll&&!rl&&r
4302270
MC/DC50%1/2
defined $self->version and length $self->version
defined $self->version length $self->version
Truth table66%2/3
A and B
A= defined $self->versionB= length $self->version
ABresult
0X0
100
111
278  
279 # Qualifiers
280 2313 ▶ if ($self->qualifiers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->qualifiers) 2313 0 2313
281  
282 2313 my %qualifiers = %{$self->qualifiers};
283  
284 # TODO: Legacy 'checksums' qualifier will be dropped in the future
285 2313 foreach (qw[checksum checksums]) {
286 4626 ▶ if (defined $qualifiers{$_} && ref $qualifiers{$_} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qualifiers{$_} and ref $qualifiers{$_} eq "ARRAY") 5 4621 4626
Condition66%2/3
defined $qualifiers{$_} and ref $qualifiers{$_} eq "ARRAY"
!ll&&!rl&&r
462105
MC/DC50%1/2
defined $qualifiers{$_} and ref $qualifiers{$_} eq "ARRAY"
defined $qualifiers{$_} ref $qualifiers{$_} eq "ARRAY"
Truth table66%2/3
A and B
A= defined $qualifiers{$_}B= ref $qualifiers{$_} eq "ARRAY"
ABresult
0X0
100
111
287 5 $qualifiers{$_} = join ',', @{$qualifiers{$_}};
288 }
289 }
290  
291 2313 ▶ if (defined $qualifiers{vers} && ref $qualifiers{vers} eq 'URI::VersionRange') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qualifiers{"vers"} and ref $qualifiers{"vers"} eq "URI::VersionRange") 1 2312 2313
Condition66%2/3
defined $qualifiers{"vers"} and ref $qualifiers{"vers"} eq "URI::VersionRange"
!ll&&!rl&&r
231201
MC/DC50%1/2
defined $qualifiers{"vers"} and ref $qualifiers{"vers"} eq "URI::VersionRange"
defined $qualifiers{"vers"} ref $qualifiers{"vers"} eq "URI::VersionRange"
Truth table66%2/3
A and B
A= defined $qualifiers{"vers"}B= ref $qualifiers{"vers"} eq "URI::VersionRange"
ABresult
0X0
100
111
292 1 $qualifiers{vers} = $qualifiers{vers}->to_string;
293 }
294  
295 3120 my @qualifiers = map { sprintf('%s=%s', lc $_, _percent_encode($qualifiers{$_})) }
296 2313 ▶ grep { defined $qualifiers{$_} && length $qualifiers{$_} } sort keys %qualifiers;
Condition33%1/3
defined $qualifiers{$_} && length $qualifiers{$_}
!ll&&!rl&&r
003120
MC/DC0%0/2
defined $qualifiers{$_} && length $qualifiers{$_}
defined $qualifiers{$_} length $qualifiers{$_}
Truth table33%1/3
A && B
A= defined $qualifiers{$_}B= length $qualifiers{$_}
ABresult
0X0
100
111
297  
298 2313 ▶ push @purl, ('?', join('&', @qualifiers)) if (@qualifiers);
Branch: 1 branch
BranchTrueFalseTotal
if @qualifiers 2081 232 2313
299  
300 }
301  
302 # Subpath
303 2313 ▶ if (defined $self->subpath && length $self->subpath) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->subpath and length $self->subpath) 38 2275 2313
Condition66%2/3
defined $self->subpath and length $self->subpath
!ll&&!rl&&r
2275038
MC/DC50%1/2
defined $self->subpath and length $self->subpath
defined $self->subpath length $self->subpath
Truth table66%2/3
A and B
A= defined $self->subpathB= length $self->subpath
ABresult
0X0
100
111
304 38 ▶ my @subpath = map { _percent_encode($_) } grep { length $_ && $_ ne '.' && $_ ne '..' } split '/',
Condition33%2/6
length $_ && $_ ne '.' && $_ ne '..'
!ll&&!rl&&r
0079
length $_ and $_ ne "."
!ll&&!rl&&r
0079
MC/DC0%0/3
length $_ && $_ ne '.' && $_ ne '..'
length $_ $_ ne "." $_ ne '..'
Truth table25%1/4
A and B && C
A= length $_B= $_ ne "."C= $_ ne '..'
ABCresult
0XX0
10X0
1100
1111
305 $self->subpath;
306 38 push @purl, ('#', join('/', @subpath));
307 }
308  
309 2313 return join '', @purl;
310  
311 }
312  
313 928 ▶sub to_hash {
Subroutine to_hash: called CC=1 SCAR=0.0
Pod documented
314 928 my %hash = map { $_ => $_[0]->{components}->{$_} } qw[scheme type name version namespace qualifiers subpath];
315 928 return \%hash;
316 }
317  
318 1 ▶sub TO_JSON { shift->to_hash }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
319  
320 36483 ▶sub _component {
Subroutine _component: called CC=2 SCAR=6.9
321  
322 36483 my ($self, $component, $value) = @_;
323  
324 36483 ▶ if (@_ == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) 927 35556 36483
325 927 $self->{components}->{$component} = $value;
326 }
327  
328 36483 return $self->{components}->{$component};
329  
330 }
331  
332 8016 ▶sub _percent_encode {
Subroutine _percent_encode: called CC=3 SCAR=11.0
333  
334 8016 my ($string, $pattern) = @_;
335  
336 8016 ▶ $pattern //= '^A-Za-z0-9\-._~:' unless $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $pattern 5703 2313 8016
Condition50%1/2
$pattern //= "^A-Za-z0-9\\-._~:"
l!l
05703
MC/DC0%0/1
$pattern //= "^A-Za-z0-9\\-._~:"
$pattern
Truth table50%1/2
A
A= $pattern
Aresult
11
00
337  
338 8016 utf8::encode($string);
339  
340 8016 $string =~ s/([$pattern])/sprintf '%%%02X', ord $1/ge;
341 8016 return $string;
342  
343 }
344  
345 1472 ▶sub _percent_decode {
Subroutine _percent_decode: called CC=3 SCAR=11.0
346  
347 1472 my $string = shift;
348 1472 ▶ return unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 6 1466 1472
349  
350 1466 $string =~ s/%([0-9a-fA-F]{2})/chr hex $1/ge;
351  
352 1466 ▶ Carp::croak 'Invalid PURL: invalid UTF-8 encoding' unless utf8::decode($string);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::decode($string) 1 1465 1466
353 1465 return $string;
354  
355 }
356  
357 10 1;
358  
359 __END__
« VersionRange/Util.pm ↑ Summary PackageURL/Util.pm »