VersionRange/Constraint.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 90.0% 9 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 93.3% 14 / 15 Podpod 100% 7 / 7 totaltotal 93.9% 77 / 82 CC 7 SCAR 6.9
CC
7
Cov
95%
from_string
4.0
to_string
3.0
new
2.0
CRAP 2.0
« VersionRange.pm ↑ Summary VersionRange/Version.pm »
1 package URI::VersionRange::Constraint;
2  
3 4 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use overload '""' => 'to_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use URI::VersionRange::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 our $VERSION = '2.25';
16  
17 4 our %COMPARATOR = (
18 '=' => 'equal',
19 '<' => 'less than',
20 '<=' => 'less than or equal',
21 '>' => 'greater than',
22 '>=' => 'greater than or equal',
23 );
24  
25 1156 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
26  
27 1156 my ($class, %params) = @_;
28  
29 1156 ▶ my $comparator = delete $params{comparator} // '=';
Condition50%1/2
delete $params{"comparator"} // "="
l!l
11560
MC/DC0%0/1
delete $params{"comparator"} // "="
delete $params{"comparator"}
Truth table50%1/2
A
A= delete $params{"comparator"}
Aresult
11
00
30 1156 my $version = delete $params{version};
31  
32 1156 my $self = {comparator => $comparator, version => $version};
33  
34 1156 return bless $self, $class;
35 }
36  
37 4459 ▶sub version { shift->{version} }
Subroutine version: called CC=1 SCAR=0.0
Pod documented
38 6930 ▶sub comparator { shift->{comparator} }
Subroutine comparator: called CC=1 SCAR=0.0
Pod documented
39  
40 1153 ▶sub from_string {
Subroutine from_string: called CC=4 SCAR=13.9
Pod documented
41  
42 1153 my ($class, $string) = @_;
43  
44 1153 ▶ Carp::croak 'Empty version' unless $string;
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 1153 1153
45  
46 # - For each <version-constraint>:
47 # - Determine if the <version-constraint> starts with one of the two comparators:
48 # - If it starts with ">=", then the comparator is ">=".
49 # - If it starts with "<=", then the comparator is "<=".
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 # - Remove the comparator from <version-constraint> string start. The remaining string is the version.
54 # - Otherwise the version is the full <version-constraint> string (which implies an equality comparator of "=")
55 # - Tools should validate and report an error if the version is empty.
56 # - If the version contains a percent "%" character, apply URL quoting rules to unquote this string.
57  
58 1153 ▶ if ($string =~ /^(>=|<=|!=|<|>)(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^(>=|<=|!=|<|>)(.*)/) 1013 140 1153
59 1013 my ($comparator, $version) = ($1, $2);
60 1013 return $class->new(comparator => $comparator, version => $version);
61 }
62  
63 140 ▶ return $class->new(comparator => '*') if ($string eq '*');
Branch: 1 branch
BranchTrueFalseTotal
if $string eq "*" 18 122 140
64  
65 122 return $class->new(comparator => '=', version => $string);
66  
67 }
68  
69 2269 ▶sub to_string {
Subroutine to_string: called CC=3 SCAR=11.0
Pod documented
70  
71 2269 my $self = shift;
72  
73 2269 ▶ return '*' if $self->comparator eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $self->comparator eq "*" 5 2264 2269
74  
75 2264 ▶ return $self->version if $self->comparator eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if $self->comparator eq "=" 234 2030 2264
76  
77 2030 return join '', $self->comparator, $self->version;
78  
79 }
80  
81 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
82  
83 3 ▶sub TO_JSON { {version => $_[0]->version, comparator => $_[0]->comparator} }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
84  
85 4 1;
86  
87 __END__
« VersionRange.pm ↑ Summary VersionRange/Version.pm »