Versioning/Scheme/Perl.pm

filter: Statementstmt 100% 80 / 80 Branchbran 88.4% 23 / 26 Conditioncond 93.7% 15 / 16 MC/DCmcdc 88.8% 8 / 9 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 96.6% 142 / 147 CC 22 SCAR 25.7
CC
22
Cov
97%
bump_version
20.0
is_valid_version
2.0
parse_version
2.0
CRAP 13.0
↑ Summary Versioning/Scheme/Semantic.pm »
1 package Versioning::Scheme::Perl;
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 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶sub is_valid_version {
Subroutine is_valid_version: called CC=2 SCAR=6.9
Pod documented
16 7 my ($self, $v) = @_;
17 7 eval { version->parse($v) };
18 7 ▶ $@ ? 0:1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 2 5 7
19 }
20  
21 2 ▶sub parse_version {
Subroutine parse_version: called CC=2 SCAR=6.9
Pod documented
22 2 my ($self, $v) = @_;
23  
24 2 my $vp;
25 2 eval { $vp = version->parse($v) };
26 2 ▶ return undef if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1 2
27 1 $vp =~ s/\Av//;
28 1 {parts => [split /\./, $vp]};
29 }
30  
31 3 ▶sub normalize_version {
Subroutine normalize_version: called CC=1 SCAR=0.0
Pod documented
32 3 my ($self, $v) = @_;
33 3 version->parse($v)->normal;
34 }
35  
36 7 ▶sub cmp_version {
Subroutine cmp_version: called CC=1 SCAR=0.0
Pod documented
37 7 my ($self, $v1, $v2) = @_;
38  
39 7 version->parse($v1) <=> version->parse($v2);
40 }
41  
42 19 ▶sub bump_version {
Subroutine bump_version: called CC=20 SCAR=30.0
Pod documented
43 19 my ($self, $v, $opts) = @_;
44 19 ▶ $opts //= {};
Condition100%2/2
$opts //= {}
l!l
172
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
Aresult
11
00
45 19 ▶ $opts->{num} //= 1;
Condition100%2/2
$opts->{"num"} //= 1
l!l
118
MC/DC100%1/1
$opts->{"num"} //= 1
$opts->{"num"}
Truth table100%2/2
A
A= $opts->{"num"}
Aresult
11
00
46 19 ▶ $opts->{part} //= -1;
Condition100%2/2
$opts->{"part"} //= -1
l!l
811
MC/DC100%1/1
$opts->{"part"} //= -1
$opts->{"part"}
Truth table100%2/2
A
A= $opts->{"part"}
Aresult
11
00
47 19 ▶ $opts->{reset_smaller} //= 1;
Condition100%2/2
$opts->{"reset_smaller"} //= 1
l!l
118
MC/DC100%1/1
$opts->{"reset_smaller"} //= 1
$opts->{"reset_smaller"}
Truth table100%2/2
A
A= $opts->{"reset_smaller"}
Aresult
11
00
48  
49 19 ▶ die "Invalid 'num', must be non-zero" unless $opts->{num} != 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"num"} != 0 1 18 19
50  
51 18 ▶ if ($opts->{part} eq 'dev') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"part"} eq "dev") 3 15 18
52 3 version->parse($v);
53 3 my $dev1;
54 3 ▶ if ($v =~ /_([0-9]+)\z/) { $dev1 = $1 } else { $v .= "_000"; $dev1 = "000" }
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /_([0-9]+)\z/) { } 2 1 3
55 3 my $dev2 = $dev1 + $opts->{num};
56 3 ▶ die "Cannot decrease version, would result in a negative dev part"
Branch: 1 branch
BranchTrueFalseTotal
if $dev2 < 0 0 3 3
57 if $dev2 < 0;
58 3 $v =~ s/_([0-9]+)\z/sprintf("_%0".length($dev1)."d", $dev2)/e;
59 3 return $v;
60 }
61  
62 15 my $vn = version->parse($v)->normal; $vn =~ s/\Av//;
63 14 my @parts = split /\./, $vn;
64 die "Invalid 'part', must not be smaller than -".@parts
65 14 ▶ if $opts->{part} < -@parts;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"part"} < -@parts 1 13 14
66 die "Invalid 'part', must not be larger than ".$#parts
67 13 ▶ if $opts->{part} > $#parts;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"part"} > $#parts 0 13 13
68  
69 13 ▶ my $idx = $opts->{part}; $idx = @parts + $idx if $idx < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 12 1 13
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 ▶ if $parts[$idx] + $opts->{num} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $parts[$idx] + $opts->{"num"} < 0 1 12 13
74 12 my $i = $idx;
75 12 my $left = $opts->{num};
76 12 while (1) {
77 17 ▶ if ($i == 0 || $parts[$i]+$left < 1000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 or $parts[$i] + $left < 1000) { } 12 5 17
Condition100%3/3
$i == 0 or $parts[$i] + $left < 1000
l!l&&r!l&&!r
2105
MC/DC100%2/2
$i == 0 or $parts[$i] + $left < 1000
$i == 0 $parts[$i] + $left < 1000
Truth table100%3/3
A or B
A= $i == 0B= $parts[$i] + $left < 1000
ABresult
1X1
011
000
78 12 $parts[$i] += $left;
79 12 $left = 0;
80 12 last;
81 } else {
82 5 my $tmp = $parts[$i] + $left;
83 5 $parts[$i] = $tmp % 1000;
84 5 $left = int($tmp / 1000);
85 5 $i--;
86 5 next;
87 }
88 }
89 12 ▶ if ($opts->{reset_smaller} && $opts->{num} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"reset_smaller"} and $opts->{"num"} > 0) 8 4 12
Condition100%3/3
$opts->{"reset_smaller"} and $opts->{"num"} > 0
!ll&&!rl&&r
138
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
90 8 ▶ $idx = @parts + $idx if $idx < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 0 8 8
91 8 for my $i ($idx+1 .. $#parts) {
92 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
93 3 $parts[$i] = sprintf("%0".length($parts[$i])."d", 0);
94 }
95 }
96 12 version->parse(join(".", @parts))->normal;
97 }
98  
99 2 1;
100 # ABSTRACT: Perl (version.pm) version numbering
101  
102 __END__
↑ Summary Versioning/Scheme/Semantic.pm »