line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Versioning::Scheme::Monotonic; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-04-14'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
63206
|
use 5.010001; |
|
1
|
|
|
|
|
13
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
375
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
4245
|
|
|
1
|
|
|
|
|
551
|
|
11
|
|
|
|
|
|
|
with 'Role::Versioning::Scheme'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $re = qr/ |
14
|
|
|
|
|
|
|
\A |
15
|
|
|
|
|
|
|
([1-9][0-9]*)\. # 1=compatibility |
16
|
|
|
|
|
|
|
([1-9][0-9]*) # 2=release |
17
|
|
|
|
|
|
|
(?:\.(0))? # 3=semver_marker |
18
|
|
|
|
|
|
|
(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))? # 4=metadata |
19
|
|
|
|
|
|
|
\z |
20
|
|
|
|
|
|
|
/x; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub is_valid_version { |
23
|
13
|
|
|
13
|
1
|
1083
|
my ($self, $v) = @_; |
24
|
13
|
100
|
|
|
|
121
|
$v =~ $re ? 1:0; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub parse_version { |
28
|
0
|
|
|
0
|
1
|
0
|
my ($self, $v) = @_; |
29
|
0
|
0
|
|
|
|
0
|
return undef unless my ($c, $r, $mark, $meta) = $v =~ $re; |
30
|
|
|
|
|
|
|
return { |
31
|
0
|
|
|
|
|
0
|
compatibility => $1, |
32
|
|
|
|
|
|
|
release => $2, |
33
|
|
|
|
|
|
|
semver_marker => $3, |
34
|
|
|
|
|
|
|
metadata => $4, |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub normalize_version { |
39
|
3
|
|
|
3
|
1
|
2414
|
my ($self, $v, $opts) = @_; |
40
|
3
|
|
50
|
|
|
15
|
$opts //= {}; |
41
|
|
|
|
|
|
|
|
42
|
3
|
100
|
|
|
|
38
|
die "Invalid version '$v'" unless $v =~ $re; |
43
|
|
|
|
|
|
|
|
44
|
2
|
50
|
|
|
|
19
|
"$1.$2" . (defined $4 ? ".$4" : ""); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub cmp_version { |
48
|
8
|
|
|
8
|
1
|
2621
|
my ($self, $v1, $v2) = @_; |
49
|
|
|
|
|
|
|
|
50
|
8
|
100
|
|
|
|
123
|
die "Invalid version '$v1'" unless my ($c1, $r1, undef, $m1) = $v1 =~ $re; |
51
|
7
|
100
|
|
|
|
47
|
die "Invalid version '$v2'" unless my ($c2, $r2, undef, $m2) = $v2 =~ $re; |
52
|
|
|
|
|
|
|
|
53
|
6
|
100
|
100
|
|
|
58
|
($c1 <=> $c2) || ($r1 <=> $r2) || (($m1||'') cmp ($m2||'')); |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub bump_version { |
57
|
15
|
|
|
15
|
1
|
2594
|
my ($self, $v, $opts) = @_; |
58
|
15
|
|
100
|
|
|
41
|
$opts //= {}; |
59
|
15
|
|
100
|
|
|
45
|
$opts->{num} //= 1; |
60
|
15
|
|
100
|
|
|
41
|
$opts->{part} //= 1; |
61
|
|
|
|
|
|
|
|
62
|
15
|
100
|
|
|
|
143
|
die "Invalid version '$v'" unless my ($c, $r, $mark, $meta) = $v =~ $re; |
63
|
14
|
50
|
|
|
|
34
|
die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; |
64
|
14
|
100
|
|
|
|
61
|
die "Invalid 'part', must be 0|1" unless $opts->{part} =~ /\A(0|1)\z/; |
65
|
|
|
|
|
|
|
|
66
|
12
|
100
|
|
|
|
25
|
if ($opts->{part} == 0) { |
67
|
2
|
50
|
|
|
|
8
|
if ($c + $opts->{num} < 1) { |
68
|
0
|
|
|
|
|
0
|
die "Cannot decrease compatibility that would result in zero/negative number"; |
69
|
|
|
|
|
|
|
} |
70
|
2
|
100
|
|
|
|
10
|
if ($r + ($opts->{num} < 0 ? -1 : 1) < 1) { |
|
|
50
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
die "Cannot decrease compatibility that would result in zero/negative release number"; |
72
|
|
|
|
|
|
|
} |
73
|
2
|
|
|
|
|
3
|
$c = $c + $opts->{num}; |
74
|
2
|
100
|
|
|
|
4
|
$r = $r + ($opts->{num} < 0 ? -1 : 1); |
75
|
|
|
|
|
|
|
} else { |
76
|
10
|
100
|
|
|
|
26
|
if ($r + $opts->{num} < 1) { |
77
|
3
|
|
|
|
|
22
|
die "Cannot decrease release that would result in zero/negative number"; |
78
|
|
|
|
|
|
|
} |
79
|
7
|
|
|
|
|
12
|
$r = $r + $opts->{num}; |
80
|
|
|
|
|
|
|
} |
81
|
9
|
100
|
|
|
|
55
|
join( |
|
|
50
|
|
|
|
|
|
82
|
|
|
|
|
|
|
"", |
83
|
|
|
|
|
|
|
$c, ".", $r, |
84
|
|
|
|
|
|
|
(defined $mark ? ".$mark" : ""), |
85
|
|
|
|
|
|
|
(defined $meta ? ".$meta" : ""), |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
# ABSTRACT: Monotonic versioning |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |