Requirements/Range.pm

filter: Statementstmt 95.9% 214 / 223 Branchbran 83.3% 90 / 108 Conditioncond 76.0% 54 / 71 MC/DCmcdc 52.6% 20 / 38 Subroutinesub 94.8% 37 / 39 Podpod 100% 8 / 8 totaltotal 86.8% 423 / 487 CC 85 SCAR 22.1
CC
85
Cov
89%
_version_object
30.9
_simplify
12.0
with_string_requirement
9.0
CRAP 9.2
↑ Summary Requirements.pm »
1 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package CPAN::Meta::Requirements::Range;
5 # ABSTRACT: a set of version requirements for a CPAN dist
6  
7 11 our $VERSION = '2.142';
8  
9 11 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #pod =head1 SYNOPSIS
12 #pod
13 #pod use CPAN::Meta::Requirements::Range;
14 #pod
15 #pod my $range = CPAN::Meta::Requirements::Range->with_minimum(1);
16 #pod
17 #pod $range = $range->with_maximum('v2.2');
18 #pod
19 #pod my $stringified = $range->as_string;
20 #pod
21 #pod =head1 DESCRIPTION
22 #pod
23 #pod A CPAN::Meta::Requirements::Range object models a set of version constraints like
24 #pod those specified in the F<META.yml> or F<META.json> files in CPAN distributions,
25 #pod and as defined by L<CPAN::Meta::Spec>;
26 #pod It can be built up by adding more and more constraints, and it will reduce them
27 #pod to the simplest representation.
28 #pod
29 #pod Logically impossible constraints will be identified immediately by thrown
30 #pod exceptions.
31 #pod
32 #pod =cut
33  
34 11 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 package
37 CPAN::Meta::Requirements::Range::_Base;
38  
39 # To help ExtUtils::MakeMaker bootstrap CPAN::Meta::Requirements on perls
40 # before 5.10, we fall back to the EUMM bundled compatibility version module if
41 # that's the only thing available. This shouldn't ever happen in a normal CPAN
42 # install of CPAN::Meta::Requirements, as version.pm will be picked up from
43 # prereqs and be available at runtime.
44  
45 BEGIN {
46 11 ▶ eval "use version ()"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
47 11 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 11 11
48 0 ▶ eval "use ExtUtils::MakeMaker::version" or die $err; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
eval "use ExtUtils::MakeMaker::version" or die $err 0 0 0
49 }
50 }
51  
52 # from version::vpp
53 sub _find_magic_vstring {
54 1360 ▶ my $value = shift;
Subroutine _find_magic_vstring: called CC=4 SCAR=13.9
55 1360 my $tvalue = '';
56 1360 require B;
57 1360 my $sv = B::svref_2object(\$value);
58 1360 ▶ my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sv eq 'B::PVMG' ? : 2 1358 1360
59 1360 ▶ while ( $magic ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic) 1 1359 1360
60 1 ▶ if ( $magic->TYPE eq 'V' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic->TYPE eq 'V') { } 1 0 1
61 1 $tvalue = $magic->PTR;
62 1 $tvalue =~ s/^v?(.+)$/v$1/;
63 1 last;
64 }
65 else {
66 0 $magic = $magic->MOREMAGIC;
67 }
68 }
69 1360 return $tvalue;
70 }
71  
72 # Perl 5.10.0 didn't have "is_qv" in version.pm
73 210 ▶*_is_qv = version->can('is_qv') ? sub { $_[0]->is_qv } : sub { exists $_[0]->{qv} };
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
'version'->can('is_qv') ? : 11 0 11
74  
75 # construct once, reuse many times
76 11 my $V0 = version->new(0);
77  
78 # safe if given an unblessed reference
79 sub _isa_version {
80 0 ▶ UNIVERSAL::isa( $_[0], 'UNIVERSAL' ) && $_[0]->isa('version')
Subroutine _isa_version: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], "UNIVERSAL") and $_[0]->isa("version") 0 0 0
81 }
82  
83 sub _version_object {
84 1726 ▶ my ($self, $version, $module, $bad_version_hook) = @_;
Subroutine _version_object: called CC=20 SCAR=34.3
85  
86 1726 my ($vobj, $err);
87  
88 1726 ▶ if (not defined $version or (!ref($version) && $version eq '0')) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $version or not ref $version and $version eq '0') { } 1129 597 1726
elsif (ref $version eq 'version' or ref $version and _isa_version($version)) { } 271 326 597
Condition83%5/6
not defined $version or not ref $version and $version eq 0
l!l&&r!l&&!r
01129597
not ref $version and $version eq 0
!ll&&!rl&&r
2713261129
MC/DC66%2/3
not defined $version or not ref $version and $version eq 0
not defined $version not ref $version $version eq 0
Truth table75%3/4
not(A) or not(B) and C
A= not defined $versionB= not ref $versionC= $version eq 0
ABCresult
1XX1
0111
00X0
0100
89 1129 return $V0;
90 }
91 ▶ elsif ( ref($version) eq 'version' || ( ref($version) && _isa_version($version) ) ) {
Condition50%3/6
ref $version eq "version" or ref $version and _isa_version($version)
l!l&&r!l&&!r
2710326
ref $version and _isa_version($version)
!ll&&!rl&&r
32600
MC/DC33%1/3
ref $version eq "version" or ref $version and _isa_version($version)
ref $version eq "version" ref $version _isa_version($version)
Truth table50%2/4
A or B and C
A= ref $version eq "version"B= ref $versionC= _isa_version($version)
ABCresult
1XX1
0111
00X0
0100
92 271 $vobj = $version;
93 }
94 else {
95 # hack around version::vpp not handling <3 character vstring literals
96 326 ▶ if ( $INC{'version/vpp.pm'} || $INC{'ExtUtils/MakeMaker/version/vpp.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"version/vpp.pm"} or $INC{"ExtUtils/MakeMaker/version/vpp.pm"}) 0 326 326
Condition33%1/3
$INC{"version/vpp.pm"} or $INC{"ExtUtils/MakeMaker/version/vpp.pm"}
l!l&&r!l&&!r
00326
MC/DC0%0/2
$INC{"version/vpp.pm"} or $INC{"ExtUtils/MakeMaker/version/vpp.pm"}
$INC{"version/vpp.pm"} $INC{"ExtUtils/MakeMaker/version/vpp.pm"}
Truth table33%1/3
A or B
A= $INC{"version/vpp.pm"}B= $INC{"ExtUtils/MakeMaker/version/vpp.pm"}
ABresult
1X1
011
000
97 0 my $magic = _find_magic_vstring( $version );
98 0 ▶ $version = $magic if length $magic;
Branch: 1 branch
BranchTrueFalseTotal
if length $magic 0 0 0
99 }
100 # pad to 3 characters if before 5.8.1 and appears to be a v-string
101 326 ▶ if ( $] < 5.008001 && $version !~ /\A[0-9]/ && substr($version,0,1) ne 'v' && length($version) < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.008001" and not $version =~ /\A[0-9]/ and substr($version, 0, 1) ne "v" and length $version < 3) 0 326 326
Condition33%3/9
$] < "5.008001" and not $version =~ /\A[0-9]/ and substr($version, 0, 1) ne "v" and length $version < 3
!ll&&!rl&&r
32600
$] < "5.008001" and not $version =~ /\A[0-9]/ and substr($version, 0, 1) ne "v"
!ll&&!rl&&r
32600
$] < "5.008001" and not $version =~ /\A[0-9]/
!ll&&!rl&&r
32600
MC/DC0%0/4
$] < "5.008001" and not $version =~ /\A[0-9]/ and substr($version, 0, 1) ne "v" and length $version < 3
$] < "5.008001" not $version =~ /\A[0-9]/ substr($version, 0, 1) ne "v" length $version < 3
Truth table20%1/5
A and not(B) and C and D
A= $] < "5.008001"B= not $version =~ /\A[0-9]/C= substr($version, 0, 1) ne "v"D= length $version < 3
ABCDresult
0XXX0
10XX0
110X0
11100
11111
102 0 $version .= "\0" x (3 - length($version));
103 }
104 326 eval {
105 326 ▶ local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
106 # avoid specific segfault on some older version.pm versions
107 326 ▶ die "Invalid version: $version" if $version eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "version" 1 325 326
108 325 $vobj = version->new($version);
109 };
110 326 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 6 320 326
111 6 ▶ $vobj = eval { $bad_version_hook->($version, $module) }
Branch: 1 branch
BranchTrueFalseTotal
if ref $bad_version_hook eq "CODE" 4 2 6
112 if ref $bad_version_hook eq 'CODE';
113 6 ▶ unless (eval { $vobj->isa("version") }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $vobj->isa("version") } }) 3 3 6
114 3 $err =~ s{ at .* line \d+.*$}{};
115 3 die "Can't convert '$version': $err";
116 }
117 }
118 }
119  
120 # ensure no leading '.'
121 594 ▶ if ( $vobj =~ m{\A\.} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vobj =~ /\A\./) 0 594 594
122 0 $vobj = version->new("0$vobj");
123 }
124  
125 # ensure normal v-string form
126 594 ▶ if ( _is_qv($vobj) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_qv($vobj)) 21 573 594
127 21 $vobj = version->new($vobj->normal);
128 }
129  
130 594 return $vobj;
131 }
132  
133 #pod =method with_string_requirement
134 #pod
135 #pod $req->with_string_requirement('>= 1.208, <= 2.206');
136 #pod $req->with_string_requirement(v1.208);
137 #pod
138 #pod This method parses the passed in string and adds the appropriate requirement.
139 #pod A version can be a Perl "v-string". It understands version ranges as described
140 #pod in the L<CPAN::Meta::Spec/Version Ranges>. For example:
141 #pod
142 #pod =over 4
143 #pod
144 #pod =item 1.3
145 #pod
146 #pod =item >= 1.3
147 #pod
148 #pod =item <= 1.3
149 #pod
150 #pod =item == 1.3
151 #pod
152 #pod =item != 1.3
153 #pod
154 #pod =item > 1.3
155 #pod
156 #pod =item < 1.3
157 #pod
158 #pod =item >= 1.3, != 1.5, <= 2.0
159 #pod
160 #pod A version number without an operator is equivalent to specifying a minimum
161 #pod (C<E<gt>=>). Extra whitespace is allowed.
162 #pod
163 #pod =back
164 #pod
165 #pod =cut
166  
167 11 my %methods_for_op = (
168 '==' => [ qw(with_exact_version) ],
169 '!=' => [ qw(with_exclusion) ],
170 '>=' => [ qw(with_minimum) ],
171 '<=' => [ qw(with_maximum) ],
172 '>' => [ qw(with_minimum with_exclusion) ],
173 '<' => [ qw(with_maximum with_exclusion) ],
174 );
175  
176 sub with_string_requirement {
177 1360 ▶ my ($self, $req, $module, $bad_version_hook) = @_;
Subroutine with_string_requirement: called CC=9 SCAR=22.0
178 1360 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
135010
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
179  
180 1360 ▶ unless ( defined $req && length $req ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $req and length $req) 4 1356 1360
Condition100%3/3
defined $req and length $req
!ll&&!rl&&r
221356
MC/DC100%2/2
defined $req and length $req
defined $req length $req
Truth table100%3/3
A and B
A= defined $reqB= length $req
ABresult
0X0
100
111
181 4 $req = 0;
182 4 Carp::carp("Undefined requirement for $module treated as '0'");
183 }
184  
185 1360 my $magic = _find_magic_vstring( $req );
186 1360 ▶ if (length $magic) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $magic) 1 1359 1360
187 1 return $self->with_minimum($magic, $module, $bad_version_hook);
188 }
189  
190 1359 my @parts = split qr{\s*,\s*}, $req;
191  
192 1359 for my $part (@parts) {
193 1367 my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z};
194  
195 1367 ▶ if (! defined $op) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $op) { } 1345 22 1367
196 1345 return $self->with_minimum($part, $module, $bad_version_hook);
197 } else {
198 Carp::croak("illegal requirement string: $req")
199 22 ▶ unless my $methods = $methods_for_op{ $op };
Branch: 1 branch
BranchTrueFalseTotal
unless my $methods = $methods_for_op{$op} 0 22 22
200  
201 22 $self = $self->$_($ver, $module, $bad_version_hook) for @$methods;
202 }
203 }
204  
205 14 return $self;
206 }
207  
208 #pod =method with_range
209 #pod
210 #pod $range->with_range($other_range)
211 #pod
212 #pod This creates a new range object that is a merge two others.
213 #pod
214 #pod =cut
215  
216 sub with_range {
217 266 ▶ my ($self, $other, $module, $bad_version_hook) = @_;
Subroutine with_range: called CC=2 SCAR=6.9
218 266 for my $modifier($other->_as_modifiers) {
219 269 my ($method, $arg) = @$modifier;
220 269 $self = $self->$method($arg, $module, $bad_version_hook);
221 }
222 266 return $self;
223 }
224  
225 package CPAN::Meta::Requirements::Range;
226  
227 11 our @ISA = 'CPAN::Meta::Requirements::Range::_Base';
228  
229 sub _clone {
230 1715 ▶ return (bless { } => $_[0]) unless ref $_[0];
Subroutine _clone: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 1590 125 1715
231  
232 125 my ($s) = @_;
233 my %guts = (
234 (exists $s->{minimum} ? (minimum => version->new($s->{minimum})) : ()),
235 (exists $s->{maximum} ? (maximum => version->new($s->{maximum})) : ()),
236  
237 (exists $s->{exclusions}
238 125 ▶ ? (exclusions => [ map { version->new($_) } @{ $s->{exclusions} } ])
Branch: 3 branches
BranchTrueFalseTotal
exists $s->{'minimum'} ? : 123 2 125
exists $s->{'maximum'} ? : 12 113 125
exists $s->{'exclusions'} ? : 12 113 125
239 : ()),
240 );
241  
242 125 bless \%guts => ref($s);
243 }
244  
245 #pod =method with_exact_version
246 #pod
247 #pod $range->with_exact_version( $version );
248 #pod
249 #pod This sets the version required to I<exactly> the given
250 #pod version. No other version would be considered acceptable.
251 #pod
252 #pod This method returns the version range object.
253 #pod
254 #pod =cut
255  
256 sub with_exact_version {
257 11 ▶ my ($self, $version, $module, $bad_version_hook) = @_;
Subroutine with_exact_version: called CC=3 SCAR=11.0
Pod documented
258 11 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
110
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
259 11 $self = $self->_clone;
260 11 $version = $self->_version_object($version, $module, $bad_version_hook);
261  
262 11 ▶ unless ($self->accepts($version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->accepts($version)) 1 10 11
263 1 $self->_reject_requirements(
264 $module,
265 "exact specification $version outside of range " . $self->as_string
266 );
267 }
268  
269 10 return CPAN::Meta::Requirements::Range::_Exact->_new($version);
270 }
271  
272 sub _simplify {
273 1702 ▶ my ($self, $module) = @_;
Subroutine _simplify: called CC=12 SCAR=24.8
274  
275 1702 ▶ if (defined $self->{minimum} and defined $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"minimum"} and defined $self->{"maximum"}) 27 1675 1702
Condition100%3/3
defined $self->{"minimum"} and defined $self->{"maximum"}
!ll&&!rl&&r
14166127
MC/DC100%2/2
defined $self->{"minimum"} and defined $self->{"maximum"}
defined $self->{"minimum"} defined $self->{"maximum"}
Truth table100%3/3
A and B
A= defined $self->{"minimum"}B= defined $self->{"maximum"}
ABresult
0X0
100
111
276 27 ▶ if ($self->{minimum} == $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"minimum"} == $self->{"maximum"}) 2 25 27
277 2 ▶ if (grep { $_ == $self->{minimum} } @{ $self->{exclusions} || [] }) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_ == $self->{"minimum"};} @{$self->{"exclusions"} or [];}) 1 1 2
$self->{"exclusions"} or [] 1 1 2
278 1 $self->_reject_requirements(
279 $module,
280 "minimum and maximum are both $self->{minimum}, which is excluded",
281 );
282 }
283  
284 1 return CPAN::Meta::Requirements::Range::_Exact->_new($self->{minimum});
285 }
286  
287 25 ▶ if ($self->{minimum} > $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"minimum"} > $self->{"maximum"}) 2 23 25
288 2 $self->_reject_requirements(
289 $module,
290 "minimum $self->{minimum} exceeds maximum $self->{maximum}",
291 );
292 }
293 }
294  
295 # eliminate irrelevant exclusions
296 1698 ▶ if ($self->{exclusions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"exclusions"}) 28 1670 1698
297 28 my %seen;
298 28 @{ $self->{exclusions} } = grep {
299 (! defined $self->{minimum} or $_ >= $self->{minimum})
300 and
301 (! defined $self->{maximum} or $_ <= $self->{maximum})
302 and
303 29 ▶ ! $seen{$_}++
Branch: 1 branch
BranchTrueFalseTotal
!defined($self->{"minimum"}) || $_ >= $self->{"minimum"} and !defined($self->{"maximum"}) || $_ <= $self->{"maximum"} and not $seen{$_}++ 26 3 29
Condition100%9/9
!defined($self->{"minimum"}) || $_ >= $self->{"minimum"} and !defined($self->{"maximum"}) || $_ <= $self->{"maximum"}
!ll&&!rl&&r
2126
not defined $self->{"minimum"} or $_ >= $self->{"minimum"}
l!l&&r!l&&!r
7202
not defined $self->{"maximum"} or $_ <= $self->{"maximum"}
l!l&&r!l&&!r
14121
MC/DC0%0/4
!defined($self->{"minimum"}) || $_ >= $self->{"minimum"} and !defined($self->{"maximum"}) || $_ <= $self->{"maximum"}
not defined $self->{"minimum"} $_ >= $self->{"minimum"} not defined $self->{"maximum"} $_ <= $self->{"maximum"}
Truth table0%0/7
not(A) or B and not(C) or D
A= not defined $self->{"minimum"}B= $_ >= $self->{"minimum"}C= not defined $self->{"maximum"}D= $_ <= $self->{"maximum"}
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
304 28 } @{ $self->{exclusions} };
305 }
306  
307 1698 return $self;
308 }
309  
310 #pod =method with_minimum
311 #pod
312 #pod $range->with_minimum( $version );
313 #pod
314 #pod This adds a new minimum version requirement. If the new requirement is
315 #pod redundant to the existing specification, this has no effect.
316 #pod
317 #pod Minimum requirements are inclusive. C<$version> is required, along with any
318 #pod greater version number.
319 #pod
320 #pod This method returns the version range object.
321 #pod
322 #pod =cut
323  
324 sub with_minimum {
325 1659 ▶ my ($self, $minimum, $module, $bad_version_hook) = @_;
Subroutine with_minimum: called CC=3 SCAR=11.0
Pod documented
326 1659 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
16563
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
327 1659 $self = $self->_clone;
328 1659 $minimum = $self->_version_object( $minimum, $module, $bad_version_hook );
329  
330 1657 ▶ if (defined (my $old_min = $self->{minimum})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old_min = $self->{'minimum'})) { } 91 1566 1657
331 91 $self->{minimum} = (sort { $b cmp $a } ($minimum, $old_min))[0];
332 } else {
333 1566 $self->{minimum} = $minimum;
334 }
335  
336 1657 return $self->_simplify($module);
337 }
338  
339 #pod =method with_maximum
340 #pod
341 #pod $range->with_maximum( $version );
342 #pod
343 #pod This adds a new maximum version requirement. If the new requirement is
344 #pod redundant to the existing specification, this has no effect.
345 #pod
346 #pod Maximum requirements are inclusive. No version strictly greater than the given
347 #pod version is allowed.
348 #pod
349 #pod This method returns the version range object.
350 #pod
351 #pod =cut
352  
353 sub with_maximum {
354 24 ▶ my ($self, $maximum, $module, $bad_version_hook) = @_;
Subroutine with_maximum: called CC=3 SCAR=11.0
Pod documented
355 24 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
222
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
356 24 $self = $self->_clone;
357 24 $maximum = $self->_version_object( $maximum, $module, $bad_version_hook );
358  
359 24 ▶ if (defined (my $old_max = $self->{maximum})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old_max = $self->{'maximum'})) { } 1 23 24
360 1 $self->{maximum} = (sort { $a cmp $b } ($maximum, $old_max))[0];
361 } else {
362 23 $self->{maximum} = $maximum;
363 }
364  
365 24 return $self->_simplify($module);
366 }
367  
368 #pod =method with_exclusion
369 #pod
370 #pod $range->with_exclusion( $version );
371 #pod
372 #pod This adds a new excluded version. For example, you might use these three
373 #pod method calls:
374 #pod
375 #pod $range->with_minimum( '1.00' );
376 #pod $range->with_maximum( '1.82' );
377 #pod
378 #pod $range->with_exclusion( '1.75' );
379 #pod
380 #pod Any version between 1.00 and 1.82 inclusive would be acceptable, except for
381 #pod 1.75.
382 #pod
383 #pod This method returns the requirements object.
384 #pod
385 #pod =cut
386  
387 sub with_exclusion {
388 21 ▶ my ($self, $exclusion, $module, $bad_version_hook) = @_;
Subroutine with_exclusion: called CC=3 SCAR=11.0
Pod documented
389 21 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
192
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
390 21 $self = $self->_clone;
391 21 $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook );
392  
393 21 ▶ push @{ $self->{exclusions} ||= [] }, $exclusion;
Condition100%2/2
$self->{"exclusions"} ||= []
l!l
417
MC/DC100%1/1
$self->{"exclusions"} ||= []
$self->{"exclusions"}
Truth table100%2/2
A
A= $self->{"exclusions"}
Aresult
11
00
394  
395 21 return $self->_simplify($module);
396 }
397  
398 sub _as_modifiers {
399 264 ▶ my ($self) = @_;
Subroutine _as_modifiers: called CC=4 SCAR=13.9
400 264 my @mods;
401 264 ▶ push @mods, [ with_minimum => $self->{minimum} ] if exists $self->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"minimum"} 263 1 264
402 264 ▶ push @mods, [ with_maximum => $self->{maximum} ] if exists $self->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"maximum"} 3 261 264
403 264 ▶ push @mods, map {; [ with_exclusion => $_ ] } @{$self->{exclusions} || []};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"exclusions"} or [] 263 1 264
404 264 return @mods;
405 }
406  
407 #pod =method as_struct
408 #pod
409 #pod $range->as_struct( $module );
410 #pod
411 #pod This returns a data structure containing the version requirements. This should
412 #pod not be used for version checks (see L</accepts_module> instead).
413 #pod
414 #pod =cut
415  
416 sub as_struct {
417 1314 ▶ my ($self) = @_;
Subroutine as_struct: called CC=6 SCAR=17.9
Pod documented
418  
419 1314 ▶ return 0 if ! keys %$self;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$self 0 1314 1314
420  
421 1314 ▶ my @exclusions = @{ $self->{exclusions} || [] };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"exclusions"} or [] 1302 12 1314
422  
423 1314 my @parts;
424  
425 1314 for my $tuple (
426 [ qw( >= > minimum ) ],
427 [ qw( <= < maximum ) ],
428 ) {
429 2628 my ($op, $e_op, $k) = @$tuple;
430 2628 ▶ if (exists $self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$k}) 1326 1302 2628
431 1326 my @new_exclusions = grep { $_ != $self->{ $k } } @exclusions;
432 1326 ▶ if (@new_exclusions == @exclusions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new_exclusions == @exclusions) { } 1325 1 1326
433 1325 push @parts, [ $op, "$self->{ $k }" ];
434 } else {
435 1 push @parts, [ $e_op, "$self->{ $k }" ];
436 1 @exclusions = @new_exclusions;
437 }
438 }
439 }
440  
441 1314 push @parts, map {; [ "!=", "$_" ] } @exclusions;
442  
443 1314 return \@parts;
444 }
445  
446 #pod =method as_string
447 #pod
448 #pod $range->as_string;
449 #pod
450 #pod This returns a string containing the version requirements in the format
451 #pod described in L<CPAN::Meta::Spec>. This should only be used for informational
452 #pod purposes such as error messages and should not be interpreted or used for
453 #pod comparison (see L</accepts> instead).
454 #pod
455 #pod =cut
456  
457 sub as_string {
458 1313 ▶ my ($self) = @_;
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
459  
460 1313 my @parts = @{ $self->as_struct };
461  
462 1313 ▶ return $parts[0][1] if @parts == 1 and $parts[0][0] eq '>=';
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 and $parts[0][0] eq ">=" 1296 17 1313
Condition100%3/3
@parts == 1 and $parts[0][0] eq ">="
!ll&&!rl&&r
1431296
MC/DC100%2/2
@parts == 1 and $parts[0][0] eq ">="
@parts == 1 $parts[0][0] eq ">="
Truth table100%3/3
A and B
A= @parts == 1B= $parts[0][0] eq ">="
ABresult
0X0
100
111
463  
464 17 return join q{, }, map {; join q{ }, @$_ } @parts;
465 }
466  
467 sub _reject_requirements {
468 4 ▶ my ($self, $module, $error) = @_;
Subroutine _reject_requirements: called CC=1 SCAR=0.0
469 4 Carp::croak("illegal requirements for $module: $error")
470 }
471  
472 #pod =method accepts
473 #pod
474 #pod my $bool = $range->accepts($version);
475 #pod
476 #pod Given a version, this method returns true if the version specification
477 #pod accepts the provided version. In other words, given:
478 #pod
479 #pod '>= 1.00, < 2.00'
480 #pod
481 #pod We will accept 1.00 and 1.75 but not 0.50 or 2.00.
482 #pod
483 #pod =cut
484  
485 sub accepts {
486 78 ▶ my ($self, $version) = @_;
Subroutine accepts: called CC=7 SCAR=19.5
Pod documented
487  
488 78 ▶ return if defined $self->{minimum} and $version < $self->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"minimum"} and $version < $self->{"minimum"} 9 69 78
Condition100%3/3
defined $self->{"minimum"} and $version < $self->{"minimum"}
!ll&&!rl&&r
30399
MC/DC100%2/2
defined $self->{"minimum"} and $version < $self->{"minimum"}
defined $self->{"minimum"} $version < $self->{"minimum"}
Truth table100%3/3
A and B
A= defined $self->{"minimum"}B= $version < $self->{"minimum"}
ABresult
0X0
100
111
489 69 ▶ return if defined $self->{maximum} and $version > $self->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"maximum"} and $version > $self->{"maximum"} 6 63 69
Condition100%3/3
defined $self->{"maximum"} and $version > $self->{"maximum"}
!ll&&!rl&&r
53106
MC/DC100%2/2
defined $self->{"maximum"} and $version > $self->{"maximum"}
defined $self->{"maximum"} $version > $self->{"maximum"}
Truth table100%3/3
A and B
A= defined $self->{"maximum"}B= $version > $self->{"maximum"}
ABresult
0X0
100
111
490 return if defined $self->{exclusions}
491 63 ▶ and grep { $version == $_ } @{ $self->{exclusions} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};} 6 57 63
Condition100%3/3
defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};}
!ll&&!rl&&r
4986
MC/DC100%2/2
defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};}
defined $self->{"exclusions"} grep {$version == $_;} @{$$self{"exclusions"};}
Truth table100%3/3
A and B
A= defined $self->{"exclusions"}B= grep {$version == $_;} @{$$self{"exclusions"};}
ABresult
0X0
100
111
492  
493 57 return 1;
494 }
495  
496 #pod =method is_simple
497 #pod
498 #pod This method returns true if and only if the range is an inclusive minimum
499 #pod -- that is, if their string expression is just the version number.
500 #pod
501 #pod =cut
502  
503 sub is_simple {
504 4 ▶ my ($self) = @_;
Subroutine is_simple: called CC=2 SCAR=6.9
Pod documented
505 # XXX: This is a complete hack, but also entirely correct.
506 4 ▶ return if $self->as_string =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->as_string =~ /\s/ 1 3 4
507  
508 3 return 1;
509 }
510  
511 package
512 CPAN::Meta::Requirements::Range::_Exact;
513  
514 11 our @ISA = 'CPAN::Meta::Requirements::Range::_Base';
515  
516 11 our $VERSION = '2.141';
517  
518 BEGIN {
519 11 ▶ eval "use version ()"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
520 11 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 11 11
521 0 ▶ eval "use ExtUtils::MakeMaker::version" or die $err; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
eval "use ExtUtils::MakeMaker::version" or die $err 0 0 0
522 }
523 }
524  
525 17 ▶sub _new { bless { version => $_[1] } => $_[0] }
Subroutine _new: called CC=1 SCAR=0.0
526  
527 9 ▶sub accepts { return $_[0]{version} == $_[1] }
Subroutine accepts: called CC=1 SCAR=0.0
528  
529 sub _reject_requirements {
530 4 ▶ my ($self, $module, $error) = @_;
Subroutine _reject_requirements: called CC=1 SCAR=0.0
531 4 Carp::croak("illegal requirements for $module: $error")
532 }
533  
534 sub _clone {
535 6 ▶ (ref $_[0])->_new( version->new( $_[0]{version} ) )
Subroutine _clone: called CC=1 SCAR=0.0
536 }
537  
538 sub with_exact_version {
539 3 ▶ my ($self, $version, $module, $bad_version_hook) = @_;
Subroutine with_exact_version: called CC=3 SCAR=11.0
540 3 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
30
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
541 3 $version = $self->_version_object($version, $module, $bad_version_hook);
542  
543 3 ▶ return $self->_clone if $self->accepts($version);
Branch: 1 branch
BranchTrueFalseTotal
if $self->accepts($version) 2 1 3
544  
545 1 $self->_reject_requirements(
546 $module,
547 "can't be exactly $version when exact requirement is already $self->{version}",
548 );
549 }
550  
551 sub with_minimum {
552 2 ▶ my ($self, $minimum, $module, $bad_version_hook) = @_;
Subroutine with_minimum: called CC=3 SCAR=11.3
553 2 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
20
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
554 2 $minimum = $self->_version_object( $minimum, $module, $bad_version_hook );
555  
556 1 ▶ return $self->_clone if $self->{version} >= $minimum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} >= $minimum 0 1 1
557 1 $self->_reject_requirements(
558 $module,
559 "minimum $minimum exceeds exact specification $self->{version}",
560 );
561 }
562  
563 sub with_maximum {
564 3 ▶ my ($self, $maximum, $module, $bad_version_hook) = @_;
Subroutine with_maximum: called CC=3 SCAR=11.0
565 3 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
30
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
566 3 $maximum = $self->_version_object( $maximum, $module, $bad_version_hook );
567  
568 3 ▶ return $self->_clone if $self->{version} <= $maximum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} <= $maximum 2 1 3
569 1 $self->_reject_requirements(
570 $module,
571 "maximum $maximum below exact specification $self->{version}",
572 );
573 }
574  
575 sub with_exclusion {
576 3 ▶ my ($self, $exclusion, $module, $bad_version_hook) = @_;
Subroutine with_exclusion: called CC=3 SCAR=11.0
577 3 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
30
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
578 3 $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook );
579  
580 3 ▶ return $self->_clone unless $exclusion == $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $exclusion == $self->{"version"} 2 1 3
581 1 $self->_reject_requirements(
582 $module,
583 "tried to exclude $exclusion, which is already exactly specified",
584 );
585 }
586  
587 7 ▶sub as_string { return "== $_[0]{version}" }
Subroutine as_string: called CC=1 SCAR=0.0
588  
589 1 ▶sub as_struct { return [ [ '==', "$_[0]{version}" ] ] }
Subroutine as_struct: called CC=1 SCAR=0.0
590  
591 2 ▶sub _as_modifiers { return [ with_exact_version => $_[0]{version} ] }
Subroutine _as_modifiers: called CC=1 SCAR=0.0
592  
593  
594 11 1;
595  
596 # vim: ts=2 sts=2 sw=2 et:
597  
598 __END__
↑ Summary Requirements.pm »