/usr/local/lib/perl5/5.44.0/CPAN/Meta/Requirements/Range.pm

filter: Statementstmt 41.7% 93 / 223 Branchbran 25.5% 25 / 98 Conditioncond 17.5% 13 / 74 MC/DCmcdc 2.5% 1 / 40 Subroutinesub 45.0% 18 / 40 Podpod 100% 8 / 8 totaltotal 32.7% 158 / 483 CC 82 SCAR 32.8
CC
82
Cov
33%
_simplify
97.6
accepts
56.0
_version_object
54.8
CRAP 26.6
« /usr/local/lib/perl5/5.44.0/x86_64-linux/Config.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/Try/Tiny.pm »
1 7 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶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 7 our $VERSION = '2.145';
8  
9 7 ▶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 7 ▶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 7 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.7
46 7 ▶ eval "use version ()"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
47 7 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 7 7
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 266 ▶sub _find_magic_vstring {
Subroutine _find_magic_vstring: called CC=4 SCAR=17.9
54 266 my $value = shift;
55 266 my $tvalue = '';
56 266 require B;
57 266 my $sv = B::svref_2object(\$value);
58 266 ▶ my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sv eq 'B::PVMG' ? : 0 266 266
59 266 ▶ while ( $magic ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic) 0 266 266
60 0 ▶ if ( $magic->TYPE eq 'V' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic->TYPE eq 'V') { } 0 0 0
61 0 $tvalue = $magic->PTR;
62 0 $tvalue =~ s/^v?(.+)$/v$1/;
63 0 last;
64 }
65 else {
66 0 $magic = $magic->MOREMAGIC;
67 }
68 }
69 266 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') ? : 7 0 7
74  
75 # construct once, reuse many times
76 7 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 266 ▶sub _version_object {
Subroutine _version_object: called CC=16 SCAR=40.0
84 266 my ($self, $version, $module, $bad_version_hook) = @_;
85  
86 266 my ($vobj, $err);
87  
88 266 ▶ 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') { } 182 84 266
elsif (ref $version eq 'version' or ref $version and _isa_version($version)) { } 0 84 84
Condition66%4/6
not defined $version or not ref $version and $version eq 0
l!l&&r!l&&!r
018284
not ref $version and $version eq 0
!ll&&!rl&&r
084182
MC/DC33%1/3
not defined $version or not ref $version and $version eq 0
not defined $version not ref $version $version eq 0
Truth table50%2/4
not(A) or not(B) and C
A= not defined $versionB= not ref $versionC= $version eq 0
ABCresult
1XX1
0111
00X0
0100
89 182 return $V0;
90 }
91 ▶ elsif ( ref($version) eq 'version' || ( ref($version) && _isa_version($version) ) ) {
Condition33%2/6
ref $version eq "version" or ref $version and _isa_version($version)
l!l&&r!l&&!r
0084
ref $version and _isa_version($version)
!ll&&!rl&&r
8400
MC/DC0%0/3
ref $version eq "version" or ref $version and _isa_version($version)
ref $version eq "version" ref $version _isa_version($version)
Truth table25%1/4
A or B and C
A= ref $version eq "version"B= ref $versionC= _isa_version($version)
ABCresult
1XX1
0111
00X0
0100
92 0 $vobj = $version;
93 }
94 else {
95 # hack around version::vpp not handling <3 character vstring literals
96 84 ▶ 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 84 84
Condition33%1/3
$INC{"version/vpp.pm"} or $INC{"ExtUtils/MakeMaker/version/vpp.pm"}
l!l&&r!l&&!r
0084
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 84 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 84 ▶ die "Invalid version: $version" if $version eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "version" 0 84 84
104 84 $vobj = version->new($version);
105 };
106 84 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 84 84
107 0 ▶ $vobj = eval { $bad_version_hook->($version, $module) }
Branch: 1 branch
BranchTrueFalseTotal
if ref $bad_version_hook eq "CODE" 0 0 0
108 if ref $bad_version_hook eq 'CODE';
109 0 ▶ unless (eval { $vobj->isa("version") }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $vobj->isa("version") } }) 0 0 0
110 0 $err =~ s{ at .* line \d+.*$}{};
111 0 die "Can't convert '$version': $err";
112 }
113 }
114 }
115  
116 # ensure no leading '.'
117 84 ▶ if ( $vobj =~ m{\A\.} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vobj =~ /\A\./) 0 84 84
118 0 $vobj = version->new("0$vobj");
119 }
120  
121 # ensure normal v-string form
122 84 ▶ if ( _is_qv($vobj) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_qv($vobj)) 0 84 84
123 0 $vobj = version->new($vobj->normal);
124 }
125  
126 84 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 7 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 266 ▶sub with_string_requirement {
Subroutine with_string_requirement: called CC=9 SCAR=27.9
173 266 my ($self, $req, $module, $bad_version_hook) = @_;
174 266 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
2660
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
175  
176 266 ▶ unless ( defined $req && length $req ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $req and length $req) 0 266 266
Condition33%1/3
defined $req and length $req
!ll&&!rl&&r
00266
MC/DC0%0/2
defined $req and length $req
defined $req length $req
Truth table33%1/3
A and B
A= defined $reqB= length $req
ABresult
0X0
100
111
177 0 $req = 0;
178 0 Carp::carp("Undefined requirement for $module treated as '0'");
179 }
180  
181 266 my $magic = _find_magic_vstring( $req );
182 266 ▶ if (length $magic) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $magic) 0 266 266
183 0 return $self->with_minimum($magic, $module, $bad_version_hook);
184 }
185  
186 266 my @parts = split qr{\s*,\s*}, $req;
187  
188 266 for my $part (@parts) {
189 266 my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z};
190  
191 266 ▶ if (! defined $op) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $op) { } 266 0 266
192 266 $self = $self->with_minimum($part, $module, $bad_version_hook);
193 } else {
194 Carp::croak("illegal requirement string: $req")
195 0 ▶ unless my $methods = $methods_for_op{ $op };
Branch: 1 branch
BranchTrueFalseTotal
unless my $methods = $methods_for_op{$op} 0 0 0
196  
197 0 $self = $self->$_($ver, $module, $bad_version_hook) for @$methods;
198 }
199 }
200  
201 266 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 0 ▶sub with_range {
Subroutine with_range: not called CC=2 SCAR=17.9
213 0 my ($self, $other, $module, $bad_version_hook) = @_;
214 0 for my $modifier($other->_as_modifiers) {
215 0 my ($method, $arg) = @$modifier;
216 0 $self = $self->$method($arg, $module, $bad_version_hook);
217 }
218 0 return $self;
219 }
220  
221 package CPAN::Meta::Requirements::Range;
222  
223 7 our @ISA = 'CPAN::Meta::Requirements::Range::_Base';
224  
225 266 ▶sub _clone {
Subroutine _clone: called CC=5 SCAR=30.3
226 266 ▶ return (bless { } => $_[0]) unless ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 266 0 266
227  
228 0 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 0 ▶ ? (exclusions => [ map { version->new($_) } @{ $s->{exclusions} } ])
Branch: 3 branches
BranchTrueFalseTotal
exists $s->{'minimum'} ? : 0 0 0
exists $s->{'maximum'} ? : 0 0 0
exists $s->{'exclusions'} ? : 0 0 0
235 : ()),
236 );
237  
238 0 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 0 ▶sub with_exact_version {
Subroutine with_exact_version: not called CC=3 SCAR=24.8
Pod documented
253 0 my ($self, $version, $module, $bad_version_hook) = @_;
254 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
255 0 $self = $self->_clone;
256 0 $version = $self->_version_object($version, $module, $bad_version_hook);
257  
258 0 ▶ unless ($self->accepts($version)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->accepts($version)) 0 0 0
259 0 $self->_reject_requirements(
260 $module,
261 "exact specification $version outside of range " . $self->as_string
262 );
263 }
264  
265 0 return CPAN::Meta::Requirements::Range::_Exact->_new($version);
266 }
267  
268 266 ▶sub _simplify {
Subroutine _simplify: called CC=12 SCAR=45.8
269 266 my ($self, $module) = @_;
270  
271 266 ▶ if (defined $self->{minimum} and defined $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"minimum"} and defined $self->{"maximum"}) 0 266 266
Condition33%1/3
defined $self->{"minimum"} and defined $self->{"maximum"}
!ll&&!rl&&r
02660
MC/DC0%0/2
defined $self->{"minimum"} and defined $self->{"maximum"}
defined $self->{"minimum"} defined $self->{"maximum"}
Truth table33%1/3
A and B
A= defined $self->{"minimum"}B= defined $self->{"maximum"}
ABresult
0X0
100
111
272 0 ▶ if ($self->{minimum} == $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"minimum"} == $self->{"maximum"}) 0 0 0
273 0 ▶ if (grep { $_ == $self->{minimum} } @{ $self->{exclusions} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ == $self->{"minimum"};} @{$self->{"exclusions"} or [];}) 0 0 0
Condition0%0/2
$self->{'exclusions'} || []
l!l
00
MC/DC0%0/1
$self->{'exclusions'} || []
$self->{'exclusions'}
Truth table0%0/2
A
A= $self->{'exclusions'}
Aresult
11
00
274 0 $self->_reject_requirements(
275 $module,
276 "minimum and maximum are both $self->{minimum}, which is excluded",
277 );
278 }
279  
280 0 return CPAN::Meta::Requirements::Range::_Exact->_new($self->{minimum});
281 }
282  
283 0 ▶ if ($self->{minimum} > $self->{maximum}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"minimum"} > $self->{"maximum"}) 0 0 0
284 0 $self->_reject_requirements(
285 $module,
286 "minimum $self->{minimum} exceeds maximum $self->{maximum}",
287 );
288 }
289 }
290  
291 # eliminate irrelevant exclusions
292 266 ▶ if ($self->{exclusions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"exclusions"}) 0 266 266
293 0 my %seen;
294 0 @{ $self->{exclusions} } = grep {
295 (! defined $self->{minimum} or $_ >= $self->{minimum})
296 and
297 (! defined $self->{maximum} or $_ <= $self->{maximum})
298 and
299 0 ▶ ! $seen{$_}++
Condition0%0/12
(!defined($self->{'minimum'}) || $_ >= $self->{'minimum'}) && (!defined($self->{'maximum'}) || $_ <= $self->{'maximum'}) && !$seen{$_}++
!ll&&!rl&&r
000
!defined($self->{"minimum"}) || $_ >= $self->{"minimum"} and !defined($self->{"maximum"}) || $_ <= $self->{"maximum"}
!ll&&!rl&&r
000
not defined $self->{"minimum"} or $_ >= $self->{"minimum"}
l!l&&r!l&&!r
000
not defined $self->{"maximum"} or $_ <= $self->{"maximum"}
l!l&&r!l&&!r
000
MC/DC0%0/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 table0%0/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 0 } @{ $self->{exclusions} };
301 }
302  
303 266 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 266 ▶sub with_minimum {
Subroutine with_minimum: called CC=3 SCAR=11.8
Pod documented
321 266 my ($self, $minimum, $module, $bad_version_hook) = @_;
322 266 ▶ $module //= 'module';
Condition50%1/2
$module //= "module"
l!l
2660
MC/DC0%0/1
$module //= "module"
$module
Truth table50%1/2
A
A= $module
Aresult
11
00
323 266 $self = $self->_clone;
324 266 $minimum = $self->_version_object( $minimum, $module, $bad_version_hook );
325  
326 266 ▶ if (defined (my $old_min = $self->{minimum})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old_min = $self->{'minimum'})) { } 0 266 266
327 0 $self->{minimum} = (sort { $b cmp $a } ($minimum, $old_min))[0];
328 } else {
329 266 $self->{minimum} = $minimum;
330 }
331  
332 266 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 0 ▶sub with_maximum {
Subroutine with_maximum: not called CC=3 SCAR=24.8
Pod documented
350 0 my ($self, $maximum, $module, $bad_version_hook) = @_;
351 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
352 0 $self = $self->_clone;
353 0 $maximum = $self->_version_object( $maximum, $module, $bad_version_hook );
354  
355 0 ▶ if (defined (my $old_max = $self->{maximum})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old_max = $self->{'maximum'})) { } 0 0 0
356 0 $self->{maximum} = (sort { $a cmp $b } ($maximum, $old_max))[0];
357 } else {
358 0 $self->{maximum} = $maximum;
359 }
360  
361 0 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 0 ▶sub with_exclusion {
Subroutine with_exclusion: not called CC=3 SCAR=24.8
Pod documented
384 0 my ($self, $exclusion, $module, $bad_version_hook) = @_;
385 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
386 0 $self = $self->_clone;
387 0 $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook );
388  
389 0 ▶ push @{ $self->{exclusions} ||= [] }, $exclusion;
Condition0%0/2
$self->{"exclusions"} ||= []
l!l
00
MC/DC0%0/1
$self->{"exclusions"} ||= []
$self->{"exclusions"}
Truth table0%0/2
A
A= $self->{"exclusions"}
Aresult
11
00
390  
391 0 return $self->_simplify($module);
392 }
393  
394 0 ▶sub _as_modifiers {
Subroutine _as_modifiers: not called CC=4 SCAR=30.0
395 0 my ($self) = @_;
396 0 my @mods;
397 0 ▶ push @mods, [ with_minimum => $self->{minimum} ] if exists $self->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"minimum"} 0 0 0
398 0 ▶ push @mods, [ with_maximum => $self->{maximum} ] if exists $self->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"maximum"} 0 0 0
399 0 ▶ push @mods, map {; [ with_exclusion => $_ ] } @{$self->{exclusions} || []};
Condition0%0/2
$self->{'exclusions'} || []
l!l
00
MC/DC0%0/1
$self->{'exclusions'} || []
$self->{'exclusions'}
Truth table0%0/2
A
A= $self->{'exclusions'}
Aresult
11
00
400 0 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 266 ▶sub as_struct {
Subroutine as_struct: called CC=6 SCAR=19.2
Pod documented
413 266 my ($self) = @_;
414  
415 266 ▶ return 0 if ! keys %$self;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$self 0 266 266
416  
417 266 ▶ my @exclusions = @{ $self->{exclusions} || [] };
Condition50%1/2
$self->{'exclusions'} || []
l!l
0266
MC/DC0%0/1
$self->{'exclusions'} || []
$self->{'exclusions'}
Truth table50%1/2
A
A= $self->{'exclusions'}
Aresult
11
00
418  
419 266 my @parts;
420  
421 266 for my $tuple (
422 [ qw( >= > minimum ) ],
423 [ qw( <= < maximum ) ],
424 ) {
425 532 my ($op, $e_op, $k) = @$tuple;
426 532 ▶ if (exists $self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$k}) 266 266 532
427 0 my @new_exclusions = grep { $_ != $self->{ $k } } @exclusions;
428 266 ▶ if (@new_exclusions == @exclusions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new_exclusions == @exclusions) { } 266 0 266
429 266 push @parts, [ $op, "$self->{ $k }" ];
430 } else {
431 0 push @parts, [ $e_op, "$self->{ $k }" ];
432 0 @exclusions = @new_exclusions;
433 }
434 }
435 }
436  
437 0 push @parts, map {; [ "!=", "$_" ] } @exclusions;
438  
439 266 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 266 ▶sub as_string {
Subroutine as_string: called CC=4 SCAR=20.7
Pod documented
454 266 my ($self) = @_;
455  
456 266 my @parts = @{ $self->as_struct };
457  
458 266 ▶ return $parts[0][1] if @parts == 1 and $parts[0][0] eq '>=';
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 and $parts[0][0] eq ">=" 266 0 266
Condition33%1/3
@parts == 1 and $parts[0][0] eq ">="
!ll&&!rl&&r
00266
MC/DC0%0/2
@parts == 1 and $parts[0][0] eq ">="
@parts == 1 $parts[0][0] eq ">="
Truth table33%1/3
A and B
A= @parts == 1B= $parts[0][0] eq ">="
ABresult
0X0
100
111
459 0 ▶ @parts = grep { $_->[0] ne '>=' || $_->[1] ne '0' } @parts;
Condition0%0/3
$_->[0] ne '>=' || $_->[1] ne '0'
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->[0] ne '>=' || $_->[1] ne '0'
$_->[0] ne '>=' $_->[1] ne '0'
Truth table0%0/3
A || B
A= $_->[0] ne '>='B= $_->[1] ne '0'
ABresult
1X1
011
000
460  
461 0 return join q{, }, map {; join q{ }, @$_ } @parts;
462 }
463  
464 0 ▶sub _reject_requirements {
Subroutine _reject_requirements: not called CC=1 SCAR=6.9
465 0 my ($self, $module, $error) = @_;
466 0 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 0 ▶sub accepts {
Subroutine accepts: not called CC=7 SCAR=40.3
Pod documented
483 0 my ($self, $version) = @_;
484  
485 0 ▶ return if defined $self->{minimum} and $version < $self->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"minimum"} and $version < $self->{"minimum"} 0 0 0
Condition0%0/3
defined $self->{"minimum"} and $version < $self->{"minimum"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"minimum"} and $version < $self->{"minimum"}
defined $self->{"minimum"} $version < $self->{"minimum"}
Truth table0%0/3
A and B
A= defined $self->{"minimum"}B= $version < $self->{"minimum"}
ABresult
0X0
100
111
486 0 ▶ return if defined $self->{maximum} and $version > $self->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"maximum"} and $version > $self->{"maximum"} 0 0 0
Condition0%0/3
defined $self->{"maximum"} and $version > $self->{"maximum"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"maximum"} and $version > $self->{"maximum"}
defined $self->{"maximum"} $version > $self->{"maximum"}
Truth table0%0/3
A and B
A= defined $self->{"maximum"}B= $version > $self->{"maximum"}
ABresult
0X0
100
111
487 return if defined $self->{exclusions}
488 0 ▶ and grep { $version == $_ } @{ $self->{exclusions} };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};} 0 0 0
Condition0%0/3
defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"exclusions"} and grep {$version == $_;} @{$$self{"exclusions"};}
defined $self->{"exclusions"} grep {$version == $_;} @{$$self{"exclusions"};}
Truth table0%0/3
A and B
A= defined $self->{"exclusions"}B= grep {$version == $_;} @{$$self{"exclusions"};}
ABresult
0X0
100
111
489  
490 0 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 0 ▶sub is_simple {
Subroutine is_simple: not called CC=2 SCAR=17.9
Pod documented
501 0 my ($self) = @_;
502 # XXX: This is a complete hack, but also entirely correct.
503 0 ▶ return if $self->as_string =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->as_string =~ /\s/ 0 0 0
504  
505 0 return 1;
506 }
507  
508 package
509 CPAN::Meta::Requirements::Range::_Exact;
510  
511 7 our @ISA = 'CPAN::Meta::Requirements::Range::_Base';
512  
513 7 our $VERSION = '2.141';
514  
515 7 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.7
516 7 ▶ eval "use version ()"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
517 7 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 7 7
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 0 ▶sub _new { bless { version => $_[1] } => $_[0] }
Subroutine _new: not called CC=1 SCAR=6.9
523  
524 0 ▶sub accepts { return $_[0]{version} == $_[1] }
Subroutine accepts: not called CC=1 SCAR=6.9
525  
526 0 ▶sub _reject_requirements {
Subroutine _reject_requirements: not called CC=1 SCAR=6.9
527 0 my ($self, $module, $error) = @_;
528 0 Carp::croak("illegal requirements for $module: $error")
529 }
530  
531 0 ▶sub _clone {
Subroutine _clone: not called CC=1 SCAR=6.9
532 0 (ref $_[0])->_new( version->new( $_[0]{version} ) )
533 }
534  
535 0 ▶sub with_exact_version {
Subroutine with_exact_version: not called CC=3 SCAR=24.8
536 0 my ($self, $version, $module, $bad_version_hook) = @_;
537 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
538 0 $version = $self->_version_object($version, $module, $bad_version_hook);
539  
540 0 ▶ return $self->_clone if $self->accepts($version);
Branch: 1 branch
BranchTrueFalseTotal
if $self->accepts($version) 0 0 0
541  
542 0 $self->_reject_requirements(
543 $module,
544 "can't be exactly $version when exact requirement is already $self->{version}",
545 );
546 }
547  
548 0 ▶sub with_minimum {
Subroutine with_minimum: not called CC=3 SCAR=24.8
549 0 my ($self, $minimum, $module, $bad_version_hook) = @_;
550 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
551 0 $minimum = $self->_version_object( $minimum, $module, $bad_version_hook );
552  
553 0 ▶ return $self->_clone if $self->{version} >= $minimum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} >= $minimum 0 0 0
554 0 $self->_reject_requirements(
555 $module,
556 "minimum $minimum exceeds exact specification $self->{version}",
557 );
558 }
559  
560 0 ▶sub with_maximum {
Subroutine with_maximum: not called CC=3 SCAR=24.8
561 0 my ($self, $maximum, $module, $bad_version_hook) = @_;
562 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
563 0 $maximum = $self->_version_object( $maximum, $module, $bad_version_hook );
564  
565 0 ▶ return $self->_clone if $self->{version} <= $maximum;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"version"} <= $maximum 0 0 0
566 0 $self->_reject_requirements(
567 $module,
568 "maximum $maximum below exact specification $self->{version}",
569 );
570 }
571  
572 0 ▶sub with_exclusion {
Subroutine with_exclusion: not called CC=3 SCAR=24.8
573 0 my ($self, $exclusion, $module, $bad_version_hook) = @_;
574 0 ▶ $module //= 'module';
Condition0%0/2
$module //= "module"
l!l
00
MC/DC0%0/1
$module //= "module"
$module
Truth table0%0/2
A
A= $module
Aresult
11
00
575 0 $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook );
576  
577 0 ▶ return $self->_clone unless $exclusion == $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $exclusion == $self->{"version"} 0 0 0
578 0 $self->_reject_requirements(
579 $module,
580 "tried to exclude $exclusion, which is already exactly specified",
581 );
582 }
583  
584 0 ▶sub as_string { return "== $_[0]{version}" }
Subroutine as_string: not called CC=1 SCAR=6.9
585  
586 0 ▶sub as_struct { return [ [ '==', "$_[0]{version}" ] ] }
Subroutine as_struct: not called CC=1 SCAR=6.9
587  
588 0 ▶sub _as_modifiers { return [ with_exact_version => $_[0]{version} ] }
Subroutine _as_modifiers: not called CC=1 SCAR=6.9
589  
590  
591 7 1;
592  
593 # vim: ts=2 sts=2 sw=2 et:
594  
595 __END__
« /usr/local/lib/perl5/5.44.0/x86_64-linux/Config.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/Try/Tiny.pm »