line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Versioning::Scheme::Semantic; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-04-14'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.010'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
57484
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
457
|
use Role::Tiny; |
|
1
|
|
|
|
|
3386
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
480
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
232
|
|
|
1
|
|
|
|
|
562
|
|
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
|
1154
|
my ($self, $v) = @_; |
26
|
17
|
100
|
|
|
|
163
|
$v =~ $re ? 1:0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub parse_version { |
30
|
1
|
|
|
1
|
1
|
2029
|
my ($self, $v) = @_; |
31
|
1
|
50
|
|
|
|
9
|
$v =~ $re or return undef; |
32
|
|
|
|
|
|
|
return { |
33
|
1
|
|
|
|
|
24
|
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
|
2368
|
my ($self, $v, $opts) = @_; |
43
|
2
|
|
50
|
|
|
11
|
$opts //= {}; |
44
|
|
|
|
|
|
|
|
45
|
2
|
100
|
|
|
|
6
|
die "Invalid version '$v'" unless $self->is_valid_version($v); |
46
|
1
|
|
|
|
|
5
|
$v; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub cmp_version { |
50
|
10
|
|
|
10
|
1
|
2603
|
my ($self, $v1, $v2) = @_; |
51
|
|
|
|
|
|
|
|
52
|
10
|
100
|
|
|
|
90
|
die "Invalid version '$v1'" unless my ($x1, $y1, $z1, $pre1) = $v1 =~ $re; |
53
|
9
|
100
|
|
|
|
57
|
die "Invalid version '$v2'" unless my ($x2, $y2, $z2, $pre2) = $v2 =~ $re; |
54
|
|
|
|
|
|
|
|
55
|
8
|
100
|
100
|
|
|
93
|
($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
|
2415
|
my ($self, $v, $opts) = @_; |
62
|
14
|
|
100
|
|
|
36
|
$opts //= {}; |
63
|
14
|
|
100
|
|
|
43
|
$opts->{num} //= 1; |
64
|
14
|
|
100
|
|
|
37
|
$opts->{part} //= -1; |
65
|
14
|
|
100
|
|
|
57
|
$opts->{reset_smaller} //= 1; |
66
|
|
|
|
|
|
|
|
67
|
14
|
100
|
|
|
|
119
|
die "Invalid version '$v'" unless my ($x, $y, $z, $pre, $meta) = $v =~ $re; |
68
|
13
|
100
|
|
|
|
43
|
die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; |
69
|
12
|
|
|
|
|
26
|
my @parts = ($x, $y, $z); |
70
|
|
|
|
|
|
|
die "Invalid 'part', must not be larger than ".$#parts |
71
|
12
|
100
|
|
|
|
31
|
if $opts->{part} > $#parts; |
72
|
|
|
|
|
|
|
die "Invalid 'part', must not be smaller than -".@parts |
73
|
11
|
100
|
|
|
|
30
|
if $opts->{part} < -@parts; |
74
|
|
|
|
|
|
|
|
75
|
10
|
|
|
|
|
15
|
my $idx = $opts->{part}; |
76
|
10
|
|
50
|
|
|
17
|
$parts[$idx] //= 0; |
77
|
|
|
|
|
|
|
die "Cannot decrease version, would result in a negative number part" |
78
|
10
|
100
|
|
|
|
32
|
if $parts[$idx] + $opts->{num} < 0; |
79
|
9
|
|
|
|
|
13
|
$parts[$idx] = $parts[$idx]+$opts->{num}; |
80
|
9
|
100
|
100
|
|
|
30
|
if ($opts->{reset_smaller} && $opts->{num} > 0) { |
81
|
5
|
100
|
|
|
|
11
|
$idx = @parts + $idx if $idx < 0; |
82
|
5
|
|
|
|
|
13
|
for my $i ($idx+1 .. $#parts) { |
83
|
3
|
|
50
|
|
|
8
|
$parts[$i] //= 0; |
84
|
3
|
|
|
|
|
10
|
$parts[$i] = sprintf("%0".length($parts[$i])."d", 0); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
9
|
100
|
|
|
|
62
|
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__ |