| 1 | package URI::VersionRange::Constraint; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use feature ':5.10'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use overload '""' => 'to_string', fallback => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use URI::VersionRange::Version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 15 | our $VERSION = '2.26'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 15 | our %COMPARATOR = ( | |||||||||||||||||||||||||||
| 18 | '=' => 'equal', | ||||||||||||||||||||||||||||
| 19 | '<' => 'less than', | ||||||||||||||||||||||||||||
| 20 | '<=' => 'less than or equal', | ||||||||||||||||||||||||||||
| 21 | '>' => 'greater than', | ||||||||||||||||||||||||||||
| 22 | '>=' => 'greater than or equal', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 15 | my $PERCENT_ENCODE_REGEX = qr{[><=!*|% \x80-\xFF]}; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 8296 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 8296 | my ($class, %params) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 8296 | ▶ | my $comparator = delete $params{comparator} // '='; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{"comparator"} // "="
MC/DC100%1/1
delete $params{"comparator"} // "="
delete $params{"comparator"}
Truth table100%2/2
A
A= delete $params{"comparator"}
| |||||||||||||||||||||||||||||
| 32 | 8296 | my $version = delete $params{version}; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8296 | my $self = {comparator => $comparator, version => $version}; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8296 | return bless $self, $class; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 22258 | ▶ | sub version { shift->{version} } | ||||||||||||||||||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 21306 | ▶ | sub comparator { shift->{comparator} } | ||||||||||||||||||||||||||
|
Subroutine
comparator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8300 | ▶ | sub from_string { | ||||||||||||||||||||||||||
|
Subroutine
from_string: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 8300 | my ($class, $string) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 8300 | ▶ | Carp::croak 'Invalid constraint: empty version' unless defined $string && length $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $string and length $string
MC/DC50%1/2
defined $string and length $string
defined $string
length $string
Truth table66%2/3
A and B
A= defined $stringB= length $string
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # - For each <version-constraint>: | ||||||||||||||||||||||||||||
| 49 | # - Determine if the <version-constraint> starts with one of the two comparators: | ||||||||||||||||||||||||||||
| 50 | # - If it starts with ">=", then the comparator is ">=". | ||||||||||||||||||||||||||||
| 51 | # - If it starts with "<=", then the comparator is "<=". | ||||||||||||||||||||||||||||
| 52 | # - If it starts with "!=", then the comparator is "!=". | ||||||||||||||||||||||||||||
| 53 | # - If it starts with "<", then the comparator is "<". | ||||||||||||||||||||||||||||
| 54 | # - If it starts with ">", then the comparator is ">". | ||||||||||||||||||||||||||||
| 55 | # - Remove the comparator from <version-constraint> string start. The remaining string is the version. | ||||||||||||||||||||||||||||
| 56 | # - Otherwise the version is the full <version-constraint> string (which implies an equality comparator of "=") | ||||||||||||||||||||||||||||
| 57 | # - Tools should validate and report an error if the version is empty. | ||||||||||||||||||||||||||||
| 58 | # - If the version contains a percent "%" character, apply URL quoting rules to unquote this string. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 8299 | ▶ | if ($string =~ /^(>=|<=|!=|<|>|=)(.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 1056 | my ($comparator, $version) = ($1, $2); | |||||||||||||||||||||||||||
| 62 | 1056 | $version =~ s/^\s+//; | |||||||||||||||||||||||||||
| 63 | 1056 | ▶ | Carp::croak 'Invalid constraint: empty version' unless length $version; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 1055 | return $class->new(comparator => $comparator, version => _percent_decode($version)); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 7243 | ▶ | return $class->new(comparator => '*') if ($string eq '*'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 7219 | $string =~ s/^\s+//; | |||||||||||||||||||||||||||
| 70 | 7219 | return $class->new(comparator => '=', version => _percent_decode($string)); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 9396 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 9396 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 9396 | ▶ | return '*' if $self->comparator eq '*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 9391 | ▶ | return _percent_encode($self->version) if $self->comparator eq '='; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2056 | return join '', $self->comparator, _percent_encode($self->version); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub to_human_string { sprintf '%s %s', $COMPARATOR{$_[0]->comparator}, $_[0]->version } | ||||||||||||||||||||||||||
|
Subroutine
to_human_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 3 | ▶ | sub TO_JSON { {version => $_[0]->version, comparator => $_[0]->comparator} } | ||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 9419 | ▶ | sub _percent_encode { | ||||||||||||||||||||||||||
|
Subroutine
_percent_encode: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 9419 | my $string = shift; | |||||||||||||||||||||||||||
| 93 | 9419 | utf8::encode($string); | |||||||||||||||||||||||||||
| 94 | 9419 | $string =~ s/($PERCENT_ENCODE_REGEX)/sprintf '%%%02X', ord $1/ge; | |||||||||||||||||||||||||||
| 95 | 9419 | return $string; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 8274 | ▶ | sub _percent_decode { | ||||||||||||||||||||||||||
|
Subroutine
_percent_decode: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 8274 | my $string = shift; | |||||||||||||||||||||||||||
| 102 | 8274 | ▶ | return $string unless $string =~ /%/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 34 | ▶ | Carp::croak "Invalid percent-encoding in version '$string'" if $string =~ /%(?![0-9A-F]{2})/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 29 | my $version = $string; | |||||||||||||||||||||||||||
| 107 | 29 | $version =~ s/%([0-9A-F]{2})/chr hex $1/ge; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 29 | ▶ | Carp::croak "Invalid UTF-8 encoding in version '$string'" unless utf8::decode($version); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 28 | ▶ | Carp::croak "Non-canonical percent-encoding in version '$string'" if _percent_encode($version) ne $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 23 | return $version; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 15 | 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||