| 1 | package Versioning::Scheme::Dotted; | ||||||||||||||||||||||||||||
| 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/\A[0-9]+(?:\.[0-9]+)*\z/; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 39 | ▶ | sub is_valid_version { | ||||||||||||||||||||||||||
|
Subroutine
is_valid_version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 39 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 18 | 39 | ▶ | $v =~ $re ? 1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | sub parse_version { | ||||||||||||||||||||||||||
|
Subroutine
parse_version: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | $v =~ $re or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 1 | {parts => [split /\./, $v]}; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 7 | ▶ | sub normalize_version { | ||||||||||||||||||||||||||
|
Subroutine
normalize_version: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 7 | my ($self, $v, $opts) = @_; | |||||||||||||||||||||||||||
| 29 | 7 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts //= {}
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 7 | ▶ | die "Invalid version '$v'" unless $self->is_valid_version($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | my @parts = split /\./, $v; | |||||||||||||||||||||||||||
| 34 | 6 | ▶ | if (defined $opts->{parts}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 4 | ▶ | die "parts must at least be 1" unless $opts->{parts} >= 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | if ($opts->{parts} < @parts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | splice @parts, $opts->{parts}; | |||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||
| 39 | 2 | ▶ | $parts[$opts->{parts}-1] //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$parts[$opts->{"parts"} - 1] //= 0
MC/DC0%0/1
$parts[$opts->{"parts"} - 1] //= 0
$parts[$opts->{"parts"} - 1]
Truth table50%1/2
A
A= $parts[$opts->{"parts"} - 1]
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 5 | ▶ | join(".", map { $_ // "0" } @parts); | ||||||||||||||||||||||||||
|
Condition100%2/2
$_ // 0
MC/DC100%1/1
$_ // 0
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 7 | ▶ | sub cmp_version { | ||||||||||||||||||||||||||
|
Subroutine
cmp_version: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 7 | my ($self, $v1, $v2) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 7 | ▶ | die "Invalid version '$v1'" unless $self->is_valid_version($v1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | die "Invalid version '$v2'" unless $self->is_valid_version($v2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 5 | my @parts1 = split /\./, $v1; | |||||||||||||||||||||||||||
| 52 | 5 | my @parts2 = split /\./, $v2; | |||||||||||||||||||||||||||
| 53 | 5 | ▶ | my $n = @parts1 < @parts2 ? @parts2 : @parts1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 5 | for my $i (0..$n-1) { | |||||||||||||||||||||||||||
| 55 | 12 | ▶ | my $cmp = ($parts1[$i] // 0) <=> ($parts2[$i] // 0); | ||||||||||||||||||||||||||
|
Condition75%3/4
$parts1[$i] // 0
$parts2[$i] // 0
MC/DC0%0/1
$parts1[$i] // 0
$parts1[$i]
MC/DC100%1/1
$parts2[$i] // 0
$parts2[$i]
Truth table50%1/2
A
A= $parts1[$i]
Truth table100%2/2
A
A= $parts2[$i]
| |||||||||||||||||||||||||||||
| 56 | 12 | ▶ | return $cmp if $cmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 3 | 0; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 12 | ▶ | sub bump_version { | ||||||||||||||||||||||||||
|
Subroutine
bump_version: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 12 | my ($self, $v, $opts) = @_; | |||||||||||||||||||||||||||
| 63 | 12 | ▶ | $opts //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts //= {}
MC/DC100%1/1
$opts //= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||||||||||
| 64 | 12 | ▶ | $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"}
| |||||||||||||||||||||||||||||
| 65 | 12 | ▶ | $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"}
| |||||||||||||||||||||||||||||
| 66 | 12 | ▶ | $opts->{reset_smaller} //= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"reset_smaller"} //= 1
MC/DC100%1/1
$opts->{"reset_smaller"} //= 1
$opts->{"reset_smaller"}
Truth table100%2/2
A
A= $opts->{"reset_smaller"}
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 12 | ▶ | die "Invalid version '$v'" unless $self->is_valid_version($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 11 | ▶ | die "Invalid 'num', must be non-zero" unless $opts->{num} != 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 10 | my @parts = split /\./, $v; | |||||||||||||||||||||||||||
| 71 | die "Invalid 'part', must not be smaller than -".@parts | ||||||||||||||||||||||||||||
| 72 | 10 | ▶ | if $opts->{part} < -@parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 9 | my $idx = $opts->{part}; | |||||||||||||||||||||||||||
| 75 | 9 | ▶ | $parts[$idx] //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$parts[$idx] //= 0
MC/DC0%0/1
$parts[$idx] //= 0
$parts[$idx]
Truth table50%1/2
A
A= $parts[$idx]
| |||||||||||||||||||||||||||||
| 76 | die "Cannot decrease version, would result in a negative part" | ||||||||||||||||||||||||||||
| 77 | 9 | ▶ | if $parts[$idx] + $opts->{num} < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | $parts[$idx] = sprintf("%0".length($parts[$idx])."d", | ||||||||||||||||||||||||||||
| 79 | 8 | $parts[$idx]+$opts->{num}); | |||||||||||||||||||||||||||
| 80 | 8 | ▶ | if ($opts->{reset_smaller} && $opts->{num} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"reset_smaller"} and $opts->{"num"} > 0
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
| |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | $idx = @parts + $idx if $idx < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 4 | for my $i ($idx+1 .. $#parts) { | |||||||||||||||||||||||||||
| 83 | 3 | ▶ | $parts[$i] //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$parts[$i] //= 0
MC/DC0%0/1
$parts[$i] //= 0
$parts[$i]
Truth table50%1/2
A
A= $parts[$i]
| |||||||||||||||||||||||||||||
| 84 | 3 | $parts[$i] = sprintf("%0".length($parts[$i])."d", 0); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 8 | ▶ | join(".", map {$_//0} @parts); | ||||||||||||||||||||||||||
|
Condition50%1/2
$_ // 0
MC/DC0%0/1
$_ // 0
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||
| 91 | # ABSTRACT: Version as dotted numbers | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||