Versioning/Scheme/Semantic.pm

filter: Statementstmt 100% 52 / 52 Branchbran 97.0% 33 / 34 Conditioncond 86.6% 26 / 30 MC/DCmcdc 53.3% 8 / 15 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 91.7% 134 / 146 CC 32 SCAR 24.3
CC
32
Cov
96%
bump_version
18.0
cmp_version
11.0
normalize_version
3.0
CRAP 11.4
« Versioning/Scheme/Perl.pm ↑ Summary Versioning/Scheme/Dotted.pm »
1 package Versioning::Scheme::Semantic;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 with 'Role::Versioning::Scheme';
13  
14 2 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 17 ▶sub is_valid_version {
Subroutine is_valid_version: called CC=2 SCAR=6.9
Pod documented
25 17 my ($self, $v) = @_;
26 17 ▶ $v =~ $re ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /$Versioning::Scheme::Semantic::re/ ? : 7 10 17
27 }
28  
29 1 ▶sub parse_version {
Subroutine parse_version: called CC=2 SCAR=7.1
Pod documented
30 1 my ($self, $v) = @_;
31 1 ▶ $v =~ $re or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /$Versioning::Scheme::Semantic::re/ or return undef 1 0 1
32 return {
33 1 major => $1,
34 minor => $2,
35 patch => $3,
36 prerelease => $4,
37 metadata => $5,
38 };
39 }
40  
41 2 ▶sub normalize_version {
Subroutine normalize_version: called CC=3 SCAR=11.0
Pod documented
42 2 my ($self, $v, $opts) = @_;
43 2 ▶ $opts //= {};
Condition50%1/2
$opts //= {}
l!l
02
MC/DC0%0/1
$opts //= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
44  
45 2 ▶ die "Invalid version '$v'" unless $self->is_valid_version($v);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_version($v) 1 1 2
46 1 $v;
47 }
48  
49 10 ▶sub cmp_version {
Subroutine cmp_version: called CC=11 SCAR=24.0
Pod documented
50 10 my ($self, $v1, $v2) = @_;
51  
52 10 ▶ die "Invalid version '$v1'" unless my ($x1, $y1, $z1, $pre1) = $v1 =~ $re;
Branch: 1 branch
BranchTrueFalseTotal
unless () = $v1 =~ /$Versioning::Scheme::Semantic::re/ 1 9 10
53 9 ▶ die "Invalid version '$v2'" unless my ($x2, $y2, $z2, $pre2) = $v2 =~ $re;
Branch: 1 branch
BranchTrueFalseTotal
unless () = $v2 =~ /$Versioning::Scheme::Semantic::re/ 1 8 9
54  
55 8 ▶ ($x1 <=> $x2) || ($y1 <=> $y2) || ($z1 <=> $z2) ||
Branch: 3 branches
BranchTrueFalseTotal
$x1 <=> $x2 or $y1 <=> $y2 or $z1 <=> $z2 or (defined $pre1 ? 0 : 1) <=> (defined $pre2 ? 0 : 1) or ($pre1 // "") cmp ($pre2 // "") 4 4 8
defined $pre1 ? : 2 4 6
defined $pre2 ? : 4 2 6
Condition92%12/13
$x1 <=> $x2 or $y1 <=> $y2 or $z1 <=> $z2 or (defined $pre1 ? 0 : 1) <=> (defined $pre2 ? 0 : 1)
l!l&&r!l&&!r
224
$x1 <=> $x2 or $y1 <=> $y2 or $z1 <=> $z2
l!l&&r!l&&!r
206
$x1 <=> $x2 or $y1 <=> $y2
l!l&&r!l&&!r
116
$pre1 // ""
l!l
22
$pre2 // ""
l!l
22
MC/DC0%0/4
$x1 <=> $x2 or $y1 <=> $y2 or $z1 <=> $z2 or (defined $pre1 ? 0 : 1) <=> (defined $pre2 ? 0 : 1)
$x1 <=> $x2 $y1 <=> $y2 $z1 <=> $z2 (defined $pre1 ? 0 : 1) <=> (defined $pre2 ? 0 : 1)
MC/DC100%1/1
$pre1 // ""
$pre1
MC/DC100%1/1
$pre2 // ""
$pre2
Truth table0%0/5
A or B or C or D
A= $x1 <=> $x2B= $y1 <=> $y2C= $z1 <=> $z2D= (defined $pre1 ? 0 : 1) <=> (defined $pre2 ? 0 : 1)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table100%2/2
A
A= $pre1
Aresult
11
00
Truth table100%2/2
A
A= $pre2
Aresult
11
00
56 ((defined($pre1) ? 0:1) <=> (defined($pre2) ? 0:1)) ||
57 (($pre1//'') cmp ($pre2//''));
58 }
59  
60 14 ▶sub bump_version {
Subroutine bump_version: called CC=18 SCAR=28.9
Pod documented
61 14 my ($self, $v, $opts) = @_;
62 14 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
113
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
63 14 ▶ $opts->{num} //= 1;
Condition100%2/2
$opts->{"num"} //= 1
l!l
68
MC/DC100%1/1
$opts->{"num"} //= 1
$opts->{"num"}
Truth table100%2/2
A
A= $opts->{"num"}
Aresult
11
00
64 14 ▶ $opts->{part} //= -1;
Condition100%2/2
$opts->{"part"} //= -1
l!l
68
MC/DC100%1/1
$opts->{"part"} //= -1
$opts->{"part"}
Truth table100%2/2
A
A= $opts->{"part"}
Aresult
11
00
65 14 ▶ $opts->{reset_smaller} //= 1;
Condition100%2/2
$opts->{"reset_smaller"} //= 1
l!l
113
MC/DC100%1/1
$opts->{"reset_smaller"} //= 1
$opts->{"reset_smaller"}
Truth table100%2/2
A
A= $opts->{"reset_smaller"}
Aresult
11
00
66  
67 14 ▶ die "Invalid version '$v'" unless my ($x, $y, $z, $pre, $meta) = $v =~ $re;
Branch: 1 branch
BranchTrueFalseTotal
unless () = $v =~ /$Versioning::Scheme::Semantic::re/ 1 13 14
68 13 ▶ die "Invalid 'num', must be non-zero" unless $opts->{num} != 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"num"} != 0 1 12 13
69 12 my @parts = ($x, $y, $z);
70 die "Invalid 'part', must not be larger than ".$#parts
71 12 ▶ if $opts->{part} > $#parts;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"part"} > $#parts 1 11 12
72 die "Invalid 'part', must not be smaller than -".@parts
73 11 ▶ if $opts->{part} < -@parts;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"part"} < -@parts 1 10 11
74  
75 10 my $idx = $opts->{part};
76 10 ▶ $parts[$idx] //= 0;
Condition50%1/2
$parts[$idx] //= 0
l!l
100
MC/DC0%0/1
$parts[$idx] //= 0
$parts[$idx]
Truth table50%1/2
A
A= $parts[$idx]
Aresult
11
00
77 die "Cannot decrease version, would result in a negative number part"
78 10 ▶ if $parts[$idx] + $opts->{num} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $parts[$idx] + $opts->{"num"} < 0 1 9 10
79 9 $parts[$idx] = $parts[$idx]+$opts->{num};
80 9 ▶ if ($opts->{reset_smaller} && $opts->{num} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"reset_smaller"} and $opts->{"num"} > 0) 5 4 9
Condition100%3/3
$opts->{"reset_smaller"} and $opts->{"num"} > 0
!ll&&!rl&&r
135
MC/DC100%2/2
$opts->{"reset_smaller"} and $opts->{"num"} > 0
$opts->{"reset_smaller"} $opts->{"num"} > 0
Truth table100%3/3
A and B
A= $opts->{"reset_smaller"}B= $opts->{"num"} > 0
ABresult
0X0
100
111
81 5 ▶ $idx = @parts + $idx if $idx < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 4 1 5
82 5 for my $i ($idx+1 .. $#parts) {
83 3 ▶ $parts[$i] //= 0;
Condition50%1/2
$parts[$i] //= 0
l!l
30
MC/DC0%0/1
$parts[$i] //= 0
$parts[$i]
Truth table50%1/2
A
A= $parts[$i]
Aresult
11
00
84 3 $parts[$i] = sprintf("%0".length($parts[$i])."d", 0);
85 }
86 }
87 9 ▶ join("",
Branch: 2 branches
BranchTrueFalseTotal
defined $pre ? : 1 8 9
defined $meta ? : 1 8 9
88 $parts[0], ".", $parts[1], ".", $parts[2],
89 (defined $pre ? "-$pre" : ""),
90 (defined $meta ? "+$meta" : ""),
91 );
92 }
93  
94 2 1;
95 # ABSTRACT: Semantic versioning
96  
97 __END__
« Versioning/Scheme/Perl.pm ↑ Summary Versioning/Scheme/Dotted.pm »