version/vpp.pm

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