| 1 | package Versioning::Scheme::Monotonic; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | our $DATE = '2020-10-01'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.011'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | with 'Role::Versioning::Scheme'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | 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 | 13 | ▶ | sub is_valid_version { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid_version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | $v =~ $re ? 1:0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub parse_version { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_version: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return undef unless my ($c, $r, $mark, $meta) = $v =~ $re; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | compatibility => $1, | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | release => $2, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | semver_marker => $3, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | metadata => $4, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | sub normalize_version { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_version: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | my ($self, $v, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts //= {}
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | die "Invalid version '$v'" unless $v =~ $re; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | "$1.$2" . (defined $4 ? ".$4" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | sub cmp_version { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmp_version: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | my ($self, $v1, $v2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | ▶ | die "Invalid version '$v1'" unless my ($c1, $r1, undef, $m1) = $v1 =~ $re; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | ▶ | die "Invalid version '$v2'" unless my ($c2, $r2, undef, $m2) = $v2 =~ $re; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | ($c1 <=> $c2) || ($r1 <=> $r2) || (($m1||'') cmp ($m2||'')); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%7/7
$c1 <=> $c2 or $r1 <=> $r2
$m1 || ''
$m2 || ''
MC/DC100%2/2
$c1 <=> $c2 or $r1 <=> $r2
$c1 <=> $c2
$r1 <=> $r2
MC/DC100%1/1
$m1 || ''
$m1
MC/DC100%1/1
$m2 || ''
$m2
Truth table100%3/3
A or B
A= $c1 <=> $c2B= $r1 <=> $r2
Truth table100%2/2
A
A= $m1
Truth table100%2/2
A
A= $m2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | sub bump_version { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bump_version: called CC=15 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 15 | my ($self, $v, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 15 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts //= {}
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 15 | ▶ | $opts->{num} //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"num"} //= 1
MC/DC100%1/1
$opts->{"num"} //= 1
$opts->{"num"}
Truth table100%2/2
A
A= $opts->{"num"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 15 | ▶ | $opts->{part} //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"part"} //= 1
MC/DC100%1/1
$opts->{"part"} //= 1
$opts->{"part"}
Truth table100%2/2
A
A= $opts->{"part"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | die "Invalid version '$v'" unless my ($c, $r, $mark, $meta) = $v =~ $re; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 14 | ▶ | die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 14 | ▶ | die "Invalid 'part', must be 0|1" unless $opts->{part} =~ /\A(0|1)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 12 | ▶ | if ($opts->{part} == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | if ($c + $opts->{num} < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | die "Cannot decrease compatibility that would result in zero/negative number"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if ($r + ($opts->{num} < 0 ? -1 : 1) < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | die "Cannot decrease compatibility that would result in zero/negative release number"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $c = $c + $opts->{num}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | $r = $r + ($opts->{num} < 0 ? -1 : 1); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | if ($r + $opts->{num} < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | die "Cannot decrease release that would result in zero/negative number"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | $r = $r + $opts->{num}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | join( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | "", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $c, ".", $r, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | (defined $mark ? ".$mark" : ""), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | (defined $meta ? ".$meta" : ""), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # ABSTRACT: Monotonic versioning | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||