Requirements/Range.pm

filter: Statementstmt 95.9% 214 / 223 Branchbran 82.6% 81 / 98 Conditioncond 85.1% 63 / 74 MC/DCmcdc 75.0% 30 / 40 Subroutinesub 92.5% 37 / 40 Podpod 100% 8 / 8 totaltotal 89.6% 433 / 483 CC 82 SCAR 19.2
CC
82
Cov
91%
_version_object
19.3
_simplify
12.0
with_string_requirement
9.0
CRAP 6.8
↑ 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.145';
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 11 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.7
46 11 ▶ eval "use version ()"; ## no critic
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 1367 ▶sub _find_magic_vstring {
Subroutine _find_magic_vstring: called CC=4 SCAR=13.9
54 1367 my $value = shift;
55 1367 my $tvalue = '';
56 1367 require B;
57 1367 my $sv = B::svref_2object(\$value);
58 1367 ▶ my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sv eq 'B::PVMG' ? : 4 1363 1367
59 1367 ▶ while ( $magic ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic) 1 1366 1367
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 1367 return $tvalue;
70 }
71  
72 # Perl 5.10.0 didn't have "is_qv" in version.pm
73 0 ▶*_is_qv = version->can('is_qv') ? sub { $_[0]->is_qv } : sub { exists $_[0]->{qv} };
Subroutine __ANON__: called CC=1 SCAR=0.6
Subroutine __ANON__: not called CC=1 SCAR=0.6
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 0 ▶sub _isa_version {
Subroutine _isa_version: not called CC=2 SCAR=17.9
80 0 ▶ UNIVERSAL::isa( $_[0], 'UNIVERSAL' ) && $_[0]->isa('version')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], "UNIVERSAL") and $_[0]->isa("version") 0 0 0
81 }
82  
83 1739 ▶sub _version_object {
Subroutine _version_object: called CC=16 SCAR=29.6
84 1739 my ($self, $version, $module, $bad_version_hook) = @_;
85  
86 1739 my ($vobj, $err);
87  
88 1739 ▶ 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') { } 1131 608 1739
elsif (ref $version eq 'version' or ref $version and _isa_version($version)) { } 271 337 608
Condition83%5/6
not defined $version or not ref $version and $version eq 0
l!l&&r!l&&!r
01131608
not ref $version and $version eq 0
!ll&&!rl&&r
2713371131
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 1131 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
2710337
ref $version and _isa_version($version)
!ll&&!rl&&r
33700
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 337 ▶ 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 337 337
Condition33%1/3
$INC{"version/vpp.pm"} or $INC{"ExtUtils/MakeMaker/version/vpp.pm"}
l!l&&r!l&&!r
00337
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 337 eval {
101 0 ▶ local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
102 # avoid specific segfault on some older version.pm versions
103 337 ▶ die "Invalid version: $version" if $version eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "version" 1 336 337
104 336 $vobj = version->new($version);
105 };
106 337 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 6 331 337
107 6 ▶ $vobj = eval { $bad_version_hook->($version, $module) }
Branch: 1 branch
BranchTrueFalseTotal
if ref $bad_version_hook eq "CODE" 4 2 6
108 if ref $bad_version_hook eq 'CODE';
109 6 ▶ unless (eval { $vobj->isa("version") }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $vobj->isa("version") } }) 3 3 6
110 3 $err =~ s{ at .* line \d+.*$}{};
111 3 die "Can't convert '$version': $err";
112 }
113 }
114 }
115  
116 # ensure no leading '.'
117 605 ▶ if ( $vobj =~ m{\A\.} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vobj =~ /\A\./) 0 605 605
118 0 $vobj = version->new("0$vobj");
119 }
120  
121 # ensure normal v-string form
122 605 ▶ if ( _is_qv($vobj) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_qv($vobj)) 22 583 605
123 22 $vobj = version->new($vobj->normal);
124 }
125  
126 605 return $vobj;
127 }
128  
129 #pod =method with_string_requirement
130 #pod
131 #pod $req->with_string_requirement('>= 1.208, <= 2.206');
132 #pod $req->with_string_requirement(v1.208);
133 #pod
134 #pod This method parses the passed in string and adds the appropriate requirement.
135 #pod A version can be a Perl "v-string". It understands version ranges as described
136 #pod in the L<CPAN::Meta::Spec/Version Ranges>. For example:
137 #pod
138 #pod =over 4
139 #pod
140 #pod =item 1.3
141 #pod
142 #pod =item >= 1.3
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, != 1.5, <= 2.0
155 #pod
156 #pod A version number without an operator is equivalent to specifying a minimum
157 #pod (C<E<gt>=>). Extra whitespace is allowed.
158 #pod
159 #pod =back
160 #pod
161 #pod =cut
162  
163 11 my %methods_for_op = (
164 '==' => [ qw(with_exact_version) ],
165 '!=' => [ qw(with_exclusion) ],
166 '>=' => [ qw(with_minimum) ],
167 '<=' => [ qw(with_maximum) ],
168 '>' => [ qw(with_minimum with_exclusion) ],
169 '<' => [ qw(with_maximum with_exclusion) ],
170 );
171  
172 1367 ▶sub with_string_requirement {
Subroutine with_string_requirement: called CC=9 SCAR=22.0
173 1367 my ($self, $req, $module, $bad_version_hook) = @_;
174 1367 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
135314
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
175  
176 1367 ▶ unless ( defined $req && length $req ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $req and length $req) 4 1363 1367
Condition100%3/3
defined $req and length $req
!ll&&!rl&&r
221363
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
177 4 $req = 0;
178 4 Carp::carp("Undefined requirement for $module treated as '0'");
179 }
180  
181 1367 my $magic = _find_magic_vstring( $req );
182 1367 ▶ if (length $magic) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $magic) 1 1366 1367
183 1 return $self->with_minimum($magic, $module, $bad_version_hook);
184 }
185  
186 1366 my @parts = split qr{\s*,\s*}, $req;
187  
188 1366 for my $part (@parts) {
189 1378 my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z};
190  
191 1378 ▶ if (! defined $op) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $op) { } 1351 27 1378
192 1351 $self = $self->with_minimum($part, $module, $bad_version_hook);
193 } else {
194 Carp::croak("illegal requirement string: $req")
195 27 ▶ unless my $methods = $methods_for_op{ $op };
Branch: 1 branch
BranchTrueFalseTotal
unless my $methods = $methods_for_op{$op} 0 27 27
196  
197 27 $self = $self->$_($ver, $module, $bad_version_hook) for @$methods;
198 }
199 }
200  
201 1364 return $self;
202 }
203  
204 #pod =method with_range
205 #pod
206 #pod $range->with_range($other_range)
207 #pod
208 #pod This creates a new range object that is a merge two others.
209 #pod
210 #pod =cut
211  
212 266 ▶sub with_range {
Subroutine with_range: called CC=2 SCAR=6.9
213 266 my ($self, $other, $module, $bad_version_hook) = @_;
214 266 for my $modifier($other->_as_modifiers) {
215 269 my ($method, $arg) = @$modifier;
216 269 $self = $self->$method($arg, $module, $bad_version_hook);
217 }
218 266 return $self;
219 }
220  
221 package CPAN::Meta::Requirements::Range;
222  
223 11 our @ISA = 'CPAN::Meta::Requirements::Range::_Base';
224  
225 1728 ▶sub _clone {
Subroutine _clone: called CC=5 SCAR=16.1
226 1728 ▶ return (bless { } => $_[0]) unless ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 1597 131 1728
227  
228 131 my ($s) = @_;
229 my %guts = (
230 (exists $s->{minimum} ? (minimum => version->new($s->{minimum})) : ()),
231 (exists $s->{maximum} ? (maximum => version->new($s->{maximum})) : ()),
232  
233 (exists $s->{exclusions}
234 131 ▶ ? (exclusions => [ map { version->new($_) } @{ $s->{exclusions} } ])
Branch: 3 branches
BranchTrueFalseTotal
exists $s->{'minimum'} ? : 129 2 131
exists $s->{'maximum'} ? : 14 117 131
exists $s->{'exclusions'} ? : 12 119 131
235 : ()),
236 );
237  
238 131 bless \%guts => ref($s);
239 }
240  
241 #pod =method with_exact_version
242 #pod
243 #pod $range->with_exact_version( $version );
244 #pod
245 #pod This sets the version required to I<exactly> the given
246 #pod version. No other version would be considered acceptable.
247 #pod
248 #pod This method returns the version range object.
249 #pod
250 #pod =cut
251  
252 11 ▶sub with_exact_version {
Subroutine with_exact_version: called CC=3 SCAR=11.0
Pod documented
253 11 my ($self, $version, $module, $bad_version_hook) = @_;
254 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
255 11 $self = $self->_clone;
256 11 $version = $self->_version_object($version, $module, $bad_version_hook);
257  
258 11 ▶ unless ($self->accepts($version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->accepts($version)) 1 10 11
259 1 $self->_reject_requirements(
260 $module,
261 "exact specification $version outside of range " . $self->as_string
262 );
263 }
264  
265 10 return CPAN::Meta::Requirements::Range::_Exact->_new($version);
266 }
267  
268 1715 ▶sub _simplify {
Subroutine _simplify: called CC=12 SCAR=24.8
269 1715 my ($self, $module) = @_;
270  
271 1715 ▶ if (defined $self->{minimum} and defined $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"minimum"} and defined $self->{"maximum"}) 31 1684 1715
Condition100%3/3
defined $self->{"minimum"} and defined $self->{"maximum"}
!ll&&!rl&&r
14167031
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
272 31 ▶ if ($self->{minimum} == $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"minimum"} == $self->{"maximum"}) 2 29 31
273 2 ▶ if (grep { $_ == $self->{minimum} } @{ $self->{exclusions} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ == $self->{"minimum"};} @{$self->{"exclusions"} or [];}) 1 1 2
Condition100%2/2
$self->{'exclusions'} || []
l!l
11
MC/DC100%1/1
$self->{'exclusions'} || []
$self->{'exclusions'}
Truth table100%2/2
A
A= $self->{'exclusions'}
Aresult
11
00
274 1 $self->_reject_requirements(
275 $module,
276 "minimum and maximum are both $self->{minimum}, which is excluded",
277 );
278 }
279  
280 1 return CPAN::Meta::Requirements::Range::_Exact->_new($self->{minimum});
281 }
282  
283 29 ▶ if ($self->{minimum} > $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"minimum"} > $self->{"maximum"}) 2 27 29
284 2 $self->_reject_requirements(
285 $module,
286 "minimum $self->{minimum} exceeds maximum $self->{maximum}",
287 );
288 }
289 }
290  
291 # eliminate irrelevant exclusions
292 1711 ▶ if ($self->{exclusions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"exclusions"}) 32 1679 1711
293 32 my %seen;
294 32 @{ $self->{exclusions} } = grep {
295 (! defined $self->{minimum} or $_ >= $self->{minimum})
296 and
297 (! defined $self->{maximum} or $_ <= $self->{maximum})
298 and
299 33 ▶ ! $seen{$_}++
Condition100%12/12
(!defined($self->{'minimum'}) || $_ >= $self->{'minimum'}) && (!defined($self->{'maximum'}) || $_ <= $self->{'maximum'}) && !$seen{$_}++
!ll&&!rl&&r
3129
!defined($self->{"minimum"}) || $_ >= $self->{"minimum"} and !defined($self->{"maximum"}) || $_ <= $self->{"maximum"}
!ll&&!rl&&r
2130
not defined $self->{"minimum"} or $_ >= $self->{"minimum"}
l!l&&r!l&&!r
7242
not defined $self->{"maximum"} or $_ <= $self->{"maximum"}
l!l&&r!l&&!r
16141
MC/DC100%5/5
(!defined($self->{'minimum'}) || $_ >= $self->{'minimum'}) && (!defined($self->{'maximum'}) || $_ <= $self->{'maximum'}) && !$seen{$_}++
not defined $self->{"minimum"} $_ >= $self->{"minimum"} not defined $self->{"maximum"} $_ <= $self->{"maximum"} !$seen{$_}++
Truth table54%6/11
not(A) or B and not(C) or D && not(E)
A= not defined $self->{"minimum"}B= $_ >= $self->{"minimum"}C= not defined $self->{"maximum"}D= $_ <= $self->{"maximum"}E= !$seen{$_}++
ABCDEresult
00XXX0
1X00X0
0100X0
1X1X00
1X0100
011X00
010100
1X1X11
1X0111
011X11
010111
300 32 } @{ $self->{exclusions} };
301 }
302  
303 1711 return $self;
304 }
305  
306 #pod =method with_minimum
307 #pod
308 #pod $range->with_minimum( $version );
309 #pod
310 #pod This adds a new minimum version requirement. If the new requirement is
311 #pod redundant to the existing specification, this has no effect.
312 #pod
313 #pod Minimum requirements are inclusive. C<$version> is required, along with any
314 #pod greater version number.
315 #pod
316 #pod This method returns the version range object.
317 #pod
318 #pod =cut
319  
320 1666 ▶sub with_minimum {
Subroutine with_minimum: called CC=3 SCAR=11.0
Pod documented
321 1666 my ($self, $minimum, $module, $bad_version_hook) = @_;
322 1666 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
16633
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
323 1666 $self = $self->_clone;
324 1666 $minimum = $self->_version_object( $minimum, $module, $bad_version_hook );
325  
326 1664 ▶ if (defined (my $old_min = $self->{minimum})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old_min = $self->{'minimum'})) { } 91 1573 1664
327 91 $self->{minimum} = (sort { $b cmp $a } ($minimum, $old_min))[0];
328 } else {
329 1573 $self->{minimum} = $minimum;
330 }
331  
332 1664 return $self->_simplify($module);
333 }
334  
335 #pod =method with_maximum
336 #pod
337 #pod $range->with_maximum( $version );
338 #pod
339 #pod This adds a new maximum version requirement. If the new requirement is
340 #pod redundant to the existing specification, this has no effect.
341 #pod
342 #pod Maximum requirements are inclusive. No version strictly greater than the given
343 #pod version is allowed.
344 #pod
345 #pod This method returns the version range object.
346 #pod
347 #pod =cut
348  
349 26 ▶sub with_maximum {
Subroutine with_maximum: called CC=3 SCAR=11.0
Pod documented
350 26 my ($self, $maximum, $module, $bad_version_hook) = @_;
351 26 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
242
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
352 26 $self = $self->_clone;
353 26 $maximum = $self->_version_object( $maximum, $module, $bad_version_hook );
354  
355 26 ▶ if (defined (my $old_max = $self->{maximum})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old_max = $self->{'maximum'})) { } 1 25 26
356 1 $self->{maximum} = (sort { $a cmp $b } ($maximum, $old_max))[0];
357 } else {
358 25 $self->{maximum} = $maximum;
359 }
360  
361 26 return $self->_simplify($module);
362 }
363  
364 #pod =method with_exclusion
365 #pod
366 #pod $range->with_exclusion( $version );
367 #pod
368 #pod This adds a new excluded version. For example, you might use these three
369 #pod method calls:
370 #pod
371 #pod $range->with_minimum( '1.00' );
372 #pod $range->with_maximum( '1.82' );
373 #pod
374 #pod $range->with_exclusion( '1.75' );
375 #pod
376 #pod Any version between 1.00 and 1.82 inclusive would be acceptable, except for
377 #pod 1.75.
378 #pod
379 #pod This method returns the requirements object.
380 #pod
381 #pod =cut
382  
383 25 ▶sub with_exclusion {
Subroutine with_exclusion: called CC=3 SCAR=11.0
Pod documented
384 25 my ($self, $exclusion, $module, $bad_version_hook) = @_;
385 25 ▶ $module //= 'module';
Condition100%2/2
$module //= "module"
l!l
232
MC/DC100%1/1
$module //= "module"
$module
Truth table100%2/2
A
A= $module
Aresult
11
00
386 25 $self = $self->_clone;
387 25 $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook );
388  
389 25 ▶ push @{ $self->{exclusions} ||= [] }, $exclusion;
Condition100%2/2
$self->{"exclusions"} ||= []
l!l
421
MC/DC100%1/1
$self->{"exclusions"} ||= []
$self->{"exclusions"}
Truth table100%2/2
A
A= $self->{"exclusions"}
Aresult
11
00
390  
391 25 return $self->_simplify($module);
392 }
393  
394 264 ▶sub _as_modifiers {
Subroutine _as_modifiers: called CC=4 SCAR=13.9
395 264 my ($self) = @_;
396 264 my @mods;
397 264 ▶ push @mods, [ with_minimum => $self->{minimum} ] if exists $self->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"minimum"} 263 1 264
398 264 ▶ push @mods, [ with_maximum => $self->{maximum} ] if exists $self->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"maximum"} 3 261 264
399 264 ▶ push @mods, map {; [ with_exclusion => $_ ] } @{$self->{exclusions} || []};
Condition100%2/2
$self->{'exclusions'} || []
l!l
1263
MC/DC100%1/1
$self->{'exclusions'} || []
$self->{'exclusions'}
Truth table100%2/2
A
A= $self->{'exclusions'}
Aresult
11
00
400 264 return @mods;
401 }
402  
403 #pod =method as_struct
404 #pod
405 #pod $range->as_struct( $module );
406 #pod
407 #pod This returns a data structure containing the version requirements. This should
408 #pod not be used for version checks (see L</accepts_module> instead).
409 #pod
410 #pod =cut
411  
412 1318 ▶sub as_struct {
Subroutine as_struct: called CC=6 SCAR=17.9
Pod documented
413 1318 my ($self) = @_;
414  
415 1318 ▶ return 0 if ! keys %$self;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$self 0 1318 1318
416  
417 1318 ▶ my @exclusions = @{ $self->{exclusions} || [] };
Condition100%2/2
$self->{'exclusions'} || []
l!l
151303
MC/DC100%1/1
$self->{'exclusions'} || []
$self->{'exclusions'}
Truth table100%2/2
A
A= $self->{'exclusions'}
Aresult
11
00
418  
419 1318 my @parts;
420  
421 1318 for my $tuple (
422 [ qw( >= > minimum ) ],
423 [ qw( <= < maximum ) ],
424 ) {
425 2636 my ($op, $e_op, $k) = @$tuple;
426 2636 ▶ if (exists $self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$k}) 1332 1304 2636
427 1332 my @new_exclusions = grep { $_ != $self->{ $k } } @exclusions;
428 1332 ▶ if (@new_exclusions == @exclusions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new_exclusions == @exclusions) { } 1329 3 1332
429 1329 push @parts, [ $op, "$self->{ $k }" ];
430 } else {
431 3 push @parts, [ $e_op, "$self->{ $k }" ];
432 3 @exclusions = @new_exclusions;
433 }
434 }
435 }
436  
437 1318 push @parts, map {; [ "!=", "$_" ] } @exclusions;
438  
439 1318 return \@parts;
440 }
441  
442 #pod =method as_string
443 #pod
444 #pod $range->as_string;
445 #pod
446 #pod This returns a string containing the version requirements in the format
447 #pod described in L<CPAN::Meta::Spec>. This should only be used for informational
448 #pod purposes such as error messages and should not be interpreted or used for
449 #pod comparison (see L</accepts> instead).
450 #pod
451 #pod =cut
452  
453 1317 ▶sub as_string {
Subroutine as_string: called CC=4 SCAR=13.9
Pod documented
454 1317 my ($self) = @_;
455  
456 1317 my @parts = @{ $self->as_struct };
457  
458 1317 ▶ return $parts[0][1] if @parts == 1 and $parts[0][0] eq '>=';
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 and $parts[0][0] eq ">=" 1297 20 1317
Condition100%3/3
@parts == 1 and $parts[0][0] eq ">="
!ll&&!rl&&r
1731297
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
459 20 ▶ @parts = grep { $_->[0] ne '>=' || $_->[1] ne '0' } @parts;
Condition100%3/3
$_->[0] ne '>=' || $_->[1] ne '0'
l!l&&r!l&&!r
29141
MC/DC100%2/2
$_->[0] ne '>=' || $_->[1] ne '0'
$_->[0] ne '>=' $_->[1] ne '0'
Truth table100%3/3
A || B
A= $_->[0] ne '>='B= $_->[1] ne '0'
ABresult
1X1
011
000
460  
461 20 return join q{, }, map {; join q{ }, @$_ } @parts;
462 }
463  
464 4 ▶sub _reject_requirements {
Subroutine _reject_requirements: called CC=1 SCAR=0.0
465 4 my ($self, $module, $error) = @_;
466 4 Carp::croak("illegal requirements for $module: $error")
467 }
468  
469 #pod =method accepts
470 #pod
471 #pod my $bool = $range->accepts($version);
472 #pod
473 #pod Given a version, this method returns true if the version specification
474 #pod accepts the provided version. In other words, given:
475 #pod
476 #pod '>= 1.00, < 2.00'
477 #pod
478 #pod We will accept 1.00 and 1.75 but not 0.50 or 2.00.
479 #pod
480 #pod =cut
481  
482 83 ▶sub accepts {
Subroutine accepts: called CC=7 SCAR=19.5
Pod documented
483 83 my ($self, $version) = @_;
484  
485 83 ▶ return if defined $self->{minimum} and $version < $self->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"minimum"} and $version < $self->{"minimum"} 10 73 83
Condition100%3/3
defined $self->{"minimum"} and $version < $self->{"minimum"}
!ll&&!rl&&r
304310
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
486 73 ▶ return if defined $self->{maximum} and $version > $self->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"maximum"} and $version > $self->{"maximum"} 6 67 73
Condition100%3/3
defined $self->{"maximum"} and $version > $self->{"maximum"}
!ll&&!rl&&r
57106
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
487 return if defined $self->{exclusions}
488 67 ▶ and grep { $version == $_ } @{ $self->{exclusions} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};} 7 60 67
Condition100%3/3
defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};}
!ll&&!rl&&r
49117
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
489  
490 60 return 1;
491 }
492  
493 #pod =method is_simple
494 #pod
495 #pod This method returns true if and only if the range is an inclusive minimum
496 #pod -- that is, if their string expression is just the version number.
497 #pod
498 #pod =cut
499  
500 4 ▶sub is_simple {
Subroutine is_simple: called CC=2 SCAR=6.9
Pod documented
501 4 my ($self) = @_;
502 # XXX: This is a complete hack, but also entirely correct.
503 4 ▶ return if $self->as_string =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->as_string =~ /\s/ 1 3 4
504  
505 3 return 1;
506 }
507  
508 package
509 CPAN::Meta::Requirements::Range::_Exact;
510  
511 11 our @ISA = 'CPAN::Meta::Requirements::Range::_Base';
512  
513 11 our $VERSION = '2.141';
514  
515 11 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.7
516 11 ▶ eval "use version ()"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
517 11 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 11 11
518 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
519 }
520 }
521  
522 17 ▶sub _new { bless { version => $_[1] } => $_[0] }
Subroutine _new: called CC=1 SCAR=0.0
523  
524 9 ▶sub accepts { return $_[0]{version} == $_[1] }
Subroutine accepts: called CC=1 SCAR=0.0
525  
526 4 ▶sub _reject_requirements {
Subroutine _reject_requirements: called CC=1 SCAR=0.0
527 4 my ($self, $module, $error) = @_;
528 4 Carp::croak("illegal requirements for $module: $error")
529 }
530  
531 6 ▶sub _clone {
Subroutine _clone: called CC=1 SCAR=0.0
532 6 (ref $_[0])->_new( version->new( $_[0]{version} ) )
533 }
534  
535 3 ▶sub with_exact_version {
Subroutine with_exact_version: called CC=3 SCAR=11.0
536 3 my ($self, $version, $module, $bad_version_hook) = @_;
537 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
538 3 $version = $self->_version_object($version, $module, $bad_version_hook);
539  
540 3 ▶ return $self->_clone if $self->accepts($version);
Branch: 1 branch
BranchTrueFalseTotal
if $self->accepts($version) 2 1 3
541  
542 1 $self->_reject_requirements(
543 $module,
544 "can't be exactly $version when exact requirement is already $self->{version}",
545 );
546 }
547  
548 2 ▶sub with_minimum {
Subroutine with_minimum: called CC=3 SCAR=11.3
549 2 my ($self, $minimum, $module, $bad_version_hook) = @_;
550 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
551 2 $minimum = $self->_version_object( $minimum, $module, $bad_version_hook );
552  
553 1 ▶ return $self->_clone if $self->{version} >= $minimum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} >= $minimum 0 1 1
554 1 $self->_reject_requirements(
555 $module,
556 "minimum $minimum exceeds exact specification $self->{version}",
557 );
558 }
559  
560 3 ▶sub with_maximum {
Subroutine with_maximum: called CC=3 SCAR=11.0
561 3 my ($self, $maximum, $module, $bad_version_hook) = @_;
562 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
563 3 $maximum = $self->_version_object( $maximum, $module, $bad_version_hook );
564  
565 3 ▶ return $self->_clone if $self->{version} <= $maximum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} <= $maximum 2 1 3
566 1 $self->_reject_requirements(
567 $module,
568 "maximum $maximum below exact specification $self->{version}",
569 );
570 }
571  
572 3 ▶sub with_exclusion {
Subroutine with_exclusion: called CC=3 SCAR=11.0
573 3 my ($self, $exclusion, $module, $bad_version_hook) = @_;
574 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
575 3 $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook );
576  
577 3 ▶ return $self->_clone unless $exclusion == $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $exclusion == $self->{"version"} 2 1 3
578 1 $self->_reject_requirements(
579 $module,
580 "tried to exclude $exclusion, which is already exactly specified",
581 );
582 }
583  
584 7 ▶sub as_string { return "== $_[0]{version}" }
Subroutine as_string: called CC=1 SCAR=0.0
585  
586 1 ▶sub as_struct { return [ [ '==', "$_[0]{version}" ] ] }
Subroutine as_struct: called CC=1 SCAR=0.0
587  
588 2 ▶sub _as_modifiers { return [ with_exact_version => $_[0]{version} ] }
Subroutine _as_modifiers: called CC=1 SCAR=0.0
589  
590  
591 11 1;
592  
593 # vim: ts=2 sts=2 sw=2 et:
594  
595 __END__
↑ Summary Requirements.pm »