line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Versioning::Scheme::Semantic; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2020-10-01'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.011'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
73075
|
use 5.010001; |
|
1
|
|
|
|
|
12
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
558
|
use Role::Tiny; |
|
1
|
|
|
|
|
4356
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
591
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
316
|
|
|
1
|
|
|
|
|
702
|
|
12
|
|
|
|
|
|
|
with 'Role::Versioning::Scheme'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $re = qr/ |
15
|
|
|
|
|
|
|
\A |
16
|
|
|
|
|
|
|
([0-9]|[1-9][0-9]*)\. # 1=major |
17
|
|
|
|
|
|
|
([0-9]|[1-9][0-9]*)\. # 2=minor |
18
|
|
|
|
|
|
|
([0-9]|[1-9][0-9]*) # 3=major |
19
|
|
|
|
|
|
|
(?:-([0-9]|[1-9][0-9]*|[A-Za-z-][0-9A-Za-z-]*))? # 4=pre-release identifier |
20
|
|
|
|
|
|
|
(?:\+([0-9A-Za-z-]+))? # 5=metadata |
21
|
|
|
|
|
|
|
\z |
22
|
|
|
|
|
|
|
/x; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub is_valid_version { |
25
|
17
|
|
|
17
|
1
|
1230
|
my ($self, $v) = @_; |
26
|
17
|
100
|
|
|
|
204
|
$v =~ $re ? 1:0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub parse_version { |
30
|
1
|
|
|
1
|
1
|
2398
|
my ($self, $v) = @_; |
31
|
1
|
50
|
|
|
|
13
|
$v =~ $re or return undef; |
32
|
|
|
|
|
|
|
return { |
33
|
1
|
|
|
|
|
18
|
major => $1, |
34
|
|
|
|
|
|
|
minor => $2, |
35
|
|
|
|
|
|
|
patch => $3, |
36
|
|
|
|
|
|
|
prerelease => $4, |
37
|
|
|
|
|
|
|
metadata => $5, |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub normalize_version { |
42
|
2
|
|
|
2
|
1
|
2951
|
my ($self, $v, $opts) = @_; |
43
|
2
|
|
50
|
|
|
14
|
$opts //= {}; |
44
|
|
|
|
|
|
|
|
45
|
2
|
100
|
|
|
|
5
|
die "Invalid version '$v'" unless $self->is_valid_version($v); |
46
|
1
|
|
|
|
|
6
|
$v; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub cmp_version { |
50
|
10
|
|
|
10
|
1
|
3275
|
my ($self, $v1, $v2) = @_; |
51
|
|
|
|
|
|
|
|
52
|
10
|
100
|
|
|
|
113
|
die "Invalid version '$v1'" unless my ($x1, $y1, $z1, $pre1) = $v1 =~ $re; |
53
|
9
|
100
|
|
|
|
67
|
die "Invalid version '$v2'" unless my ($x2, $y2, $z2, $pre2) = $v2 =~ $re; |
54
|
|
|
|
|
|
|
|
55
|
8
|
100
|
100
|
|
|
118
|
($x1 <=> $x2) || ($y1 <=> $y2) || ($z1 <=> $z2) || |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
56
|
|
|
|
|
|
|
((defined($pre1) ? 0:1) <=> (defined($pre2) ? 0:1)) || |
57
|
|
|
|
|
|
|
(($pre1//'') cmp ($pre2//'')); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub bump_version { |
61
|
14
|
|
|
14
|
1
|
3285
|
my ($self, $v, $opts) = @_; |
62
|
14
|
|
100
|
|
|
48
|
$opts //= {}; |
63
|
14
|
|
100
|
|
|
47
|
$opts->{num} //= 1; |
64
|
14
|
|
100
|
|
|
45
|
$opts->{part} //= -1; |
65
|
14
|
|
100
|
|
|
51
|
$opts->{reset_smaller} //= 1; |
66
|
|
|
|
|
|
|
|
67
|
14
|
100
|
|
|
|
149
|
die "Invalid version '$v'" unless my ($x, $y, $z, $pre, $meta) = $v =~ $re; |
68
|
13
|
100
|
|
|
|
49
|
die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; |
69
|
12
|
|
|
|
|
32
|
my @parts = ($x, $y, $z); |
70
|
|
|
|
|
|
|
die "Invalid 'part', must not be larger than ".$#parts |
71
|
12
|
100
|
|
|
|
39
|
if $opts->{part} > $#parts; |
72
|
|
|
|
|
|
|
die "Invalid 'part', must not be smaller than -".@parts |
73
|
11
|
100
|
|
|
|
33
|
if $opts->{part} < -@parts; |
74
|
|
|
|
|
|
|
|
75
|
10
|
|
|
|
|
20
|
my $idx = $opts->{part}; |
76
|
10
|
|
50
|
|
|
21
|
$parts[$idx] //= 0; |
77
|
|
|
|
|
|
|
die "Cannot decrease version, would result in a negative number part" |
78
|
10
|
100
|
|
|
|
36
|
if $parts[$idx] + $opts->{num} < 0; |
79
|
9
|
|
|
|
|
18
|
$parts[$idx] = $parts[$idx]+$opts->{num}; |
80
|
9
|
100
|
100
|
|
|
38
|
if ($opts->{reset_smaller} && $opts->{num} > 0) { |
81
|
5
|
100
|
|
|
|
12
|
$idx = @parts + $idx if $idx < 0; |
82
|
5
|
|
|
|
|
16
|
for my $i ($idx+1 .. $#parts) { |
83
|
3
|
|
50
|
|
|
8
|
$parts[$i] //= 0; |
84
|
3
|
|
|
|
|
15
|
$parts[$i] = sprintf("%0".length($parts[$i])."d", 0); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
9
|
100
|
|
|
|
93
|
join("", |
|
|
100
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$parts[0], ".", $parts[1], ".", $parts[2], |
89
|
|
|
|
|
|
|
(defined $pre ? "-$pre" : ""), |
90
|
|
|
|
|
|
|
(defined $meta ? "+$meta" : ""), |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
# ABSTRACT: Semantic versioning |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |