version/vpp.pm

filter: Statementstmt 87.8% 491 / 559 Branchbran 76.0% 245 / 322 Conditioncond 67.0% 112 / 167 MC/DCmcdc 45.2% 43 / 95 Subroutinesub 98.1% 52 / 53 Podpod 0.0% 0 / 20 totaltotal 77.5% 943 / 1216 CC 217 SCAR 40.4
CC
217
Cov
81%
prescan_version
165.3
scan_version
49.2
new
23.1
CRAP 56.9
« version.pm ↑ Summary version/regex.pm »
1 package charstar;
2 # a little helper class to emulate C char* semantics in Perl
3 # so that prescan_version can use the same code as in C
4  
5 1 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 '""' => \&thischar,
7 '0+' => \&thischar,
8 '++' => \&increment,
9 '--' => \&decrement,
10 '+' => \&plus,
11 '-' => \&minus,
12 '*' => \&multiply,
13 'cmp' => \&cmp,
14 '<=>' => \&spaceship,
15 'bool' => \&thischar,
16 '=' => \&clone,
17 1 );
18  
19 1414 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
20 1414 my ($self, $string) = @_;
21 1414 ▶ my $class = ref($self) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
6157990
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
22  
23 1414 my $obj = {
24 string => [split(//,$string)],
25 current => 0,
26 };
27 1414 return bless $obj, $class;
28 }
29  
30 32426 ▶sub thischar {
Subroutine thischar: called CC=3 SCAR=11.0
31 32426 my ($self) = @_;
32 32426 my $last = $#{$self->{string}};
33 32426 my $curr = $self->{current};
34 32426 ▶ if ($curr >= 0 && $curr <= $last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curr >= 0 and $curr <= $last) { } 25391 7035 32426
Condition66%2/3
$curr >= 0 and $curr <= $last
!ll&&!rl&&r
0703525391
MC/DC50%1/2
$curr >= 0 and $curr <= $last
$curr >= 0 $curr <= $last
Truth table66%2/3
A and B
A= $curr >= 0B= $curr <= $last
ABresult
0X0
100
111
35 25391 return $self->{string}->[$curr];
36 }
37 else {
38 7035 return '';
39 }
40 }
41  
42 10241 ▶sub increment {
Subroutine increment: called CC=1 SCAR=0.0
43 10241 my ($self) = @_;
44 10241 $self->{current}++;
45 }
46  
47 2958 ▶sub decrement {
Subroutine decrement: called CC=1 SCAR=0.0
48 2958 my ($self) = @_;
49 2958 $self->{current}--;
50 }
51  
52 36 ▶sub plus {
Subroutine plus: called CC=1 SCAR=0.0
53 36 my ($self, $offset) = @_;
54 36 my $rself = $self->clone;
55 36 $rself->{current} += $offset;
56 36 return $rself;
57 }
58  
59 524 ▶sub minus {
Subroutine minus: called CC=1 SCAR=0.0
60 524 my ($self, $offset) = @_;
61 524 my $rself = $self->clone;
62 524 $rself->{current} -= $offset;
63 524 return $rself;
64 }
65  
66 2122 ▶sub multiply {
Subroutine multiply: called CC=1 SCAR=0.0
67 2122 my ($left, $right, $swapped) = @_;
68 2122 my $char = $left->thischar();
69 2122 return $char * $right;
70 }
71  
72 4565 ▶sub spaceship {
Subroutine spaceship: called CC=2 SCAR=7.6
73 4565 my ($left, $right, $swapped) = @_;
74 4565 ▶ unless (ref($right)) { # not an object already
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $right) 0 4565 4565
75 0 $right = $left->new($right);
76 }
77 4565 return $left->{current} <=> $right->{current};
78 }
79  
80 13003 ▶sub cmp {
Subroutine cmp: called CC=3 SCAR=11.0
81 13003 my ($left, $right, $swapped) = @_;
82 13003 ▶ unless (ref($right)) { # not an object already
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $right) 13003 0 13003
83 13003 ▶ if (length($right) == 1) { # comparing single character only
Branch: 1 branch
BranchTrueFalseTotal
if (length $right == 1) 12388 615 13003
84 12388 return $left->thischar cmp $right;
85 }
86 615 $right = $left->new($right);
87 }
88 615 return $left->currstr cmp $right->currstr;
89 }
90  
91 0 ▶sub bool {
Subroutine bool: not called CC=1 SCAR=6.9
92 0 my ($self) = @_;
93 0 my $char = $self->thischar;
94 0 return ($char ne '');
95 }
96  
97 4112 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
98 4112 my ($left, $right, $swapped) = @_;
99 $right = {
100 4112 string => [@{$left->{string}}],
101 current => $left->{current},
102 4112 };
103 4112 return bless $right, ref($left);
104 }
105  
106 1749 ▶sub currstr {
Subroutine currstr: called CC=3 SCAR=11.3
107 1749 my ($self, $s) = @_;
108 1749 my $curr = $self->{current};
109 1749 my $last = $#{$self->{string}};
110 1749 ▶ if (defined($s) && $s->{current} < $last) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and $s->{"current"} < $last) 0 1749 1749
Condition66%2/3
defined $s and $s->{"current"} < $last
!ll&&!rl&&r
12305190
MC/DC0%0/2
defined $s and $s->{"current"} < $last
defined $s $s->{"current"} < $last
Truth table66%2/3
A and B
A= defined $sB= $s->{"current"} < $last
ABresult
0X0
100
111
111 0 $last = $s->{current};
112 }
113  
114 1749 my $string = join('', @{$self->{string}}[$curr..$last]);
115 1749 return $string;
116 }
117  
118 package version::vpp;
119  
120 1 ▶use 5.006002;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 1 our $VERSION = '0.9934';
127 1 our $CLASS = 'version::vpp';
128 1 our ($LAX, $STRICT, $WARN_CATEGORY);
129  
130 1 ▶if ($] > 5.015) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] > 5.015) { } 1 0 1
131 1 warnings::register_categories(qw/version/);
132 1 $WARN_CATEGORY = 'version';
133 } else {
134 0 $WARN_CATEGORY = 'numeric';
135 }
136  
137 1 require version::regex;
138 1 *version::vpp::is_strict = \&version::regex::is_strict;
139 1 *version::vpp::is_lax = \&version::regex::is_lax;
140 1 *LAX = \$version::regex::LAX;
141 1 *STRICT = \$version::regex::STRICT;
142  
143 1 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
144 1 '""' => \&stringify,
145 '0+' => \&numify,
146 'cmp' => \&vcmp,
147 '<=>' => \&vcmp,
148 'bool' => \&vbool,
149 '+' => \&vnoop,
150 '-' => \&vnoop,
151 '*' => \&vnoop,
152 '/' => \&vnoop,
153 '+=' => \&vnoop,
154 '-=' => \&vnoop,
155 '*=' => \&vnoop,
156 '/=' => \&vnoop,
157 'abs' => \&vnoop,
158 1 );
159  
160 9 ▶sub import {
Subroutine import: called CC=13 SCAR=27.8
161 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
162 9 my ($class) = shift;
163  
164 # Set up any derived class
165 9 ▶ unless ($class eq $CLASS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class eq $version::vpp::CLASS) 4 5 9
166 4 local $^W;
167 4 *{$class.'::declare'} = \&{$CLASS.'::declare'};
168 4 *{$class.'::qv'} = \&{$CLASS.'::qv'};
169 }
170  
171 9 my %args;
172 9 ▶ if (@_) { # any remaining terms are arguments
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 4 5 9
173 4 map { $args{$_} = 1 } @_
174 }
175 else { # no parameters at all on use line
176 5 %args =
177 (
178 qv => 1,
179 'UNIVERSAL::VERSION' => 1,
180 );
181 }
182  
183 9 my $callpkg = caller();
184  
185 9 ▶ if (exists($args{declare})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"declare"}) 4 5 9
186 3 *{$callpkg.'::declare'} =
187 4 ▶ sub {return $class->declare(shift) }
Subroutine __ANON__: called CC=1 SCAR=0.0
188 4 ▶ unless defined(&{$callpkg.'::declare'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$callpkg . '::declare';} 3 1 4
189 }
190  
191 9 ▶ if (exists($args{qv})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"qv"}) 9 0 9
192 7 *{$callpkg.'::qv'} =
193 4 ▶ sub {return $class->qv(shift) }
Subroutine __ANON__: called CC=1 SCAR=0.0
194 9 ▶ unless defined(&{$callpkg.'::qv'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$callpkg . '::qv';} 7 2 9
195 }
196  
197 9 ▶ if (exists($args{'UNIVERSAL::VERSION'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"UNIVERSAL::VERSION"}) 5 4 9
198 1 ▶ no warnings qw/redefine/;
Subroutine BEGIN: called CC=1 SCAR=0.0
199 *UNIVERSAL::VERSION
200 5 = \&{$CLASS.'::_VERSION'};
201 }
202  
203 9 ▶ if (exists($args{'VERSION'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"VERSION"}) 0 9 9
204 0 *{$callpkg.'::VERSION'} = \&{$CLASS.'::_VERSION'};
205 }
206  
207 9 ▶ if (exists($args{'is_strict'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"is_strict"}) 0 9 9
208 0 *{$callpkg.'::is_strict'} = \&{$CLASS.'::is_strict'}
209 0 ▶ unless defined(&{$callpkg.'::is_strict'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$callpkg . '::is_strict';} 0 0 0
210 }
211  
212 9 ▶ if (exists($args{'is_lax'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"is_lax"}) 0 9 9
213 0 *{$callpkg.'::is_lax'} = \&{$CLASS.'::is_lax'}
214 0 ▶ unless defined(&{$callpkg.'::is_lax'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$callpkg . '::is_lax';} 0 0 0
215 }
216 }
217  
218 1 my $VERSION_MAX = 0x7FFFFFFF;
219  
220 # implement prescan_version as closely to the C version as possible
221 1 ▶use constant TRUE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
222 1 ▶use constant FALSE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
223  
224 12894 ▶sub isDIGIT {
Subroutine isDIGIT: called CC=1 SCAR=0.0
Pod undocumented
225 12894 my ($char) = shift->thischar();
226 12894 return ($char =~ /\d/);
227 }
228  
229 1051 ▶sub isALPHA {
Subroutine isALPHA: called CC=1 SCAR=0.0
Pod undocumented
230 1051 my ($char) = shift->thischar();
231 1051 return ($char =~ /[a-zA-Z]/);
232 }
233  
234 1718 ▶sub isSPACE {
Subroutine isSPACE: called CC=1 SCAR=0.0
Pod undocumented
235 1718 my ($char) = shift->thischar();
236 1718 return ($char =~ /\s/);
237 }
238  
239 68 ▶sub BADVERSION {
Subroutine BADVERSION: called CC=2 SCAR=7.0
Pod undocumented
240 68 my ($s, $errstr, $error) = @_;
241 68 ▶ if ($errstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errstr) 68 0 68
242 68 $$errstr = $error;
243 }
244 68 return $s;
245 }
246  
247 615 ▶sub prescan_version {
Subroutine prescan_version: called CC=70 SCAR=51.1
Pod undocumented
248 615 my ($s, $strict, $errstr, $sqv, $ssaw_decimal, $swidth, $salpha) = @_;
249 615 ▶ my $qv = defined $sqv ? $$sqv : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
defined $sqv ? : 615 0 615
250 615 ▶ my $saw_decimal = defined $ssaw_decimal ? $$ssaw_decimal : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $ssaw_decimal ? : 615 0 615
251 615 ▶ my $width = defined $swidth ? $$swidth : 3;
Branch: 1 branch
BranchTrueFalseTotal
defined $swidth ? : 615 0 615
252 615 ▶ my $alpha = defined $salpha ? $$salpha : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
defined $salpha ? : 615 0 615
253  
254 615 my $d = $s;
255  
256 615 ▶ if ($d eq 'v') { # explicit v-string
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq "v") 164 451 615
257 164 $d++;
258 164 ▶ if (isDIGIT($d)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($d)) { } 144 20 164
259 144 $qv = TRUE;
260 }
261 else { # degenerate v-string
262 # requires v1.2.3
263 20 return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions require at least three parts)");
264 }
265 }
266  
267 595 ▶ if ($qv && isDIGIT($d)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qv and isDIGIT($d)) { } 152 443 595
Condition66%2/3
$qv and isDIGIT($d)
!ll&&!rl&&r
4430152
MC/DC50%1/2
$qv and isDIGIT($d)
$qv isDIGIT($d)
Truth table66%2/3
A and B
A= $qvB= isDIGIT($d)
ABresult
0X0
100
111
268 dotted_decimal_version:
269 344 ▶ if ($strict && $d eq '0' && isDIGIT($d+1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict and $d eq 0 and isDIGIT($d + 1)) 0 344 344
Condition33%2/6
$strict and $d eq 0 and isDIGIT($d + 1)
!ll&&!rl&&r
34400
$strict and $d eq 0
!ll&&!rl&&r
34400
MC/DC0%0/3
$strict and $d eq 0 and isDIGIT($d + 1)
$strict $d eq 0 isDIGIT($d + 1)
Truth table25%1/4
A and B and C
A= $strictB= $d eq 0C= isDIGIT($d + 1)
ABCresult
0XX0
10X0
1100
1111
270 # no leading zeros allowed
271 0 return BADVERSION($s,$errstr,"Invalid version format (no leading zeros)");
272 }
273  
274 344 ▶ while (isDIGIT($d)) { # integer part
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($d)) 360 344 704
275 360 $d++;
276 }
277  
278 344 ▶ if ($d eq '.')
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq '.') { } 340 4 344
279 {
280 340 $saw_decimal++;
281 340 $d++; # decimal point
282 }
283 else
284 {
285 4 ▶ if ($strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) { } 0 4 4
286 # require v1.2.3
287 0 return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions require at least three parts)");
288 }
289 else {
290 4 goto version_prescan_finish;
291 }
292 }
293  
294 {
295 340 my $i = 0;
296 340 my $j = 0;
297 340 ▶ while (isDIGIT($d)) { # just keep reading
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($d)) 736 8 744
298 736 $i++;
299 736 ▶ while (isDIGIT($d)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($d)) 948 736 1684
300 948 $d++; $j++;
301 # maximum 3 digits between decimal
302 948 ▶ if ($strict && $j > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict and $j > 3) 0 948 948
Condition33%1/3
$strict and $j > 3
!ll&&!rl&&r
94800
MC/DC0%0/2
$strict and $j > 3
$strict $j > 3
Truth table33%1/3
A and B
A= $strictB= $j > 3
ABresult
0X0
100
111
303 0 return BADVERSION($s,$errstr,"Invalid version format (maximum 3 digits between decimals)");
304 }
305 }
306 736 ▶ if ($d eq '_') {
Branch: 3 branches
BranchTrueFalseTotal
if ($d eq '_') { } 52 684 736
elsif ($d eq '.') { } 352 332 684
elsif (not isDIGIT($d)) { } 332 0 332
307 52 ▶ if ($strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) 0 52 52
308 0 return BADVERSION($s,$errstr,"Invalid version format (no underscores)");
309 }
310 52 ▶ if ( $alpha ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha) 0 52 52
311 0 return BADVERSION($s,$errstr,"Invalid version format (multiple underscores)");
312 }
313 52 $d++;
314 52 $alpha = TRUE;
315 }
316 elsif ($d eq '.') {
317 352 ▶ if ($alpha) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha) 0 352 352
318 0 return BADVERSION($s,$errstr,"Invalid version format (underscores before decimal)");
319 }
320 352 $saw_decimal++;
321 352 $d++;
322 }
323 elsif (!isDIGIT($d)) {
324 332 last;
325 }
326 404 $j = 0;
327 }
328  
329 340 ▶ if ($strict && $i < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict and $i < 2) 0 340 340
Condition33%1/3
$strict and $i < 2
!ll&&!rl&&r
34000
MC/DC0%0/2
$strict and $i < 2
$strict $i < 2
Truth table33%1/3
A and B
A= $strictB= $i < 2
ABresult
0X0
100
111
330 # requires v1.2.3
331 0 return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions require at least three parts)");
332 }
333 }
334 } # end if dotted-decimal
335 else
336 { # decimal versions
337 443 my $j = 0;
338 # special $strict case for leading '.' or '0'
339 443 ▶ if ($strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) 0 443 443
340 0 ▶ if ($d eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq ".") 0 0 0
341 0 return BADVERSION($s,$errstr,"Invalid version format (0 before decimal required)");
342 }
343 0 ▶ if ($d eq '0' && isDIGIT($d+1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq 0 and isDIGIT($d + 1)) 0 0 0
Condition0%0/3
$d eq 0 and isDIGIT($d + 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$d eq 0 and isDIGIT($d + 1)
$d eq 0 isDIGIT($d + 1)
Truth table0%0/3
A and B
A= $d eq 0B= isDIGIT($d + 1)
ABresult
0X0
100
111
344 0 return BADVERSION($s,$errstr,"Invalid version format (no leading zeros)");
345 }
346 }
347  
348 # and we never support negative version numbers
349 443 ▶ if ($d eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq "-") 4 439 443
350 4 return BADVERSION($s,$errstr,"Invalid version format (negative version number)");
351 }
352  
353 # consume all of the integer part
354 439 ▶ while (isDIGIT($d)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($d)) 1799 439 2238
355 1799 $d++;
356 }
357  
358 # look for a fractional part
359 439 ▶ if ($d eq '.') {
Branch: 5 branches
BranchTrueFalseTotal
if ($d eq '.') { } 351 88 439
elsif (not $d or $d eq ';' or isSPACE($d) or $d eq '}') { } 72 16 88
elsif ($d == $s) { } 4 12 16
elsif ($d eq '_') { } 4 8 12
elsif ($d) { } 8 0 8
360 # we found it, so consume it
361 351 $saw_decimal++;
362 351 $d++;
363 }
364 ▶ elsif (!$d || $d eq ';' || isSPACE($d) || $d eq '}') {
Condition77%7/9
not $d or $d eq ";" or isSPACE($d) or $d eq "}"
l!l&&r!l&&!r
72016
not $d or $d eq ";" or isSPACE($d)
l!l&&r!l&&!r
68416
not $d or $d eq ";"
l!l&&r!l&&!r
68020
MC/DC50%2/4
not $d or $d eq ";" or isSPACE($d) or $d eq "}"
not $d $d eq ";" isSPACE($d) $d eq "}"
Truth table60%3/5
not(A) or B or C or D
A= not $dB= $d eq ";"C= isSPACE($d)D= $d eq "}"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
365 72 ▶ if ( $d == $s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d == $s) 0 72 72
366 # found nothing
367 0 return BADVERSION($s,$errstr,"Invalid version format (version required)");
368 }
369 # found just an integer
370 72 goto version_prescan_finish;
371 }
372 elsif ( $d == $s ) {
373 # didn't find either integer or period
374 4 return BADVERSION($s,$errstr,"Invalid version format (non-numeric data)");
375 }
376 elsif ($d eq '_') {
377 # underscore can't come after integer part
378 4 ▶ if ($strict) {
Branch: 2 branches
BranchTrueFalseTotal
if ($strict) { } 0 4 4
elsif (isDIGIT($d + 1)) { } 4 0 4
379 0 return BADVERSION($s,$errstr,"Invalid version format (no underscores)");
380 }
381 elsif (isDIGIT($d+1)) {
382 4 return BADVERSION($s,$errstr,"Invalid version format (alpha without decimal)");
383 }
384 else {
385 0 return BADVERSION($s,$errstr,"Invalid version format (misplaced underscore)");
386 }
387 }
388 elsif ($d) {
389 # anything else after integer part is just invalid data
390 8 return BADVERSION($s,$errstr,"Invalid version format (non-numeric data)");
391 }
392  
393 # scan the fractional part after the decimal point
394 351 ▶ if ($d && !isDIGIT($d) && ($strict || ! ($d eq ';' || isSPACE($d) || $d eq '}') )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d and not isDIGIT($d) and $strict || !($d eq ";" || isSPACE($d) || $d eq "}")) 4 347 351
Condition53%8/15
$d and not isDIGIT($d) and $strict || !($d eq ";" || isSPACE($d) || $d eq "}")
!ll&&!rl&&r
34704
$d and not isDIGIT($d)
!ll&&!rl&&r
1122354
$strict or not $d eq ";" || isSPACE($d) || $d eq "}"
l!l&&r!l&&!r
040
$d eq ';' || isSPACE($d) || $d eq '}'
l!l&&r!l&&!r
004
$d eq ";" or isSPACE($d)
l!l&&r!l&&!r
004
MC/DC33%2/6
$d and not isDIGIT($d) and $strict || !($d eq ";" || isSPACE($d) || $d eq "}")
$d not isDIGIT($d) $strict $d eq ";" isSPACE($d) $d eq '}'
Truth table42%3/7
A and not(B) and C or not(D or E || F)
A= $dB= not isDIGIT($d)C= $strictD= $d eq ";"E= isSPACE($d)F= $d eq '}'
ABCDEFresult
0XXXXX0
10XXXX0
1101XX0
11001X0
1100010
111XXX1
1100001
395 # $strict or lax-but-not-the-end
396 4 return BADVERSION($s,$errstr,"Invalid version format (fractional part required)");
397 }
398  
399 347 ▶ while (isDIGIT($d)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($d)) 699 147 846
400 699 $d++; $j++;
401 699 ▶ if ($d eq '.' && isDIGIT($d-1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq "." and isDIGIT($d - 1)) 196 503 699
Condition66%2/3
$d eq "." and isDIGIT($d - 1)
!ll&&!rl&&r
5030196
MC/DC50%1/2
$d eq "." and isDIGIT($d - 1)
$d eq "." isDIGIT($d - 1)
Truth table66%2/3
A and B
A= $d eq "."B= isDIGIT($d - 1)
ABresult
0X0
100
111
402 196 ▶ if ($alpha) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha) 4 192 196
403 4 return BADVERSION($s,$errstr,"Invalid version format (underscores before decimal)");
404 }
405 192 ▶ if ($strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) 0 192 192
406 0 return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions must begin with 'v')");
407 }
408 192 $d = $s; # start all over again
409 192 $qv = TRUE;
410 192 goto dotted_decimal_version;
411 }
412 503 ▶ if ($d eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d eq "_") 32 471 503
413 32 ▶ if ($strict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) 0 32 32
414 0 return BADVERSION($s,$errstr,"Invalid version format (no underscores)");
415 }
416 32 ▶ if ( $alpha ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha) 4 28 32
417 4 return BADVERSION($s,$errstr,"Invalid version format (multiple underscores)");
418 }
419 28 ▶ if ( ! isDIGIT($d+1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (isDIGIT($d + 1)) 0 28 28
420 0 return BADVERSION($s,$errstr,"Invalid version format (misplaced underscore)");
421 }
422 28 $width = $j;
423 28 $d++;
424 28 $alpha = TRUE;
425 }
426 }
427 }
428  
429 version_prescan_finish:
430 563 ▶ while (isSPACE($d)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isSPACE($d)) 4 563 567
431 4 $d++;
432 }
433  
434 563 ▶ if ($d && !isDIGIT($d) && (! ($d eq ';' || $d eq '}') )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d and not isDIGIT($d) and not $d eq ";" || $d eq "}") 8 555 563
Condition55%5/9
$d and not isDIGIT($d) and not $d eq ";" || $d eq "}"
!ll&&!rl&&r
55508
$d and not isDIGIT($d)
!ll&&!rl&&r
55508
$d eq ';' || $d eq '}'
l!l&&r!l&&!r
008
MC/DC25%1/4
$d and not isDIGIT($d) and not $d eq ";" || $d eq "}"
$d not isDIGIT($d) $d eq ';' $d eq '}'
Truth table40%2/5
A and not(B) and not(C || D)
A= $dB= not isDIGIT($d)C= $d eq ';'D= $d eq '}'
ABCDresult
0XXX0
10XX0
111X0
11010
11001
435 # trailing non-numeric data
436 8 return BADVERSION($s,$errstr,"Invalid version format (non-numeric data)");
437 }
438 555 ▶ if ($saw_decimal > 1 && ($d-1) eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_decimal > 1 and $d - 1 eq ".") 8 547 555
Condition100%3/3
$saw_decimal > 1 and $d - 1 eq "."
!ll&&!rl&&r
2552928
MC/DC100%2/2
$saw_decimal > 1 and $d - 1 eq "."
$saw_decimal > 1 $d - 1 eq "."
Truth table100%3/3
A and B
A= $saw_decimal > 1B= $d - 1 eq "."
ABresult
0X0
100
111
439 # no trailing period allowed
440 8 return BADVERSION($s,$errstr,"Invalid version format (trailing decimal)");
441 }
442  
443 547 ▶ if (defined $sqv) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sqv) 547 0 547
444 547 $$sqv = $qv;
445 }
446 547 ▶ if (defined $swidth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $swidth) 547 0 547
447 547 $$swidth = $width;
448 }
449 547 ▶ if (defined $ssaw_decimal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ssaw_decimal) 547 0 547
450 547 $$ssaw_decimal = $saw_decimal;
451 }
452 547 ▶ if (defined $salpha) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $salpha) 547 0 547
453 547 $$salpha = $alpha;
454 }
455 547 return $d;
456 }
457  
458 615 ▶sub scan_version {
Subroutine scan_version: called CC=46 SCAR=39.0
Pod undocumented
459 615 my ($s, $rv, $qv) = @_;
460 615 my $start;
461 my $pos;
462 615 my $last;
463 615 my $errstr;
464 615 my $saw_decimal = 0;
465 615 my $width = 3;
466 615 my $alpha = FALSE;
467 615 my $vinf = FALSE;
468 615 my @av;
469  
470 615 $s = new charstar $s;
471  
472 615 ▶ while (isSPACE($s)) { # leading whitespace is OK
Branch: 1 branch
BranchTrueFalseTotal
if (isSPACE($s)) 4 615 619
473 4 $s++;
474 }
475  
476 615 $last = prescan_version($s, FALSE, \$errstr, \$qv, \$saw_decimal,
477 \$width, \$alpha);
478  
479 615 ▶ if ($errstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errstr) 68 547 615
480 # 'undef' is a special case and not an error
481 68 ▶ if ( $s ne 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne "undef") 68 0 68
482 68 require Carp;
483 68 Carp::croak($errstr);
484 }
485 }
486  
487 547 $start = $s;
488 547 ▶ if ($s eq 'v') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "v") 144 403 547
489 144 $s++;
490 }
491 547 $pos = $s;
492  
493 547 ▶ if ( $qv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qv) 336 211 547
494 336 $$rv->{qv} = $qv;
495 }
496 547 ▶ if ( $alpha ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha) 72 475 547
497 72 $$rv->{alpha} = $alpha;
498 }
499 547 ▶ if ( !$qv && $width < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $qv and $width < 3) 16 531 547
Condition100%3/3
not $qv and $width < 3
!ll&&!rl&&r
33619516
MC/DC100%2/2
not $qv and $width < 3
not $qv $width < 3
Truth table100%3/3
not(A) and B
A= not $qvB= $width < 3
ABresult
0X0
100
111
500 16 $$rv->{width} = $width;
501 }
502  
503 547 ▶ while (isDIGIT($pos) || $pos eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($pos) or $pos eq "_") 1915 547 2462
Condition66%2/3
isDIGIT($pos) or $pos eq "_"
l!l&&r!l&&!r
19150547
MC/DC50%1/2
isDIGIT($pos) or $pos eq "_"
isDIGIT($pos) $pos eq "_"
Truth table66%2/3
A or B
A= isDIGIT($pos)B= $pos eq "_"
ABresult
1X1
011
000
504 1915 $pos++;
505 }
506 547 ▶ if (!isALPHA($pos)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (isALPHA($pos)) 547 0 547
507 547 my $rev;
508  
509 547 for (;;) {
510 1394 $rev = 0;
511 {
512 # this is atoi() that delimits on underscores
513 1394 my $end = $pos;
514 1394 my $mult = 1;
515 1394 my $orev;
516  
517 # the following if() will only be true after the decimal
518 # point of a version originally created with a bare
519 # floating point number, i.e. not quoted in any way
520 #
521 1394 ▶ if ( !$qv && $s > $start && $saw_decimal == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $qv and $s > $start and $saw_decimal == 1) { } 179 1215 1394
Condition83%5/6
not $qv and $s > $start and $saw_decimal == 1
!ll&&!rl&&r
12150179
not $qv and $s > $start
!ll&&!rl&&r
1004211179
MC/DC66%2/3
not $qv and $s > $start and $saw_decimal == 1
not $qv $s > $start $saw_decimal == 1
Truth table75%3/4
not(A) and B and C
A= not $qvB= $s > $startC= $saw_decimal == 1
ABCresult
0XX0
10X0
1100
1111
522 179 $mult *= 100;
523 179 ▶ while ( $s < $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s < $end) 431 179 610
524 431 ▶ next if $s eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "_" 0 431 431
525 431 $orev = $rev;
526 431 $rev += $s * $mult;
527 431 $mult /= 10;
528 431 ▶ if ( (abs($orev) > abs($rev))
Branch: 1 branch
BranchTrueFalseTotal
if (abs $orev > abs $rev or abs $rev > $VERSION_MAX) 0 431 431
Condition33%1/3
abs $orev > abs $rev or abs $rev > $VERSION_MAX
l!l&&r!l&&!r
00431
MC/DC0%0/2
abs $orev > abs $rev or abs $rev > $VERSION_MAX
abs $orev > abs $rev abs $rev > $VERSION_MAX
Truth table33%1/3
A or B
A= abs $orev > abs $revB= abs $rev > $VERSION_MAX
ABresult
1X1
011
000
529 || (abs($rev) > $VERSION_MAX )) {
530 0 warn("Integer overflow in version %d",
531 $VERSION_MAX);
532 0 $s = $end - 1;
533 0 $rev = $VERSION_MAX;
534 0 $vinf = 1;
535 }
536 431 $s++;
537 431 ▶ if ( $s eq '_' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "_") 20 411 431
538 20 $s++;
539 }
540 }
541 }
542 else {
543 1215 ▶ while (--$end >= $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$end >= $s) 1743 1215 2958
544 1743 ▶ next if $end eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $end eq "_" 52 1691 1743
545 1691 $orev = $rev;
546 1691 $rev += $end * $mult;
547 1691 $mult *= 10;
548 1691 ▶ if ( (abs($orev) > abs($rev))
Branch: 1 branch
BranchTrueFalseTotal
if (abs $orev > abs $rev or abs $rev > $VERSION_MAX) 28 1663 1691
Condition66%2/3
abs $orev > abs $rev or abs $rev > $VERSION_MAX
l!l&&r!l&&!r
0281663
MC/DC50%1/2
abs $orev > abs $rev or abs $rev > $VERSION_MAX
abs $orev > abs $rev abs $rev > $VERSION_MAX
Truth table66%2/3
A or B
A= abs $orev > abs $revB= abs $rev > $VERSION_MAX
ABresult
1X1
011
000
549 || (abs($rev) > $VERSION_MAX )) {
550 28 warn("Integer overflow in version");
551 28 $end = $s - 1;
552 28 $rev = $VERSION_MAX;
553 28 $vinf = 1;
554 }
555 }
556 }
557 }
558  
559 # Append revision
560 1394 push @av, $rev;
561 1394 ▶ if ( $vinf ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($vinf) { } 28 1366 1394
elsif ($pos eq '.') { } 799 567 1366
elsif ($pos eq '_' and isDIGIT($pos + 1)) { } 4 563 567
elsif ($pos eq ',' and isDIGIT($pos + 1)) { } 0 563 563
elsif (isDIGIT($pos)) { } 44 519 563
562 28 $s = $last;
563 28 last;
564 }
565 elsif ( $pos eq '.' ) {
566 799 $s = ++$pos;
567 }
568 ▶ elsif ( $pos eq '_' && isDIGIT($pos+1) ) {
Condition66%2/3
$pos eq "_" and isDIGIT($pos + 1)
!ll&&!rl&&r
56304
MC/DC50%1/2
$pos eq "_" and isDIGIT($pos + 1)
$pos eq "_" isDIGIT($pos + 1)
Truth table66%2/3
A and B
A= $pos eq "_"B= isDIGIT($pos + 1)
ABresult
0X0
100
111
569 4 $s = ++$pos;
570 }
571 ▶ elsif ( $pos eq ',' && isDIGIT($pos+1) ) {
Condition33%1/3
$pos eq "," and isDIGIT($pos + 1)
!ll&&!rl&&r
56300
MC/DC0%0/2
$pos eq "," and isDIGIT($pos + 1)
$pos eq "," isDIGIT($pos + 1)
Truth table33%1/3
A and B
A= $pos eq ","B= isDIGIT($pos + 1)
ABresult
0X0
100
111
572 0 $s = ++$pos;
573 }
574 elsif ( isDIGIT($pos) ) {
575 44 $s = $pos;
576 }
577 else {
578 519 $s = $pos;
579 519 last;
580 }
581 847 ▶ if ( $qv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qv) { } 668 179 847
582 668 ▶ while ( isDIGIT($pos) || $pos eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($pos) or $pos eq "_") 948 668 1616
Condition100%3/3
isDIGIT($pos) or $pos eq "_"
l!l&&r!l&&!r
89652668
MC/DC100%2/2
isDIGIT($pos) or $pos eq "_"
isDIGIT($pos) $pos eq "_"
Truth table100%3/3
A or B
A= isDIGIT($pos)B= $pos eq "_"
ABresult
1X1
011
000
583 948 $pos++;
584 }
585 }
586 else {
587 179 my $digits = 0;
588 179 ▶ while ( ( isDIGIT($pos) || $pos eq '_' ) && $digits < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (isDIGIT($pos) || $pos eq "_" and $digits < 3) 447 179 626
Condition100%6/6
isDIGIT($pos) || $pos eq "_" and $digits < 3
!ll&&!rl&&r
13148447
isDIGIT($pos) or $pos eq "_"
l!l&&r!l&&!r
47520131
MC/DC100%3/3
isDIGIT($pos) || $pos eq "_" and $digits < 3
isDIGIT($pos) $pos eq "_" $digits < 3
Truth table100%5/5
A or B and C
A= isDIGIT($pos)B= $pos eq "_"C= $digits < 3
ABCresult
00X0
1X00
0100
1X11
0111
589 447 ▶ if ( $pos ne '_' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos ne "_") 431 16 447
590 431 $digits++;
591 }
592 447 $pos++;
593 }
594 }
595 }
596 }
597 547 ▶ if ( $qv ) { # quoted versions always get at least three terms
Branch: 1 branch
BranchTrueFalseTotal
if ($qv) 336 211 547
598 336 my $len = $#av;
599 # This for loop appears to trigger a compiler bug on OS X, as it
600 # loops infinitely. Yes, len is negative. No, it makes no sense.
601 # Compiler in question is:
602 # gcc version 3.3 20030304 (Apple Computer, Inc. build 1640)
603 # for ( len = 2 - len; len > 0; len-- )
604 # av_push(MUTABLE_AV(sv), newSViv(0));
605 #
606 336 $len = 2 - $len;
607 336 ▶ while ($len-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len-- > 0) 52 336 388
608 52 push @av, 0;
609 }
610 }
611  
612 # need to save off the current version string for later
613 547 ▶ if ( $vinf ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($vinf) { } 28 519 547
elsif ($s > $start) { } 519 0 519
614 28 $$rv->{original} = "v.Inf";
615 28 $$rv->{vinf} = 1;
616 }
617 elsif ( $s > $start ) {
618 519 $$rv->{original} = $start->currstr($s);
619 519 ▶ if ( $qv && $saw_decimal == 1 && $start ne 'v' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qv and $saw_decimal == 1 and $start ne "v") 4 515 519
Condition100%6/6
$qv and $saw_decimal == 1 and $start ne "v"
!ll&&!rl&&r
479364
$qv and $saw_decimal == 1
!ll&&!rl&&r
18729240
MC/DC100%3/3
$qv and $saw_decimal == 1 and $start ne "v"
$qv $saw_decimal == 1 $start ne "v"
Truth table100%4/4
A and B and C
A= $qvB= $saw_decimal == 1C= $start ne "v"
ABCresult
0XX0
10X0
1100
1111
620 # need to insert a v to be consistent
621 4 $$rv->{original} = 'v' . $$rv->{original};
622 }
623 }
624 else {
625 0 $$rv->{original} = '0';
626 0 push(@av, 0);
627 }
628  
629 # And finally, store the AV in the hash
630 547 $$rv->{version} = \@av;
631  
632 # fix RT#19517 - special case 'undef' as string
633 547 ▶ if ($s eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "undef") 0 547 547
634 0 $s += 5;
635 }
636  
637 547 return $s;
638 }
639  
640 655 ▶sub new {
Subroutine new: called CC=16 SCAR=31.4
Pod undocumented
641 655 my $class = shift;
642 655 ▶ unless (defined $class or $#_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $class or $#_ > 1) 0 655 655
Condition33%1/3
defined $class or $#_ > 1
l!l&&r!l&&!r
65500
MC/DC0%0/2
defined $class or $#_ > 1
defined $class $#_ > 1
Truth table33%1/3
A or B
A= defined $classB= $#_ > 1
ABresult
1X1
011
000
643 0 require Carp;
644 0 Carp::croak('Usage: version::new(class, version)');
645 }
646  
647 655 ▶ my $self = bless ({}, ref ($class) || $class);
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
166390
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
648 655 my $qv = FALSE;
649  
650 655 ▶ if ( $#_ == 1 ) { # must be CVS-style
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == 1) 8 647 655
651 8 $qv = TRUE;
652 }
653 655 my $value = pop; # always going to be the last element
654  
655 655 ▶ if ( ref($value) && eval('$value->isa("version")') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and eval "\$value->isa(\"version\")") 0 655 655
Condition66%2/3
ref $value and eval "\$value->isa(\"version\")"
!ll&&!rl&&r
615400
MC/DC0%0/2
ref $value and eval "\$value->isa(\"version\")"
ref $value eval "\$value->isa(\"version\")"
Truth table66%2/3
A and B
A= ref $valueB= eval "\$value->isa(\"version\")"
ABresult
0X0
100
111
656 # Can copy the elements directly
657 0 $self->{version} = [ @{$value->{version} } ];
658 0 ▶ $self->{qv} = 1 if $value->{qv};
Branch: 1 branch
BranchTrueFalseTotal
if $value->{"qv"} 0 0 0
659 0 ▶ $self->{alpha} = 1 if $value->{alpha};
Branch: 1 branch
BranchTrueFalseTotal
if $value->{"alpha"} 0 0 0
660 0 $self->{original} = ''.$value->{original};
661 0 return $self;
662 }
663  
664 655 ▶ if ( not defined $value or $value =~ /^undef$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or $value =~ /^undef$/) 32 623 655
Condition100%3/3
not defined $value or $value =~ /^undef$/
l!l&&r!l&&!r
2012623
MC/DC100%2/2
not defined $value or $value =~ /^undef$/
not defined $value $value =~ /^undef$/
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value =~ /^undef$/
ABresult
1X1
011
000
665 # RT #19517 - special case for undef comparison
666 # or someone forgot to pass a value
667 32 push @{$self->{version}}, 0;
668 32 $self->{original} = "0";
669 32 return ($self);
670 }
671  
672  
673 623 ▶ if (ref($value) =~ m/ARRAY|HASH/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($value) =~ /ARRAY|HASH/) 8 615 623
674 8 require Carp;
675 8 Carp::croak("Invalid version format (non-numeric data)");
676 }
677  
678 615 $value = _un_vstring($value);
679  
680 615 ▶ if ($Config{d_setlocale}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version::vpp::Config{"d_setlocale"}) 615 0 615
681 1 ▶ use POSIX qw/locale_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
682 1 ▶ use if $Config{d_setlocale}, 'locale';
Subroutine BEGIN: called CC=1 SCAR=0.0
683 615 my $currlocale = setlocale(LC_ALL);
684  
685 # if the current locale uses commas for decimal points, we
686 # just replace commas with decimal places, rather than changing
687 # locales
688 615 ▶ if ( localeconv()->{decimal_point} eq ',' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (localeconv()->{"decimal_point"} eq ",") 0 615 615
689 0 $value =~ tr/,/./;
690 }
691 }
692  
693 # exponential notation
694 615 ▶ if ( $value =~ /\d+.?\d*e[-+]?\d+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\d+.?\d*e[-+]?\d+/) 20 595 615
695 20 $value = sprintf("%.9f",$value);
696 20 $value =~ s/(0+)$//; # trim trailing zeros
697 }
698  
699 615 my $s = scan_version($value, \$self, $qv);
700  
701 547 ▶ if ($s) { # must be something left over
Branch: 1 branch
BranchTrueFalseTotal
if ($s) 0 547 547
702 0 warn(sprintf "Version string '%s' contains invalid data; "
703 ."ignoring: '%s'", $value, $s);
704 }
705  
706 547 return ($self);
707 }
708  
709 1 *parse = \&new;
710  
711 56 ▶sub numify {
Subroutine numify: called CC=7 SCAR=19.6
Pod undocumented
712 56 my ($self) = @_;
713 56 ▶ unless (_verify($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($self)) 0 56 56
714 0 require Carp;
715 0 Carp::croak("Invalid version object");
716 }
717 56 ▶ my $alpha = $self->{alpha} || "";
Condition100%2/2
$self->{'alpha'} || ''
l!l
848
MC/DC100%1/1
$self->{'alpha'} || ''
$self->{'alpha'}
Truth table100%2/2
A
A= $self->{'alpha'}
Aresult
11
00
718 56 my $len = $#{$self->{version}};
719 56 my $digit = $self->{version}[0];
720 56 my $string = sprintf("%d.", $digit );
721  
722 56 ▶ if ($alpha and warnings::enabled()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alpha and warnings::enabled()) 8 48 56
Condition66%2/3
$alpha and warnings::enabled()
!ll&&!rl&&r
4808
MC/DC50%1/2
$alpha and warnings::enabled()
$alpha warnings::enabled()
Truth table66%2/3
A and B
A= $alphaB= warnings::enabled()
ABresult
0X0
100
111
723 8 warnings::warn($WARN_CATEGORY, 'alpha->numify() is lossy');
724 }
725  
726 56 ▶ for ( my $i = 1 ; $i <= $len ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $len) 96 56 152
727 96 $digit = $self->{version}[$i];
728 96 $string .= sprintf("%03d", $digit);
729 }
730  
731 56 ▶ if ( $len == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 0) 4 52 56
732 4 $string .= sprintf("000");
733 }
734  
735 56 return $string;
736 }
737  
738 32 ▶sub normal {
Subroutine normal: called CC=5 SCAR=16.2
Pod undocumented
739 32 my ($self) = @_;
740 32 ▶ unless (_verify($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($self)) 0 32 32
741 0 require Carp;
742 0 Carp::croak("Invalid version object");
743 }
744  
745 32 my $len = $#{$self->{version}};
746 32 my $digit = $self->{version}[0];
747 32 my $string = sprintf("v%d", $digit );
748  
749 32 ▶ for ( my $i = 1 ; $i <= $len ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $len) 56 32 88
750 56 $digit = $self->{version}[$i];
751 56 $string .= sprintf(".%d", $digit);
752 }
753  
754 32 ▶ if ( $len <= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len <= 2) 28 4 32
755 28 ▶ for ( $len = 2 - $len; $len != 0; $len-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len != 0) 12 28 40
756 12 $string .= sprintf(".%0d", 0);
757 }
758 }
759  
760 32 return $string;
761 }
762  
763 346 ▶sub stringify {
Subroutine stringify: called CC=4 SCAR=15.6
Pod undocumented
764 346 my ($self) = @_;
765 346 ▶ unless (_verify($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($self)) 0 346 346
766 0 require Carp;
767 0 Carp::croak("Invalid version object");
768 }
769 return exists $self->{original}
770 ? $self->{original}
771 : exists $self->{qv}
772 346 ▶ ? $self->normal
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'original'} ? : 342 4 346
exists $self->{'qv'} ? : 4 0 4
773 : $self->numify;
774 }
775  
776 4 ▶sub to_decimal {
Subroutine to_decimal: called CC=1 SCAR=0.0
Pod undocumented
777 4 my ($self) = @_;
778 4 return ref($self)->new($self->numify);
779 }
780  
781 4 ▶sub to_dotted_decimal {
Subroutine to_dotted_decimal: called CC=1 SCAR=0.0
Pod undocumented
782 4 my ($self) = @_;
783 4 return ref($self)->new($self->normal);
784 }
785  
786 269 ▶sub vcmp {
Subroutine vcmp: called CC=18 SCAR=29.1
Pod undocumented
787 269 my ($left,$right,$swap) = @_;
788 269 ▶ die "Usage: version::vcmp(lobj, robj, ...)" if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 269 269
789 269 my $class = ref($left);
790 269 ▶ unless ( UNIVERSAL::isa($right, $class) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($right, $class)) 108 161 269
791 108 $right = $class->new($right);
792 }
793  
794 265 ▶ if ( $swap ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($swap) 20 245 265
795 20 ($left, $right) = ($right, $left);
796 }
797 265 ▶ unless (_verify($left)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($left)) 0 265 265
798 0 require Carp;
799 0 Carp::croak("Invalid version object");
800 }
801 265 ▶ unless (_verify($right)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($right)) 0 265 265
802 0 require Carp;
803 0 Carp::croak("Invalid version format");
804 }
805 265 my $l = $#{$left->{version}};
806 265 my $r = $#{$right->{version}};
807 265 ▶ my $m = $l < $r ? $l : $r;
Branch: 1 branch
BranchTrueFalseTotal
$l < $r ? : 41 224 265
808 265 my $lalpha = $left->is_alpha;
809 265 my $ralpha = $right->is_alpha;
810 265 my $retval = 0;
811 265 my $i = 0;
812 265 ▶ while ( $i <= $m && $retval == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $m and $retval == 0) 631 265 896
Condition100%3/3
$i <= $m and $retval == 0
!ll&&!rl&&r
23431631
MC/DC100%2/2
$i <= $m and $retval == 0
$i <= $m $retval == 0
Truth table100%3/3
A and B
A= $i <= $mB= $retval == 0
ABresult
0X0
100
111
813 631 $retval = $left->{version}[$i] <=> $right->{version}[$i];
814 631 $i++;
815 }
816  
817 # possible match except for trailing 0's
818 265 ▶ if ( $retval == 0 && $l != $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval == 0 and $l != $r) 40 225 265
Condition100%3/3
$retval == 0 and $l != $r
!ll&&!rl&&r
1299640
MC/DC100%2/2
$retval == 0 and $l != $r
$retval == 0 $l != $r
Truth table100%3/3
A and B
A= $retval == 0B= $l != $r
ABresult
0X0
100
111
819 40 ▶ if ( $l < $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l < $r) { } 24 16 40
820 24 ▶ while ( $i <= $r && $retval == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $r and $retval == 0) 24 24 48
Condition66%2/3
$i <= $r and $retval == 0
!ll&&!rl&&r
24024
MC/DC50%1/2
$i <= $r and $retval == 0
$i <= $r $retval == 0
Truth table66%2/3
A and B
A= $i <= $rB= $retval == 0
ABresult
0X0
100
111
821 24 ▶ if ( $right->{version}[$i] != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right->{"version"}[$i] != 0) 20 4 24
822 20 $retval = -1; # not a match after all
823 }
824 24 $i++;
825 }
826 }
827 else {
828 16 ▶ while ( $i <= $l && $retval == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $l and $retval == 0) 20 16 36
Condition100%3/3
$i <= $l and $retval == 0
!ll&&!rl&&r
12420
MC/DC100%2/2
$i <= $l and $retval == 0
$i <= $l $retval == 0
Truth table100%3/3
A and B
A= $i <= $lB= $retval == 0
ABresult
0X0
100
111
829 20 ▶ if ( $left->{version}[$i] != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left->{"version"}[$i] != 0) 12 8 20
830 12 $retval = +1; # not a match after all
831 }
832 20 $i++;
833 }
834 }
835 }
836  
837 265 return $retval;
838 }
839  
840 8 ▶sub vbool {
Subroutine vbool: called CC=1 SCAR=0.0
Pod undocumented
841 8 my ($self) = @_;
842 8 return vcmp($self,$self->new("0"),1);
843 }
844  
845 28 ▶sub vnoop {
Subroutine vnoop: called CC=1 SCAR=0.0
Pod undocumented
846 28 require Carp;
847 28 Carp::croak("operation not supported with version object");
848 }
849  
850 542 ▶sub is_alpha {
Subroutine is_alpha: called CC=1 SCAR=0.0
Pod undocumented
851 542 my ($self) = @_;
852 542 return (exists $self->{alpha});
853 }
854  
855 24 ▶sub qv {
Subroutine qv: called CC=4 SCAR=14.1
Pod undocumented
856 24 my $value = shift;
857 24 my $class = $CLASS;
858 24 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 24 0 24
859 24 ▶ $class = ref($value) || $value;
Condition33%1/3
ref $value || $value
l!l&&r!l&&!r
0240
MC/DC0%0/2
ref $value || $value
ref $value $value
Truth table33%1/3
A || B
A= ref $valueB= $value
ABresult
1X1
011
000
860 24 $value = shift;
861 }
862  
863 24 $value = _un_vstring($value);
864 24 ▶ $value = 'v'.$value unless $value =~ /(^v|\d+\.\d+\.\d)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /(^v|\d+\.\d+\.\d)/ 16 8 24
865 24 my $obj = $CLASS->new($value);
866 24 return bless $obj, $class;
867 }
868  
869 1 *declare = \&qv;
870  
871 36 ▶sub is_qv {
Subroutine is_qv: called CC=1 SCAR=0.0
Pod undocumented
872 36 my ($self) = @_;
873 36 return (exists $self->{qv});
874 }
875  
876 4 ▶sub tuple {
Subroutine tuple: called CC=1 SCAR=0.0
Pod undocumented
877 4 my ($self) = @_;
878 4 return @{ $self->{version} };
879 }
880  
881 4 ▶sub from_tuple {
Subroutine from_tuple: called CC=3 SCAR=11.8
Pod undocumented
882 4 my ($proto, @args) = @_;
883 4 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
884  
885 4 my @version = map 0+$_, @args;
886 4 ▶ die if @args < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args < 1 0 4 4
887 4 return bless {
888 version => \@version,
889 qv => !!1,
890 'v' . join('.', @version),
891 }, $class;
892 }
893  
894 964 ▶sub _verify {
Subroutine _verify: called CC=4 SCAR=17.2
895 964 my ($self) = @_;
896 964 ▶ if ( ref($self)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and eval { do { exists $self->{'version'} } } and ref $self->{'version'} eq 'ARRAY') { } 964 0 964
Condition33%2/6
ref $self and eval { do { exists $self->{"version"} } } and ref $self->{"version"} eq "ARRAY"
!ll&&!rl&&r
00964
ref $self and eval { do { exists $self->{"version"} } }
!ll&&!rl&&r
00964
MC/DC0%0/3
ref $self and eval { do { exists $self->{"version"} } } and ref $self->{"version"} eq "ARRAY"
ref $self eval { do { exists $self->{"version"} } } ref $self->{"version"} eq "ARRAY"
Truth table25%1/4
A and B and C
A= ref $selfB= eval { do { exists $self->{"version"} } }C= ref $self->{"version"} eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
897 964 && eval { exists $self->{version} }
898 && ref($self->{version}) eq 'ARRAY'
899 ) {
900 964 return 1;
901 }
902 else {
903 0 return 0;
904 }
905 }
906  
907 184 ▶sub _is_non_alphanumeric {
Subroutine _is_non_alphanumeric: called CC=6 SCAR=17.9
908 184 my $s = shift;
909 184 $s = new charstar $s;
910 184 ▶ while ($s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s) 508 108 616
911 508 ▶ return 0 if isSPACE($s); # early out
Branch: 1 branch
BranchTrueFalseTotal
if isSPACE($s) 4 504 508
912 504 ▶ return 1 unless (isALPHA($s) || isDIGIT($s) || $s =~ /[.-]/);
Branch: 1 branch
BranchTrueFalseTotal
unless isALPHA($s) or isDIGIT($s) or $s =~ /[.-]/ 72 432 504
Condition100%6/6
isALPHA($s) or isDIGIT($s) or $s =~ /[.-]/
l!l&&r!l&&!r
424872
isALPHA($s) or isDIGIT($s)
l!l&&r!l&&!r
22020480
MC/DC100%3/3
isALPHA($s) or isDIGIT($s) or $s =~ /[.-]/
isALPHA($s) isDIGIT($s) $s =~ /[.-]/
Truth table100%4/4
A or B or C
A= isALPHA($s)B= isDIGIT($s)C= $s =~ /[.-]/
ABCresult
1XX1
01X1
0011
0000
913 432 $s++;
914 }
915 108 return 0;
916 }
917  
918 639 ▶sub _un_vstring {
Subroutine _un_vstring: called CC=8 SCAR=23.7
919 639 my $value = shift;
920 # may be a v-string
921 639 ▶ if ( length($value) >= 1 && $value !~ /[,._]/
Branch: 1 branch
BranchTrueFalseTotal
if (length $value >= 1 and not $value =~ /[,._]/ and _is_non_alphanumeric($value)) 72 567 639
Condition83%5/6
length $value >= 1 and not $value =~ /[,._]/ and _is_non_alphanumeric($value)
!ll&&!rl&&r
45511272
length $value >= 1 and not $value =~ /[,._]/
!ll&&!rl&&r
0455184
MC/DC66%2/3
length $value >= 1 and not $value =~ /[,._]/ and _is_non_alphanumeric($value)
length $value >= 1 not $value =~ /[,._]/ _is_non_alphanumeric($value)
Truth table75%3/4
A and not(B) and C
A= length $value >= 1B= not $value =~ /[,._]/C= _is_non_alphanumeric($value)
ABCresult
0XX0
10X0
1100
1111
922 && _is_non_alphanumeric($value)) {
923 72 my $tvalue;
924 72 ▶ if ( $] >= 5.008_001 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($] >= 5.008001) { } 72 0 72
elsif ($] >= 5.006) { } 0 0 0
925 72 $tvalue = _find_magic_vstring($value);
926 72 ▶ $value = $tvalue if length $tvalue;
Branch: 1 branch
BranchTrueFalseTotal
if length $tvalue 60 12 72
927 }
928 elsif ( $] >= 5.006_000 ) {
929 0 $tvalue = sprintf("v%vd",$value);
930 0 ▶ if ( $tvalue =~ /^v\d+(\.\d+)*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tvalue =~ /^v\d+(\.\d+)*$/) 0 0 0
931 # must be a v-string
932 0 $value = $tvalue;
933 }
934 }
935 }
936 639 return $value;
937 }
938  
939 72 ▶sub _find_magic_vstring {
Subroutine _find_magic_vstring: called CC=4 SCAR=14.0
940 72 my $value = shift;
941 72 my $tvalue = '';
942 72 require B;
943 72 my $sv = B::svref_2object(\$value);
944 72 ▶ my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $sv eq 'B::PVMG' ? : 72 0 72
945 72 ▶ while ( $magic ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic) 60 12 72
946 60 ▶ if ( $magic->TYPE eq 'V' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic->TYPE eq 'V') { } 60 0 60
947 60 $tvalue = $magic->PTR;
948 60 $tvalue =~ s/^v?(.+)$/v$1/;
949 60 last;
950 }
951 else {
952 0 $magic = $magic->MOREMAGIC;
953 }
954 }
955 72 $tvalue =~ tr/_//d;
956 72 return $tvalue;
957 }
958  
959 102 ▶sub _VERSION {
Subroutine _VERSION: called CC=14 SCAR=26.7
960 102 my ($obj, $req) = @_;
961 102 ▶ my $class = ref($obj) || $obj;
Condition33%1/3
ref $obj || $obj
l!l&&r!l&&!r
01020
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table33%1/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
962  
963 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
964 102 ▶ if ( exists $INC{"$class.pm"} and not %{"$class\::"} and $] >= 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{"$class.pm"} and not %{"${class}::";} and $] >= "5.008") 4 98 102
Condition83%5/6
exists $INC{"$class.pm"} and not %{"${class}::";} and $] >= "5.008"
!ll&&!rl&&r
9804
exists $INC{"$class.pm"} and not %{"${class}::";}
!ll&&!rl&&r
17814
MC/DC66%2/3
exists $INC{"$class.pm"} and not %{"${class}::";} and $] >= "5.008"
exists $INC{"$class.pm"} not %{"${class}::";} $] >= "5.008"
Truth table75%3/4
A and not(B) and C
A= exists $INC{"$class.pm"}B= not %{"${class}::";}C= $] >= "5.008"
ABCresult
0XX0
10X0
1100
1111
965 # file but no package
966 4 require Carp;
967 4 Carp::croak( "$class defines neither package nor VERSION"
968 ."--version check failed");
969 }
970  
971 98 my $version = eval "\$$class\::VERSION";
972 98 ▶ if ( defined $version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) 74 24 98
973 74 ▶ local $^W if $] <= 5.008;
Branch: 1 branch
BranchTrueFalseTotal
if $] <= "5.008" 0 74 74
974 74 $version = version::vpp->new($version);
975 }
976  
977 90 ▶ if ( defined $req ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req) 65 25 90
978 65 ▶ unless ( defined $version ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 8 57 65
979 8 require Carp;
980 8 ▶ my $msg = $] < 5.006
Branch: 1 branch
BranchTrueFalseTotal
$] < 5.006 ? : 0 8 8
981 ? "$class version $req required--this is only version "
982 : "$class does not define \$$class\::VERSION"
983 ."--version check failed";
984  
985 8 ▶ if ( $ENV{VERSION_DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'VERSION_DEBUG'}) { } 0 8 8
986 0 Carp::confess($msg);
987 }
988 else {
989 8 Carp::croak($msg);
990 }
991 }
992  
993 57 $req = version::vpp->new($req);
994  
995 57 ▶ if ( $req > $version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req > $version) 36 21 57
996 36 require Carp;
997 36 ▶ if ( $req->is_qv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->is_qv) { } 8 28 36
998 8 Carp::croak(
999 sprintf ("%s version %s required--".
1000 "this is only version %s", $class,
1001 $req->normal, $version->normal)
1002 );
1003 }
1004 else {
1005 28 Carp::croak(
1006 sprintf ("%s version %s required--".
1007 "this is only version %s", $class,
1008 $req->stringify, $version->stringify)
1009 );
1010 }
1011 }
1012 }
1013  
1014 46 ▶ return defined $version ? $version->stringify : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 30 16 46
1015 }
1016  
1017 1 1; #this line is important and will help the module return a true value
« version.pm ↑ Summary version/regex.pm »