line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Version::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2018-06-10'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.731'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
58552
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
352
|
use version 0.77; |
|
1
|
|
|
|
|
1583
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
80
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
842
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
cmp_version |
14
|
|
|
|
|
|
|
version_eq version_ne |
15
|
|
|
|
|
|
|
version_lt version_le version_gt version_ge |
16
|
|
|
|
|
|
|
version_between version_in |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
min_version max_version |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
add_version subtract_version |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub cmp_version { |
24
|
3
|
|
|
3
|
1
|
1020
|
version->parse($_[0]) <=> version->parse($_[1]); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub version_eq { |
28
|
3
|
|
|
3
|
1
|
2500
|
version->parse($_[0]) == version->parse($_[1]); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub version_ne { |
32
|
3
|
|
|
3
|
1
|
1794
|
version->parse($_[0]) != version->parse($_[1]); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub version_lt { |
36
|
3
|
|
|
3
|
1
|
1867
|
version->parse($_[0]) < version->parse($_[1]); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub version_le { |
40
|
3
|
|
|
3
|
1
|
1813
|
version->parse($_[0]) <= version->parse($_[1]); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub version_gt { |
44
|
3
|
|
|
3
|
1
|
1846
|
version->parse($_[0]) > version->parse($_[1]); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub version_ge { |
48
|
3
|
|
|
3
|
1
|
1835
|
version->parse($_[0]) >= version->parse($_[1]); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub version_between { |
52
|
5
|
|
|
5
|
1
|
1794
|
my $v = version->parse(shift); |
53
|
5
|
|
|
|
|
14
|
while (@_) { |
54
|
7
|
|
|
|
|
11
|
my $v1 = shift; |
55
|
7
|
|
|
|
|
9
|
my $v2 = shift; |
56
|
7
|
100
|
100
|
|
|
83
|
return 1 if $v >= version->parse($v1) && $v <= version->parse($v2); |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
8
|
0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub version_in { |
62
|
3
|
|
|
3
|
1
|
1839
|
my $v = version->parse(shift); |
63
|
3
|
|
|
|
|
9
|
for (@_) { |
64
|
5
|
100
|
|
|
|
43
|
return 1 if $v == version->parse($_); |
65
|
|
|
|
|
|
|
} |
66
|
1
|
|
|
|
|
4
|
0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _max2 { |
70
|
28
|
100
|
|
28
|
|
51
|
$_[0] > $_[1] ? $_[0] : $_[1]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub min_version { |
74
|
1
|
|
|
1
|
1
|
1767
|
my @v = sort { version->parse($a) <=> version->parse($b) } @_; |
|
3
|
|
|
|
|
30
|
|
75
|
1
|
50
|
|
|
|
8
|
@v ? $v[0] : undef; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub max_version { |
79
|
1
|
|
|
1
|
1
|
2088
|
my @v = sort { version->parse($a) <=> version->parse($b) } @_; |
|
3
|
|
|
|
|
26
|
|
80
|
1
|
50
|
|
|
|
8
|
@v ? $v[-1] : undef; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _add_or_subtract_version { |
84
|
14
|
|
|
14
|
|
30
|
my ($which, $v, $inc) = @_; |
85
|
|
|
|
|
|
|
|
86
|
14
|
|
|
|
|
22
|
state $re = qr/\Av?(\d{1,15})(?:\.(\d{1,3}))?(?:\.(\d{1,3}))?\z/; |
87
|
|
|
|
|
|
|
|
88
|
14
|
50
|
|
|
|
100
|
$v =~ $re or die "Invalid version '$v', must match $re"; |
89
|
14
|
|
|
|
|
44
|
my ($v_maj, $v_min, $v_pl) = ($1, $2, $3); |
90
|
14
|
|
100
|
|
|
25
|
$v_min //= ''; |
91
|
14
|
|
100
|
|
|
52
|
$v_pl //= ''; |
92
|
|
|
|
|
|
|
|
93
|
14
|
50
|
|
|
|
55
|
$inc =~ $re or die "Invalid increment '$inc', must match $re"; |
94
|
14
|
|
|
|
|
32
|
my ($inc_maj, $inc_min, $inc_pl) = ($1, $2, $3); |
95
|
14
|
|
50
|
|
|
24
|
$inc_min //= ''; |
96
|
14
|
|
100
|
|
|
37
|
$inc_pl //= ''; |
97
|
|
|
|
|
|
|
|
98
|
14
|
|
|
|
|
28
|
my $width_min = _max2(length($v_min), length($inc_min)); |
99
|
14
|
|
|
|
|
19
|
my $width_pl = _max2(length($v_pl ), length($inc_pl )); |
100
|
|
|
|
|
|
|
|
101
|
14
|
50
|
|
|
|
35
|
$v_min .= "0" x ($width_min-length($v_min)) if $width_min; |
102
|
14
|
100
|
|
|
|
25
|
$v_pl .= "0" x ($width_pl -length($v_pl )) if $width_pl; |
103
|
14
|
50
|
|
|
|
27
|
$inc_min .= "0" x ($width_min-length($inc_min)) if $width_min; |
104
|
14
|
100
|
|
|
|
24
|
$inc_pl .= "0" x ($width_pl -length($inc_pl )) if $width_pl; |
105
|
|
|
|
|
|
|
|
106
|
14
|
100
|
|
|
|
23
|
if ($which eq 'subtract') { |
107
|
4
|
50
|
|
|
|
10
|
$inc_min = "-$inc_min" if length($inc_min); |
108
|
4
|
100
|
|
|
|
8
|
$inc_pl = "-$inc_pl" if length($inc_pl ); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
14
|
50
|
33
|
|
|
31
|
$v_min = 0 if !length($v_min) && $width_min; |
112
|
14
|
50
|
66
|
|
|
35
|
$v_pl = 0 if !length($v_pl) && $width_pl; |
113
|
14
|
50
|
33
|
|
|
23
|
$inc_min = 0 if !length($inc_min) && $width_min; |
114
|
14
|
50
|
66
|
|
|
48
|
$inc_pl = 0 if !length($inc_pl) && $width_pl; |
115
|
|
|
|
|
|
|
|
116
|
14
|
100
|
|
|
|
22
|
if ($width_pl) { |
117
|
4
|
|
|
|
|
7
|
my $limit = "1" . ("0" x $width_pl); |
118
|
4
|
|
|
|
|
8
|
$v_pl += $inc_pl; |
119
|
4
|
50
|
|
|
|
13
|
if ($v_pl < 0) { |
|
|
50
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
$v_pl += $limit; |
121
|
0
|
|
|
|
|
0
|
$v_min--; |
122
|
|
|
|
|
|
|
} elsif ($v_pl >= $limit) { |
123
|
0
|
|
|
|
|
0
|
$v_pl -= $limit; |
124
|
0
|
|
|
|
|
0
|
$v_min++; |
125
|
|
|
|
|
|
|
} |
126
|
4
|
|
|
|
|
8
|
$v_pl = ("0" x ($width_pl -length($v_pl))) . $v_pl |
127
|
|
|
|
|
|
|
} |
128
|
14
|
50
|
|
|
|
20
|
if ($width_min) { |
129
|
14
|
|
|
|
|
26
|
my $limit = "1" . ("0" x $width_min); |
130
|
14
|
|
|
|
|
21
|
$v_min += $inc_min; |
131
|
14
|
100
|
|
|
|
34
|
if ($v_min < 0) { |
|
|
100
|
|
|
|
|
|
132
|
3
|
|
|
|
|
4
|
$v_min += $limit; |
133
|
3
|
|
|
|
|
5
|
$v_maj--; |
134
|
|
|
|
|
|
|
} elsif ($v_min >= $limit) { |
135
|
3
|
|
|
|
|
4
|
$v_min -= $limit; |
136
|
3
|
|
|
|
|
5
|
$v_maj++; |
137
|
|
|
|
|
|
|
} |
138
|
14
|
|
|
|
|
29
|
$v_min = ("0" x ($width_min -length($v_min))) . $v_min; |
139
|
|
|
|
|
|
|
} |
140
|
14
|
|
|
|
|
21
|
$v_maj += $inc_maj; |
141
|
14
|
100
|
|
|
|
30
|
die "Version subtraction results in negative version ($v - $inc)" |
142
|
|
|
|
|
|
|
if $v_maj < 0; |
143
|
|
|
|
|
|
|
|
144
|
13
|
50
|
|
|
|
75
|
$v_maj . ($width_min ? ".$v_min" : '') . ($width_pl ? ".$v_pl" : ""); |
|
|
100
|
|
|
|
|
|
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub add_version { |
148
|
10
|
|
|
10
|
1
|
1923
|
_add_or_subtract_version('add', @_); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub subtract_version { |
152
|
4
|
|
|
4
|
1
|
2043
|
_add_or_subtract_version('subtract', @_); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
# ABSTRACT: Version-number utilities |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
__END__ |