line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Versioning::Scheme::Perl; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-04-14'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
59598
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
450
|
use Role::Tiny; |
|
1
|
|
|
|
|
3468
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
464
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
208
|
|
|
1
|
|
|
|
|
46
|
|
12
|
|
|
|
|
|
|
with 'Role::Versioning::Scheme'; |
13
|
1
|
|
|
1
|
|
350
|
use version; |
|
1
|
|
|
|
|
1490
|
|
|
1
|
|
|
|
|
4
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub is_valid_version { |
16
|
7
|
|
|
7
|
1
|
1094
|
my ($self, $v) = @_; |
17
|
7
|
|
|
|
|
11
|
eval { version->parse($v) }; |
|
7
|
|
|
|
|
42
|
|
18
|
7
|
100
|
|
|
|
34
|
$@ ? 0:1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub parse_version { |
22
|
2
|
|
|
2
|
1
|
2024
|
my ($self, $v) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
4
|
my $vp; |
25
|
2
|
|
|
|
|
3
|
eval { $vp = version->parse($v) }; |
|
2
|
|
|
|
|
13
|
|
26
|
2
|
100
|
|
|
|
11
|
return undef if $@; |
27
|
1
|
|
|
|
|
6
|
$vp =~ s/\Av//; |
28
|
1
|
|
|
|
|
10
|
{parts => [split /\./, $vp]}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub normalize_version { |
32
|
3
|
|
|
3
|
1
|
2488
|
my ($self, $v) = @_; |
33
|
3
|
|
|
|
|
77
|
version->parse($v)->normal; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub cmp_version { |
37
|
7
|
|
|
7
|
1
|
2576
|
my ($self, $v1, $v2) = @_; |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
87
|
version->parse($v1) <=> version->parse($v2); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub bump_version { |
43
|
19
|
|
|
19
|
1
|
2403
|
my ($self, $v, $opts) = @_; |
44
|
19
|
|
100
|
|
|
48
|
$opts //= {}; |
45
|
19
|
|
100
|
|
|
50
|
$opts->{num} //= 1; |
46
|
19
|
|
100
|
|
|
52
|
$opts->{part} //= -1; |
47
|
19
|
|
100
|
|
|
60
|
$opts->{reset_smaller} //= 1; |
48
|
|
|
|
|
|
|
|
49
|
19
|
100
|
|
|
|
41
|
die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; |
50
|
|
|
|
|
|
|
|
51
|
18
|
100
|
|
|
|
44
|
if ($opts->{part} eq 'dev') { |
52
|
3
|
|
|
|
|
18
|
version->parse($v); |
53
|
3
|
|
|
|
|
6
|
my $dev1; |
54
|
3
|
100
|
|
|
|
15
|
if ($v =~ /_([0-9]+)\z/) { $dev1 = $1 } else { $v .= "_000"; $dev1 = "000" } |
|
2
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
55
|
3
|
|
|
|
|
7
|
my $dev2 = $dev1 + $opts->{num}; |
56
|
3
|
50
|
|
|
|
7
|
die "Cannot decrease version, would result in a negative dev part" |
57
|
|
|
|
|
|
|
if $dev2 < 0; |
58
|
3
|
|
|
|
|
14
|
$v =~ s/_([0-9]+)\z/sprintf("_%0".length($dev1)."d", $dev2)/e; |
|
3
|
|
|
|
|
15
|
|
59
|
3
|
|
|
|
|
15
|
return $v; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
15
|
|
|
|
|
118
|
my $vn = version->parse($v)->normal; $vn =~ s/\Av//; |
|
14
|
|
|
|
|
65
|
|
63
|
14
|
|
|
|
|
39
|
my @parts = split /\./, $vn; |
64
|
|
|
|
|
|
|
die "Invalid 'part', must not be smaller than -".@parts |
65
|
14
|
100
|
|
|
|
42
|
if $opts->{part} < -@parts; |
66
|
|
|
|
|
|
|
die "Invalid 'part', must not be larger than ".$#parts |
67
|
13
|
50
|
|
|
|
26
|
if $opts->{part} > $#parts; |
68
|
|
|
|
|
|
|
|
69
|
13
|
100
|
|
|
|
23
|
my $idx = $opts->{part}; $idx = @parts + $idx if $idx < 0; |
|
13
|
|
|
|
|
25
|
|
70
|
|
|
|
|
|
|
# for now, we do not allow decreasing that overflow to the next more |
71
|
|
|
|
|
|
|
# significant part |
72
|
|
|
|
|
|
|
die "Cannot decrease version, would result in a negative part" |
73
|
13
|
100
|
|
|
|
39
|
if $parts[$idx] + $opts->{num} < 0; |
74
|
12
|
|
|
|
|
15
|
my $i = $idx; |
75
|
12
|
|
|
|
|
15
|
my $left = $opts->{num}; |
76
|
12
|
|
|
|
|
16
|
while (1) { |
77
|
17
|
100
|
100
|
|
|
54
|
if ($i == 0 || $parts[$i]+$left < 1000) { |
78
|
12
|
|
|
|
|
15
|
$parts[$i] += $left; |
79
|
12
|
|
|
|
|
14
|
$left = 0; |
80
|
12
|
|
|
|
|
18
|
last; |
81
|
|
|
|
|
|
|
} else { |
82
|
5
|
|
|
|
|
7
|
my $tmp = $parts[$i] + $left; |
83
|
5
|
|
|
|
|
7
|
$parts[$i] = $tmp % 1000; |
84
|
5
|
|
|
|
|
13
|
$left = int($tmp / 1000); |
85
|
5
|
|
|
|
|
5
|
$i--; |
86
|
5
|
|
|
|
|
8
|
next; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
12
|
100
|
100
|
|
|
36
|
if ($opts->{reset_smaller} && $opts->{num} > 0) { |
90
|
8
|
50
|
|
|
|
15
|
$idx = @parts + $idx if $idx < 0; |
91
|
8
|
|
|
|
|
20
|
for my $i ($idx+1 .. $#parts) { |
92
|
3
|
|
50
|
|
|
7
|
$parts[$i] //= 0; |
93
|
3
|
|
|
|
|
11
|
$parts[$i] = sprintf("%0".length($parts[$i])."d", 0); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
12
|
|
|
|
|
130
|
version->parse(join(".", @parts))->normal; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
# ABSTRACT: Perl (version.pm) version numbering |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |