Changes/Version.pm

filter: Statementstmt 70.4% 386 / 548 Branchbran 46.4% 158 / 340 Conditioncond 44.3% 138 / 311 MC/DCmcdc 16.6% 28 / 168 Subroutinesub 63.1% 60 / 95 Podpod 100% 38 / 38 totaltotal 53.8% 808 / 1500 CC 287 SCAR 42.5
CC
287
Cov
57%
_bubble
462.0
_inc_dec
147.4
_cascade
118.8
CRAP 69.9
« Changes.pm ↑ Summary Changes/Release.pm »
1 ##----------------------------------------------------------------------------
2 ## Changes file management - ~/lib/Changes/Version.pm
3 ## Version v0.2.3
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/12/01
7 ## Modified 2025/07/28
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package Changes::Version;
15 BEGIN
16 20 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 20 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 20 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 20 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 20 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 20 ▶ use vars qw( $VERSION $VERSION_LAX_REGEX $DEFAULT_TYPE );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 20 ▶ use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 # From version::regex
24 # Comments in the regular expression below are taken from version::regex
25 20 our $VERSION_LAX_REGEX = qr/
26 (?<ver_str>
27 # Lax dotted-decimal version number. Distinguished by having either leading "v"
28 # or at least three non-alpha parts. Alpha part is only permitted if there are
29 # at least two non-alpha parts. Strangely enough, without the leading "v", Perl
30 # takes .1.2 to mean v0.1.2, so when there is no "v", the leading part is optional
31 (?<dotted>
32 (?<has_v>v)
33 (?<ver>
34 (?<major>[0-9]+)
35 (?:
36 (?<minor_patch>(?:\.[0-9]+)+)
37 (?:_(?<alpha>[0-9]+))?
38 )?
39 )
40 |
41 (?<ver>
42 (?<major>[0-9]+)?
43 (?<minor_patch>(?:\.[0-9]+){2,})
44 (?:_(?<alpha>[0-9]+))?
45 )
46 )
47 |
48 (?<dotted>
49 (?<dotted_numified>
50 (?<dotted_numified_under>
51 (?<ver>
52 (?<release>
53 (?<major>[0-9]+)
54 (?<minor_patch>
55 \.
56 (?<minor>[0-9]{3})
57 (?:_(?<patch>[0-9]{3}))
58 )
59 )
60 )
61 )
62 |
63 (?<ver>
64 (?<release>
65 (?<major>[0-9]+)
66 (?<minor_patch>
67 \.
68 (?<minor>0[0-9]{2})
69 (?<patch>0[0-9]{2})
70 )
71 )
72 (?:_(?<alpha>[0-9]+))?
73 )
74 )
75 )
76 |
77 # Lax decimal version number. Just like the strict one except for allowing an
78 # alpha suffix or allowing a leading or trailing decimal-point
79 (?<decimal>
80 (?<ver>(?<release>(?<major>[0-9]+) (?: (?:\.(?<minor>[0-9]+)) | \. )?) (?:_(?<alpha>[0-9]+))?)
81 |
82 (?<ver>(?:\.(?<release>(?<major>[0-9]+))) (?:_(?<alpha>[0-9]+))?)
83 )
84 )/x;
85 20 our $DEFAULT_TYPE = 'dotted';
86 20 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
87 '""' => \&as_string,
88 # '=' => \&clone,
89 0 ▶ '0+' => sub{ $_[0]->numify->as_string },
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 '<=>' => \&_compare,
91 'cmp' => \&_compare,
92 'bool' => \&_bool,
93 12 ▶ '+' => sub { return( shift->_compute( @_, { op => '+' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
94 12 ▶ '-' => sub { return( shift->_compute( @_, { op => '-' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
95 12 ▶ '*' => sub { return( shift->_compute( @_, { op => '*' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
96 12 ▶ '/' => sub { return( shift->_compute( @_, { op => '/' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 8 ▶ '+=' => sub { return( shift->_compute( @_, { op => '+=' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
98 8 ▶ '-=' => sub { return( shift->_compute( @_, { op => '-=' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 8 ▶ '*=' => sub { return( shift->_compute( @_, { op => '*=' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
100 8 ▶ '/=' => sub { return( shift->_compute( @_, { op => '/=' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 8 ▶ '++' => sub { return( shift->_compute( @_, { op => '++' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
102 8 ▶ '--' => sub { return( shift->_compute( @_, { op => '--' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
103 # We put it here so perl won't trigger the noop overload method
104 16 ▶ '=' => sub { $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
105 20 'abs' => \&_noop,
106 'nomethod' => \&_noop,
107 20 );
108 20 our $VERSION = 'v0.2.3';
109 };
110  
111 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 sub init
115 139 ▶{
Subroutine init: called CC=14 SCAR=27.7
Pod documented
116 139 my $self = shift( @_ );
117 139 $self->{alpha} = undef;
118 # Used for other version types
119 139 $self->{beta} = undef;
120 139 $self->{compat} = 0;
121 # What version fragment to increase/decrease by default, such as when we do operations like $v++ or $v--
122 139 $self->{default_frag} = 'minor';
123 139 $self->{extra} = [];
124 139 $self->{major} = undef;
125 139 $self->{minor} = undef;
126 139 $self->{original} = undef;
127 139 $self->{padded} = 1;
128 139 $self->{patch} = undef;
129 139 $self->{pattern} = undef;
130 139 $self->{pretty} = 0;
131 139 $self->{qv} = 0;
132 # Release candidate used by non-perl open source softwares
133 139 $self->{rc} = undef;
134 139 $self->{target} = 'perl';
135 139 $self->{type} = undef;
136 139 my $keys = [qw( alpha beta compat default_frag extra major minor original patch qv rc target type _version )];
137 139 my $vstr;
138 # Changes::Version->new( 'v0.1.2_3' ); or
139 # Changes::Version->new( 'v0.1.2_3', alpha => 4 ); or
140 # Changes::Version->new( 'v0.1.2_3', { alpha => 4 } ); or
141 # Changes::Version->new( major => 0, minor => 1, patch => 2, alpha => 3, qv => 1 ); or
142 # Changes::Version->new({ major => 0, minor => 1, patch => 2, alpha => 3, qv => 1 }); or
143 139 ▶ if( ( @_ == 1 && ref( $_[0] ) ne 'HASH' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] ne "HASH" or @_ > 1 and ref $_[0] ne "HASH" and @_ % 2 || ref $_[1] eq "HASH") 42 97 139
Condition53%8/15
@_ == 1 and ref $_[0] ne "HASH" or @_ > 1 and ref $_[0] ne "HASH" and @_ % 2 || ref $_[1] eq "HASH"
l!l&&r!l&&!r
04297
@_ == 1 and ref $_[0] ne "HASH"
!ll&&!rl&&r
13900
@_ > 1 and ref $_[0] ne "HASH" and @_ % 2 || ref $_[1] eq "HASH"
!ll&&!rl&&r
09742
@_ > 1 and ref $_[0] ne "HASH"
!ll&&!rl&&r
00139
@_ % 2 or ref $_[1] eq "HASH"
l!l&&r!l&&!r
42097
MC/DC16%1/6
@_ == 1 and ref $_[0] ne "HASH" or @_ > 1 and ref $_[0] ne "HASH" and @_ % 2 || ref $_[1] eq "HASH"
@_ == 1 ref $_[0] ne "HASH" @_ > 1 ref $_[0] ne "HASH" @_ % 2 ref $_[1] eq "HASH"
Truth table18%2/11
A and B or C and D and E or F
A= @_ == 1B= ref $_[0] ne "HASH"C= @_ > 1D= ref $_[0] ne "HASH"E= @_ % 2F= ref $_[1] eq "HASH"
ABCDEFresult
11XXXX1
0X111X1
0X11011
10111X1
1011011
0X0XXX0
0X10XX0
0X11000
100XXX0
1010XX0
1011000
144 ( @_ > 1 && ref( $_[0] ) ne 'HASH' && ( ( @_ % 2 ) || ref( $_[1] ) eq 'HASH' ) ) )
145 {
146 42 $vstr = shift( @_ );
147 42 ▶ return( $self->error( "version string provided is empty." ) ) if( !defined( $vstr ) || !length( "$vstr" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vstr and length "$vstr" 0 42 42
Condition33%1/3
defined $vstr and length "$vstr"
!ll&&!rl&&r
0042
MC/DC0%0/2
defined $vstr and length "$vstr"
defined $vstr length "$vstr"
Truth table33%1/3
A and B
A= defined $vstrB= length "$vstr"
ABresult
0X0
100
111
148 # So we can get options like debug for parser
149 42 my $opts = $self->_get_args_as_hash( @_ );
150 42 ▶ $self->debug( $opts->{debug} ) if( exists( $opts->{debug} ) && defined( $opts->{debug} ) && length( "$opts->{debug}" ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"debug"} and defined $opts->{"debug"} and length qq[$opts->{"debug"}] 2 40 42
Condition66%4/6
exists $opts->{"debug"} and defined $opts->{"debug"} and length qq[$opts->{"debug"}]
!ll&&!rl&&r
4002
exists $opts->{"debug"} and defined $opts->{"debug"}
!ll&&!rl&&r
0402
MC/DC33%1/3
exists $opts->{"debug"} and defined $opts->{"debug"} and length qq[$opts->{"debug"}]
exists $opts->{"debug"} defined $opts->{"debug"} length qq[$opts->{"debug"}]
Truth table50%2/4
A and B and C
A= exists $opts->{"debug"}B= defined $opts->{"debug"}C= length qq[$opts->{"debug"}]
ABCresult
0XX0
10X0
1100
1111
151 # A version string was provided, so we parse it
152 42 my $v = $self->parse( $vstr );
153 42 ▶ return( $self->pass_error ) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 42 42
154 # And we copy the collected value as default values for our new object, which can then be overriden by additional option passed here.
155 42 @$self{ @$keys } = @$v{ @$keys };
156 }
157 139 $self->{_init_strict_use_sub} = 1;
158 139 my $rv = $self->SUPER::init( @_ );
159 139 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 139 139
160 139 return( $self );
161 }
162  
163 418 ▶sub alpha { return( shift->reset(@_)->_set_get_number( { field => 'alpha', undef_ok => 1 }, @_ ) ); }
Subroutine alpha: called CC=1 SCAR=0.0
Pod documented
164  
165 sub as_string
166 309 ▶{
Subroutine as_string: called CC=30 SCAR=38.7
Pod documented
167 309 my $self = shift( @_ );
168 309 ▶ if( !exists( $self->{_reset} ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_reset"} and defined $self->{"_reset"} and length $self->{"_reset"}) 192 117 309
Condition66%4/6
exists $self->{"_reset"} and defined $self->{"_reset"} and length $self->{"_reset"}
!ll&&!rl&&r
1920117
exists $self->{"_reset"} and defined $self->{"_reset"}
!ll&&!rl&&r
1920117
MC/DC33%1/3
exists $self->{"_reset"} and defined $self->{"_reset"} and length $self->{"_reset"}
exists $self->{"_reset"} defined $self->{"_reset"} length $self->{"_reset"}
Truth table50%2/4
A and B and C
A= exists $self->{"_reset"}B= defined $self->{"_reset"}C= length $self->{"_reset"}
ABCresult
0XX0
10X0
1100
1111
169 !defined( $self->{_reset} ) ||
170 !CORE::length( $self->{_reset} ) )
171 {
172 192 ▶ if( exists( $self->{_cache_value} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'_cache_value'} and defined $self->{'_cache_value'} and length $self->{'_cache_value'}) { } 68 124 192
elsif (defined $self->{'original'} and length "$self->{'original'}") { } 124 0 124
Condition66%4/6
exists $self->{"_cache_value"} and defined $self->{"_cache_value"} and length $self->{"_cache_value"}
!ll&&!rl&&r
124068
exists $self->{"_cache_value"} and defined $self->{"_cache_value"}
!ll&&!rl&&r
124068
MC/DC33%1/3
exists $self->{"_cache_value"} and defined $self->{"_cache_value"} and length $self->{"_cache_value"}
exists $self->{"_cache_value"} defined $self->{"_cache_value"} length $self->{"_cache_value"}
Truth table50%2/4
A and B and C
A= exists $self->{"_cache_value"}B= defined $self->{"_cache_value"}C= length $self->{"_cache_value"}
ABCresult
0XX0
10X0
1100
1111
173 defined( $self->{_cache_value} ) &&
174 length( $self->{_cache_value} ) )
175 {
176 68 return( $self->{_cache_value} );
177 }
178 ▶ elsif( defined( $self->{original} ) && length( "$self->{original}" ) )
Condition33%1/3
defined $self->{"original"} and length qq[$self->{"original"}]
!ll&&!rl&&r
00124
MC/DC0%0/2
defined $self->{"original"} and length qq[$self->{"original"}]
defined $self->{"original"} length qq[$self->{"original"}]
Truth table33%1/3
A and B
A= defined $self->{"original"}B= length qq[$self->{"original"}]
ABresult
0X0
100
111
179 {
180 124 return( $self->{original}->scalar );
181 }
182 }
183 117 my $type = $self->type;
184 117 my $str;
185 117 ▶ if( ( defined( $type ) && $type eq 'dotted' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and $type eq 'dotted' or not defined $type and $Changes::Version::DEFAULT_TYPE eq 'dotted') { } 59 58 117
Condition88%8/9
defined $type and $type eq "dotted" or not defined $type and $Changes::Version::DEFAULT_TYPE eq "dotted"
l!l&&r!l&&!r
55458
defined $type and $type eq "dotted"
!ll&&!rl&&r
54585
not defined $type and $Changes::Version::DEFAULT_TYPE eq "dotted"
!ll&&!rl&&r
58054
MC/DC25%1/4
defined $type and $type eq "dotted" or not defined $type and $Changes::Version::DEFAULT_TYPE eq "dotted"
defined $type $type eq "dotted" not defined $type $Changes::Version::DEFAULT_TYPE eq "dotted"
Truth table42%3/7
A and B or not(C) and D
A= defined $typeB= $type eq "dotted"C= not defined $typeD= $Changes::Version::DEFAULT_TYPE eq "dotted"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
186 ( !defined( $type ) && $DEFAULT_TYPE eq 'dotted' ) )
187 {
188 59 $str = $self->normal( raw => 1 );
189 }
190 else
191 {
192 58 my $minor = $self->minor;
193 58 my $patch = $self->patch;
194 58 my $fmt = $self->pattern;
195 58 ▶ if( defined( $fmt ) && length( $fmt ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt and length $fmt) { } 1 57 58
Condition66%2/3
defined $fmt and length $fmt
!ll&&!rl&&r
5701
MC/DC50%1/2
defined $fmt and length $fmt
defined $fmt length $fmt
Truth table66%2/3
A and B
A= defined $fmtB= length $fmt
ABresult
0X0
100
111
196 {
197 1 $str = $self->format( $fmt );
198 }
199 else
200 {
201 57 ▶ if( defined( $minor ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minor and index($minor, '_') != -1 || length $minor == 3 && substr($minor, 0, 1) eq '0' || length(($patch // '') || $self->padded)) { } 57 0 57
Condition47%8/17
defined $minor and index($minor, "_") != -1 || length $minor == 3 && substr($minor, 0, 1) eq 0 || length(($patch // "") || $self->padded)
!ll&&!rl&&r
0057
index($minor, "_") != -1 or length $minor == 3 and substr($minor, 0, 1) eq 0 or length(($patch // "") || $self->padded)
l!l&&r!l&&!r
0570
index($minor, "_") != -1 or length $minor == 3 and substr($minor, 0, 1) eq 0
l!l&&r!l&&!r
0057
length $minor == 3 and substr($minor, 0, 1) eq 0
!ll&&!rl&&r
5700
($patch // '') || $self->padded
l!l&&r!l&&!r
32250
$patch // ""
l!l
552
MC/DC0%0/6
defined $minor and index($minor, "_") != -1 || length $minor == 3 && substr($minor, 0, 1) eq 0 || length(($patch // "") || $self->padded)
defined $minor index($minor, "_") != -1 length $minor == 3 substr($minor, 0, 1) eq 0 $patch $self->padded
Truth table22%2/9
A and B or C and D or E || F
A= defined $minorB= index($minor, "_") != -1C= length $minor == 3D= substr($minor, 0, 1) eq 0E= $patchF= $self->padded
ABCDEFresult
0XXXXX0
100X000
1010000
11XXXX1
1011XX1
100X1X1
100X011
10101X1
1010011
202 (
203 index( $minor, '_' ) != -1 ||
204 ( length( $minor ) == 3 && substr( $minor, 0, 1 ) eq '0' ) ||
205 length( $patch // '' ||
206 $self->padded )
207 ) )
208 {
209 57 $str = $self->numify( raw => 1 );
210 57 ▶ if( !$self->padded && index( $str, '_' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->padded and index($str, "_") == -1) 2 55 57
Condition66%2/3
not $self->padded and index($str, "_") == -1
!ll&&!rl&&r
5502
MC/DC50%1/2
not $self->padded and index($str, "_") == -1
not $self->padded index($str, "_") == -1
Truth table66%2/3
not(A) and B
A= not $self->paddedB= index($str, "_") == -1
ABresult
0X0
100
111
211 {
212 2 return( $str * 1 );
213 }
214  
215 55 ▶ if( $self->pretty && index( $str, '_' ) == -1 && !( length( [split( /\./, $str )]->[1] ) % 3 ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pretty and index($str, "_") == -1 and not length([split(/\./, $str, 0)]->[1]) % 3) 3 52 55
Condition83%5/6
$self->pretty and index($str, "_") == -1 and not length([split(/\./, $str, 0)]->[1]) % 3
!ll&&!rl&&r
5203
$self->pretty and index($str, "_") == -1
!ll&&!rl&&r
5113
MC/DC66%2/3
$self->pretty and index($str, "_") == -1 and not length([split(/\./, $str, 0)]->[1]) % 3
$self->pretty index($str, "_") == -1 not length([split(/\./, $str, 0)]->[1]) % 3
Truth table75%3/4
A and B and not(C)
A= $self->prettyB= index($str, "_") == -1C= not length([split(/\./, $str, 0)]->[1]) % 3
ABCresult
0XX0
10X0
1100
1111
216 {
217 # $str = join( '_', grep{ $_ ne ''} split( /(...)/, $str ) );
218 # Credit: <https://stackoverflow.com/questions/33442240/perl-printf-to-use-commas-as-thousands-separator>
219 3 ▶ while( $str =~ s/(\d+)(\d{3})/$1\_$2/ ){};
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/(\d+)(\d{3})/$1_$2/) 2 3 5
220 }
221 }
222 else
223 {
224 0 my $alpha = $self->alpha;
225 0 ▶ $str = $self->major . ( defined( $minor ) ? ".${minor}" : '' ) . ( defined( $alpha ) ? "_${alpha}" : '' );
Branch: 2 branches
BranchTrueFalseTotal
defined $minor ? : 0 0 0
defined $alpha ? : 0 0 0
226 }
227 }
228 }
229 115 $self->{_cache_value} = $str;
230 115 CORE::delete( $self->{_reset} );
231 115 return( $str );
232 }
233  
234 {
235 20 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
236 20 *stringify = \&as_string;
237 }
238  
239 0 ▶sub beta { return( shift->reset(@_)->_set_get_number( { field => 'beta', undef_ok => 1 }, @_ ) ); }
Subroutine beta: not called CC=1 SCAR=6.9
Pod documented
240  
241 # NOTE: clone() is inherited
242  
243 0 ▶sub compat { return( shift->_set_get_boolean( 'compat', @_ ) ); }
Subroutine compat: not called CC=1 SCAR=6.9
Pod documented
244  
245 0 ▶sub dec { return( shift->_inc_dec( 'dec', @_ ) ); }
Subroutine dec: not called CC=1 SCAR=6.9
Pod documented
246  
247 0 ▶sub dec_alpha { return( shift->_inc_dec( 'dec' => 'alpha', @_ ) ); }
Subroutine dec_alpha: not called CC=1 SCAR=6.9
Pod documented
248  
249 # For non-perl open source softwares
250 0 ▶sub dec_beta { return( shift->_inc_dec( 'dec' => 'beta', @_ ) ); }
Subroutine dec_beta: not called CC=1 SCAR=6.9
Pod documented
251  
252 0 ▶sub dec_major { return( shift->_inc_dec( 'dec' => 'major', @_ ) ); }
Subroutine dec_major: not called CC=1 SCAR=6.9
Pod documented
253  
254 0 ▶sub dec_minor { return( shift->_inc_dec( 'dec' => 'minor', @_ ) ); }
Subroutine dec_minor: not called CC=1 SCAR=6.9
Pod documented
255  
256 0 ▶sub dec_patch { return( shift->_inc_dec( 'dec' => 'patch', @_ ) ); }
Subroutine dec_patch: not called CC=1 SCAR=6.9
Pod documented
257  
258 192 ▶sub default_frag { return( shift->_set_get_scalar_as_object( 'default_frag', @_ ) ); }
Subroutine default_frag: called CC=1 SCAR=0.0
Pod documented
259  
260 386 ▶sub extra { return( shift->_set_get_array_as_object( 'extra', @_ ) ); }
Subroutine extra: called CC=1 SCAR=0.0
Pod documented
261  
262 sub format
263 1 ▶{
Subroutine format: called CC=11 SCAR=39.4
Pod documented
264 1 my $self = shift( @_ );
265 1 ▶ my $fmt = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No pattern was provided to format this version.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No pattern was provided to format this version.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
266 return( $self->error( "No pattern was provided to format this version." ) );
267 # NOTE: numify()
268 my $numify = sub
269 1 ▶ {
Subroutine __ANON__: called CC=8 SCAR=30.1
270 1 ▶ my $sep = shift( @_ ) || '';
Condition50%1/2
shift @_ || ''
l!l
01
MC/DC0%0/1
shift @_ || ''
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
271 1 my $minor = $self->minor;
272 1 my $patch = $self->patch;
273 1 ▶ if( defined( $minor ) && length( $minor ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $minor and length $minor) { } 1 0 1
elsif (defined $patch and length $patch) { } 0 0 0
Condition33%1/3
defined $minor and length $minor
!ll&&!rl&&r
001
MC/DC0%0/2
defined $minor and length $minor
defined $minor length $minor
Truth table33%1/3
A and B
A= defined $minorB= length $minor
ABresult
0X0
100
111
274 {
275 1 ▶ if( defined( $patch ) && length( $patch ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $patch and length $patch) { } 1 0 1
Condition33%1/3
defined $patch and length $patch
!ll&&!rl&&r
001
MC/DC0%0/2
defined $patch and length $patch
defined $patch length $patch
Truth table33%1/3
A and B
A= defined $patchB= length $patch
ABresult
0X0
100
111
276 {
277 1 return( sprintf( "%03d${sep}%03d", ( $minor + 0 ), ( $patch + 0 ) ) );
278 }
279 else
280 {
281 0 return( sprintf( "%03d${sep}%03d", ( $minor + 0 ), 0 ) );
282 }
283 }
284 ▶ elsif( defined( $patch ) && length( $patch ) )
Condition0%0/3
defined $patch and length $patch
!ll&&!rl&&r
000
MC/DC0%0/2
defined $patch and length $patch
defined $patch length $patch
Truth table0%0/3
A and B
A= defined $patchB= length $patch
ABresult
0X0
100
111
285 {
286 0 return( sprintf( "%03d${sep}%03d", 0, ( $patch + 0 ) ) );
287 }
288 0 return( '' );
289 1 };
290  
291 # NOTE: dotted()
292 my $dotted = sub
293 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=34.0
294 0 my $comp = $self->new_array;
295 0 ▶ if( !$self->extra->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->extra->is_empty) 0 0 0
296 {
297 0 $comp->push( $self->extra->list );
298 }
299 0 for( qw( patch minor ) )
300 {
301 0 ▶ $comp->unshift( $self->$_ // 0 );
Condition0%0/2
$self->$_ // 0
l!l
00
MC/DC0%0/1
$self->$_ // 0
$self->$_
Truth table0%0/2
A
A= $self->$_
Aresult
11
00
302 }
303 0 ▶ return( $comp->is_empty ? '' : $comp->map(sub{ 0 + $_ })->join( '.' )->scalar );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$comp->is_empty ? : 0 0 0
304 1 };
305  
306 # NOTE: map
307 my $map =
308 {
309 # NOTE: alpha
310 0 ▶ 'A' => sub{ return( $self->alpha // '' ); },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$self->alpha // ""
l!l
00
MC/DC0%0/1
$self->alpha // ""
$self->alpha
Truth table0%0/2
A
A= $self->alpha
Aresult
11
00
311 # NOTE: alpha with leading underscore
312 'a' => sub
313 1 ▶ {
Subroutine __ANON__: called CC=3 SCAR=12.0
314 1 ▶ my $a = $self->alpha // '';
Condition50%1/2
$self->alpha // ""
l!l
10
MC/DC0%0/1
$self->alpha // ""
$self->alpha
Truth table50%1/2
A
A= $self->alpha
Aresult
11
00
315 1 ▶ return( length( $a ) ? "_${a}" : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $a ? : 1 0 1
316 },
317 # NOTE: dotted versions like 1.2.3.4.5
318 'D' => sub
319 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
320 0 my $dots = $dotted->();
321 0 ▶ return( length( $dots ) ? $dots : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $dots ? : 0 0 0
322 },
323 # NOTE: dotted versions with leading dot like .1.2.3.4.5
324 'd' => sub
325 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
326 0 my $dots = $dotted->();
327 0 ▶ return( length( $dots ) ? ( '.' . $dots ) : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $dots ? : 0 0 0
328 },
329 # NOTE: minor
330 0 ▶ 'M' => sub{ return( $self->minor // '' ); },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$self->minor // ""
l!l
00
MC/DC0%0/1
$self->minor // ""
$self->minor
Truth table0%0/2
A
A= $self->minor
Aresult
11
00
331 # NOTE: minor with leading dot
332 'm' => sub
333 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
334 0 ▶ my $minor = $self->minor // '';
Condition0%0/2
$self->minor // ""
l!l
00
MC/DC0%0/1
$self->minor // ""
$self->minor
Truth table0%0/2
A
A= $self->minor
Aresult
11
00
335 0 ▶ return( length( $minor ) ? ( '.' . $minor ) : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $minor ? : 0 0 0
336 },
337 # NOTE: numified without underscore. e.g.: 5.006001 -> 006001
338 0 ▶ 'N' => sub{ return( $numify->( '_' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
339 # NOTE: numified without underscore and with leading dot: 5.006001 -> .006001
340 'n' => sub
341 1 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.2
342 1 my $num = $numify->( '' );
343 1 ▶ return( length( $num ) ? ( '.' . $num ) : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $num ? : 1 0 1
344 },
345 # NOTE: patch
346 0 ▶ 'P' => sub{ return( $self->patch // '' ); },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$self->patch // ""
l!l
00
MC/DC0%0/1
$self->patch // ""
$self->patch
Truth table0%0/2
A
A= $self->patch
Aresult
11
00
347 # NOTE: major; R for release
348 1 ▶ 'R' => sub{ return( $self->major // '' ); },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$self->major // ""
l!l
10
MC/DC0%0/1
$self->major // ""
$self->major
Truth table50%1/2
A
A= $self->major
Aresult
11
00
349 # NOTE: numified with underscore. e.g.: 5.006_001 -> 006_001
350 0 ▶ 'U' => sub{ return( $numify->( '_' ) ); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
351 # NOTE: numified with underscore. e.g.: 5.006_001 -> .006_001
352 'u' => sub
353 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
354 0 my $num = $numify->( '_' );
355 0 ▶ return( length( $num ) ? ( '.' . $num ) : '' );
Branch: 1 branch
BranchTrueFalseTotal
length $num ? : 0 0 0
356 },
357 1 };
358 1 my $str;
359 1 ▶ if( $self->_is_array( $fmt ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($fmt)) { } 0 1 1
elsif (not ref $fmt or ref $fmt and overload::Method($fmt, '""')) { } 1 0 1
360 {
361 0 foreach my $this ( @$fmt )
362 {
363 0 ▶ $this = substr( $this, 1 ) if( substr( $this, 0, 1 ) eq '%' );
Branch: 1 branch
BranchTrueFalseTotal
if substr($this, 0, 1) eq "%" 0 0 0
364 0 ▶ if( !exists( $map->{ $this } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $map->{$this}) 0 0 0
365 {
366 0 ▶ warn( "Unknown formatter '$this'" ) if( $self->_is_warnings_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled 0 0 0
367 0 next;
368 }
369 0 $str .= $map->{ $this }->();
370 }
371 }
372 ▶ elsif( !ref( $fmt ) || ( ref( $fmt ) && overload::Method( $fmt, '""' ) ) )
Condition16%1/6
not ref $fmt or ref $fmt and overload::Method($fmt, "\"\"")
l!l&&r!l&&!r
100
ref $fmt and overload::Method($fmt, "\"\"")
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $fmt or ref $fmt and overload::Method($fmt, "\"\"")
not ref $fmt ref $fmt overload::Method($fmt, "\"\"")
Truth table25%1/4
not(A) or B and C
A= not ref $fmtB= ref $fmtC= overload::Method($fmt, "\"\"")
ABCresult
1XX1
0111
00X0
0100
373 {
374 1 ( $str = "$fmt" ) =~ s
375 {
376 \%([a-zA-Z])
377 }
378 {
379 3 my $this = $1;
380 3 ▶ if( exists( $map->{ $this } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map->{$this}) { } 3 0 3
381 {
382 3 $map->{ $this }->();
383 }
384 else
385 {
386 0 "\%${this}";
387 }
388 }gexs;
389 }
390 else
391 {
392 0 return( $self->error( "Format must be a string or an array reference of pattern components." ) );
393 }
394 1 return( $str );
395 }
396  
397 4 ▶sub inc { return( shift->_inc_dec( 'inc', @_ ) ); }
Subroutine inc: called CC=1 SCAR=0.0
Pod documented
398  
399 0 ▶sub inc_alpha { return( shift->_inc_dec( 'inc' => 'alpha', @_ ) ); }
Subroutine inc_alpha: not called CC=1 SCAR=6.9
Pod documented
400  
401 0 ▶sub inc_beta { return( shift->_inc_dec( 'inc' => 'beta', @_ ) ); }
Subroutine inc_beta: not called CC=1 SCAR=6.9
Pod documented
402  
403 0 ▶sub inc_major { return( shift->_inc_dec( 'inc' => 'major', @_ ) ); }
Subroutine inc_major: not called CC=1 SCAR=6.9
Pod documented
404  
405 0 ▶sub inc_minor { return( shift->_inc_dec( 'inc' => 'minor', @_ ) ); }
Subroutine inc_minor: not called CC=1 SCAR=6.9
Pod documented
406  
407 0 ▶sub inc_patch { return( shift->_inc_dec( 'inc' => 'patch', @_ ) ); }
Subroutine inc_patch: not called CC=1 SCAR=6.9
Pod documented
408  
409 0 ▶sub is_alpha { return( shift->alpha->length > 0 ? 1 : 0 ); }
Subroutine is_alpha: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->alpha->length > 0 ? : 0 0 0
410  
411 0 ▶sub is_qv { return( shift->qv ? 1 : 0 ); }
Subroutine is_qv: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->qv ? : 0 0 0
412  
413 333 ▶sub major { return( shift->reset(@_)->_set_get_number( { field => 'major', undef_ok => 1 }, @_ ) ); }
Subroutine major: called CC=1 SCAR=0.0
Pod documented
414  
415 408 ▶sub minor { return( shift->reset(@_)->_set_get_number( { field => 'minor', undef_ok => 1 }, @_ ) ); }
Subroutine minor: called CC=1 SCAR=0.0
Pod documented
416  
417 sub normal
418 60 ▶{
Subroutine normal: called CC=5 SCAR=16.1
Pod documented
419 60 my $self = shift( @_ );
420 60 my $opts = $self->_get_args_as_hash( @_ );
421 60 ▶ $opts->{raw} //= 0;
Condition100%2/2
$opts->{"raw"} //= 0
l!l
591
MC/DC100%1/1
$opts->{"raw"} //= 0
$opts->{"raw"}
Truth table100%2/2
A
A= $opts->{"raw"}
Aresult
11
00
422 60 my $v;
423 # try-catch
424 60 local $@;
425 my $rv = eval
426 60 {
427 60 my $clone = $self->clone;
428 60 ▶ if( !$self->qv )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->qv) 1 59 60
429 {
430 1 $clone->qv(1);
431 }
432 60 ▶ if( $opts->{raw} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'raw'}) { } 59 1 60
433 {
434 59 $v = $clone->_stringify;
435 # We already did it with stringify, so we return what we got
436 59 return( $v );
437 }
438 else
439 {
440 1 $clone->type( 'dotted' );
441 1 return( $clone );
442 }
443 };
444 60 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 60 60
445 {
446 0 return( $self->error( "Error normalising version $v: $@" ) );
447 }
448 60 return( $rv );
449 }
450  
451 sub numify
452 58 ▶{
Subroutine numify: called CC=8 SCAR=21.1
Pod documented
453 58 my $self = shift( @_ );
454 58 my $opts = $self->_get_args_as_hash( @_ );
455 58 ▶ $opts->{raw} //= 0;
Condition100%2/2
$opts->{"raw"} //= 0
l!l
571
MC/DC100%1/1
$opts->{"raw"} //= 0
$opts->{"raw"}
Truth table100%2/2
A
A= $opts->{"raw"}
Aresult
11
00
456 58 my $v;
457 # try-catch
458 58 local $@;
459 my $rv = eval
460 58 {
461 58 ▶ if( $opts->{raw} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'raw'}) { } 57 1 58
462 {
463 # If alpha is set, such as when we convert a dotted decimal into a decimal, we need to remove it and add it back later, because version mess it up
464 # For example: version->parse( '1.0_3' )->normal yields v1.30.0 instead of v1.0.0_3 whereas version->parse( '1.0' )->normal yields correctly v1.0.0
465 57 my $clone = $self->clone;
466 57 my $alpha = $clone->alpha;
467 57 $clone->alpha( undef );
468 57 $v = $clone->_stringify;
469 57 my $str = version->parse( $v )->numify;
470 57 ▶ $str .= "_${alpha}" if( defined( $alpha ) && length( "$alpha" ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $alpha and length "$alpha" 22 35 57
Condition66%2/3
defined $alpha and length "$alpha"
!ll&&!rl&&r
35022
MC/DC50%1/2
defined $alpha and length "$alpha"
defined $alpha length "$alpha"
Truth table66%2/3
A and B
A= defined $alphaB= length "$alpha"
ABresult
0X0
100
111
471 57 return( $str );
472 }
473 else
474 {
475 1 my $new = $self->clone;
476 # This will also remove qv boolean
477 1 $new->type( 'decimal' );
478 1 my $alpha = $self->alpha;
479 1 ▶ if( length( $alpha // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length($alpha // '')) { } 1 0 1
Condition50%1/2
$alpha // ""
l!l
10
MC/DC0%0/1
$alpha // ""
$alpha
Truth table50%1/2
A
A= $alpha
Aresult
11
00
480 {
481 1 $new->pattern( '%R%n%a' );
482 }
483 else
484 {
485 0 $new->pattern( '%R%n' );
486 }
487 1 $new->reset(1);
488 1 return( $new );
489 }
490 };
491 58 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 58 58
492 {
493 0 return( $self->error( "Error numifying version $v: $@" ) );
494 }
495 58 return( $rv );
496 }
497  
498 96 ▶sub original { return( shift->_set_get_scalar_as_object( 'original', @_ ) ); }
Subroutine original: called CC=1 SCAR=0.0
Pod documented
499  
500 85 ▶sub padded { return( shift->reset(@_)->_set_get_boolean( 'padded', @_ ) ); }
Subroutine padded: called CC=1 SCAR=0.0
Pod documented
501  
502 sub parse
503 96 ▶{
Subroutine parse: called CC=35 SCAR=42.9
Pod documented
504 96 my $self = shift( @_ );
505 96 my $str = shift( @_ );
506 96 ▶ return( $self->error( "No version string was provided." ) ) if( !defined( $str ) || !length( "$str" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and length "$str" 0 96 96
Condition33%1/3
defined $str and length "$str"
!ll&&!rl&&r
0096
MC/DC0%0/2
defined $str and length "$str"
defined $str length "$str"
Truth table33%1/3
A and B
A= defined $strB= length "$str"
ABresult
0X0
100
111
507 96 ▶ if( $] >= 5.008_001 && ref( \$str ) eq 'VSTRING' )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.008001" and ref \$str eq "VSTRING") 0 96 96
Condition33%1/3
$] >= "5.008001" and ref \$str eq "VSTRING"
!ll&&!rl&&r
0960
MC/DC0%0/2
$] >= "5.008001" and ref \$str eq "VSTRING"
$] >= "5.008001" ref \$str eq "VSTRING"
Truth table33%1/3
A and B
A= $] >= "5.008001"B= ref \$str eq "VSTRING"
ABresult
0X0
100
111
508 {
509 0 my $def = { original => $str };
510 0 $def->{type} = 'dotted';
511 0 $def->{qv} = 1;
512 0 my @frags = map{ ord( $_ ) } split( //, $str );
513 0 @$def{qw( major minor patch )} = splice( @frags, 0, 3 );
514 0 $def->{extra} = \@frags;
515 0 $def->{pattern} = '%R%d';
516 0 my $new = $self->new( %$def );
517 0 $new->{_version} = version->parse( $str );
518 0 return( $new );
519 }
520  
521 96 ▶ if( $str =~ /^$VERSION_LAX_REGEX$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^$Changes::Version::VERSION_LAX_REGEX$/) { } 96 0 96
522 {
523 96 my $re = { %+ };
524 96 my $def = { original => $str };
525 96 my $fmt = [];
526 96 ▶ if( defined( $re->{dotted} ) && length( $re->{dotted} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $re->{'dotted'} and length $re->{'dotted'}) { } 13 83 96
elsif (defined $re->{'decimal'} and length $re->{'decimal'}) { } 83 0 83
Condition66%2/3
defined $re->{"dotted"} and length $re->{"dotted"}
!ll&&!rl&&r
83013
MC/DC50%1/2
defined $re->{"dotted"} and length $re->{"dotted"}
defined $re->{"dotted"} length $re->{"dotted"}
Truth table66%2/3
A and B
A= defined $re->{"dotted"}B= length $re->{"dotted"}
ABresult
0X0
100
111
527 {
528 13 $def->{type} = 'dotted';
529 }
530 ▶ elsif( defined( $re->{decimal} ) && length( $re->{decimal} ) )
Condition33%1/3
defined $re->{"decimal"} and length $re->{"decimal"}
!ll&&!rl&&r
0083
MC/DC0%0/2
defined $re->{"decimal"} and length $re->{"decimal"}
defined $re->{"decimal"} length $re->{"decimal"}
Truth table33%1/3
A and B
A= defined $re->{"decimal"}B= length $re->{"decimal"}
ABresult
0X0
100
111
531 {
532 83 $def->{type} = 'decimal';
533 }
534 else
535 {
536 0 return( $self->error( "No version types found. This should not happen." ) );
537 }
538 96 my $v;
539 96 ▶ $def->{qv} = 1 if( defined( $re->{has_v} ) && length( $re->{has_v} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $re->{"has_v"} and length $re->{"has_v"} 6 90 96
Condition66%2/3
defined $re->{"has_v"} and length $re->{"has_v"}
!ll&&!rl&&r
9006
MC/DC50%1/2
defined $re->{"has_v"} and length $re->{"has_v"}
defined $re->{"has_v"} length $re->{"has_v"}
Truth table66%2/3
A and B
A= defined $re->{"has_v"}B= length $re->{"has_v"}
ABresult
0X0
100
111
540 96 $def->{major} = $re->{major};
541 96 ▶ $def->{minor} = $re->{minor} if( defined( $re->{minor} ) && length( $re->{minor} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $re->{"minor"} and length $re->{"minor"} 80 16 96
Condition66%2/3
defined $re->{"minor"} and length $re->{"minor"}
!ll&&!rl&&r
16080
MC/DC50%1/2
defined $re->{"minor"} and length $re->{"minor"}
defined $re->{"minor"} length $re->{"minor"}
Truth table66%2/3
A and B
A= defined $re->{"minor"}B= length $re->{"minor"}
ABresult
0X0
100
111
542 96 ▶ $def->{alpha} = $re->{alpha} if( defined( $re->{alpha} ) && length( $re->{alpha} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $re->{"alpha"} and length $re->{"alpha"} 2 94 96
Condition66%2/3
defined $re->{"alpha"} and length $re->{"alpha"}
!ll&&!rl&&r
9402
MC/DC50%1/2
defined $re->{"alpha"} and length $re->{"alpha"}
defined $re->{"alpha"} length $re->{"alpha"}
Truth table66%2/3
A and B
A= defined $re->{"alpha"}B= length $re->{"alpha"}
ABresult
0X0
100
111
543 96 ▶ if( $def->{type} eq 'dotted' )
Branch: 2 branches
BranchTrueFalseTotal
if ($def->{'type'} eq 'dotted') { } 13 83 96
elsif ($def->{'type'} eq 'decimal') { } 83 0 83
544 {
545 13 push( @$fmt, '%R' );
546 13 ▶ if( defined( $re->{dotted_numified} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $re->{'dotted_numified'}) { } 1 12 13
547 {
548 1 $def->{type} = 'decimal';
549 1 $v = version->parse( $re->{release} );
550 # e.g.: 5.006_001
551 1 ▶ if( defined( $re->{dotted_numified_under} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $re->{'dotted_numified_under'}) { } 0 1 1
552 {
553 0 push( @$fmt, '%u' );
554 }
555 else
556 {
557 1 push( @$fmt, '%n' );
558 1 ▶ push( @$fmt, '%a' ) if( defined( $re->{alpha} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $re->{"alpha"} 1 0 1
559 }
560 1 my $vstr = $v->normal;
561 1 ▶ if( $vstr =~ /^$VERSION_LAX_REGEX$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($vstr =~ /^$Changes::Version::VERSION_LAX_REGEX$/) 1 0 1
562 {
563 1 my $re2 = { %+ };
564 1 ▶ if( defined( $re2->{dotted} ) && length( $re2->{dotted} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $re2->{"dotted"} and length $re2->{"dotted"}) 1 0 1
Condition33%1/3
defined $re2->{"dotted"} and length $re2->{"dotted"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $re2->{"dotted"} and length $re2->{"dotted"}
defined $re2->{"dotted"} length $re2->{"dotted"}
Truth table33%1/3
A and B
A= defined $re2->{"dotted"}B= length $re2->{"dotted"}
ABresult
0X0
100
111
565 {
566 1 ▶ if( defined( $re2->{minor_patch} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $re2->{"minor_patch"}) 1 0 1
567 {
568 # delete( $def->{alpha} );
569 1 $def->{major} = $re2->{major};
570 1 my @frags = split( /\./, $re2->{minor_patch} );
571 1 shift( @frags );
572 1 $def->{minor} = shift( @frags );
573 1 $def->{patch} = shift( @frags );
574 1 $def->{extra} = \@frags;
575 }
576 }
577 }
578 }
579 else
580 {
581 12 $v = version->parse( $re->{dotted} );
582 # Same as %M%P%E -> 5.3.4.5.6.7.8
583 12 push( @$fmt, '%d' );
584 12 ▶ push( @$fmt, '%a' ) if( defined( $def->{alpha} ) && length( $def->{alpha} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $def->{"alpha"} and length $def->{"alpha"} 1 11 12
Condition66%2/3
defined $def->{"alpha"} and length $def->{"alpha"}
!ll&&!rl&&r
1101
MC/DC50%1/2
defined $def->{"alpha"} and length $def->{"alpha"}
defined $def->{"alpha"} length $def->{"alpha"}
Truth table66%2/3
A and B
A= defined $def->{"alpha"}B= length $def->{"alpha"}
ABresult
0X0
100
111
585 12 ▶ if( defined( $re->{minor_patch} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $re->{"minor_patch"}) 12 0 12
586 {
587 12 my @frags = split( /\./, $re->{minor_patch} );
588 # throw away the empty data because of the leading dot
589 12 shift( @frags );
590 12 $def->{minor} = shift( @frags );
591 12 $def->{patch} = shift( @frags );
592 12 $def->{extra} = \@frags;
593 }
594 }
595 13 $def->{pattern} = join( '', @$fmt );
596 }
597 elsif( $def->{type} eq 'decimal' )
598 {
599 # $def->{minor} = $re->{minor} if( defined( $re->{minor} ) );
600 # $re->{release} is the decimal version without the alpha information if it is smaller than 3
601 # This issue stems from decimal number having an underscore can either mean they have a version like
602 # 5.006_002 which would be equivalent v5.6.2 and in this case, "_002" is not an alpha information; and
603 # 1.002_03 where 03 is the alpha version and should be converted to 1.2_03, but instead becomes v1.2.30
604 # If compatibility with 'compat' is enabled, then we use the classic albeit erroneous way of converting the decimal version
605 83 push( @$fmt, '%R' );
606 83 ▶ push( @$fmt, '%m' ) if( defined( $def->{minor} ) && length( $def->{minor} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $def->{"minor"} and length $def->{"minor"} 79 4 83
Condition66%2/3
defined $def->{"minor"} and length $def->{"minor"}
!ll&&!rl&&r
4079
MC/DC50%1/2
defined $def->{"minor"} and length $def->{"minor"}
defined $def->{"minor"} length $def->{"minor"}
Truth table66%2/3
A and B
A= defined $def->{"minor"}B= length $def->{"minor"}
ABresult
0X0
100
111
607 83 $def->{pattern} = join( '', @$fmt );
608 83 ▶ if( defined( $def->{alpha} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $def->{'alpha'} and length $def->{'alpha'} < 3 and not $self->compat) { } 0 83 83
Condition33%2/6
defined $def->{"alpha"} and length $def->{"alpha"} < 3 and not $self->compat
!ll&&!rl&&r
8300
defined $def->{"alpha"} and length $def->{"alpha"} < 3
!ll&&!rl&&r
8300
MC/DC0%0/3
defined $def->{"alpha"} and length $def->{"alpha"} < 3 and not $self->compat
defined $def->{"alpha"} length $def->{"alpha"} < 3 not $self->compat
Truth table25%1/4
A and B and not(C)
A= defined $def->{"alpha"}B= length $def->{"alpha"} < 3C= not $self->compat
ABCresult
0XX0
10X0
1100
1111
609 length( $def->{alpha} ) < 3 &&
610 !$self->compat )
611 {
612 0 $v = version->parse( "$re->{release}" );
613 }
614 else
615 {
616 83 $v = version->parse( "$str" );
617 }
618  
619 # if( (
620 # defined( $def->{alpha} ) &&
621 # ( $self->compat || length( $def->{alpha} ) == 3 )
622 # )
623 # ||
624 # ( defined( $def->{minor} ) &&
625 # length( $def->{minor} ) >= 3 &&
626 # substr( $def->{minor}, 0, 1 ) eq '0'
627 # ) )
628 # {
629 # my $vstr = $v->normal;
630 # if( $vstr =~ /^$VERSION_LAX_REGEX$/ )
631 # {
632 # my $re2 = { %+ };
633 # if( defined( $re2->{dotted} ) && length( $re2->{dotted} ) )
634 # {
635 # if( defined( $re2->{minor_patch} ) )
636 # {
637 # # delete( $def->{alpha} );
638 # $def->{major} = $re2->{major};
639 # my @frags = split( /\./, $re2->{minor_patch} );
640 # shift( @frags );
641 # $def->{minor} = shift( @frags );
642 # $def->{patch} = shift( @frags );
643 # $def->{extra} = \@frags;
644 # }
645 # }
646 # }
647 # }
648 }
649 96 my $new = $self->new( %$def );
650 96 ▶ $new->{_version} = $v if( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 96 0 96
651 96 ▶ return( $self->pass_error ) if( !defined( $new ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 96 96
652 96 CORE::delete( $new->{_reset} );
653 96 return( $new );
654 }
655 else
656 {
657 0 return( $self->error( "Invalid version '$str'" ) );
658 }
659 }
660  
661 352 ▶sub patch { return( shift->reset(@_)->_set_get_number( { field => 'patch', undef_ok => 1 }, @_ ) ); }
Subroutine patch: called CC=1 SCAR=0.0
Pod documented
662  
663 155 ▶sub pattern { return( shift->_set_get_scalar( 'pattern', @_ ) ); }
Subroutine pattern: called CC=1 SCAR=0.0
Pod documented
664  
665 56 ▶sub pretty { return( shift->reset(@_)->_set_get_boolean( 'pretty', @_ ) ); }
Subroutine pretty: called CC=1 SCAR=0.0
Pod documented
666  
667 446 ▶sub qv { return( shift->reset(@_)->_set_get_boolean( 'qv', @_ ) ); }
Subroutine qv: called CC=1 SCAR=0.0
Pod documented
668  
669 0 ▶sub rc { return( shift->_set_get_scalar_as_object( 'rc', @_ ) ); }
Subroutine rc: not called CC=1 SCAR=6.9
Pod documented
670  
671 sub reset
672 2674 ▶{
Subroutine reset: called CC=8 SCAR=21.6
Pod documented
673 2674 my $self = shift( @_ );
674 2674 ▶ if( (
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"_reset"} && defined $self->{"_reset"} && length $self->{"_reset"} and scalar @_) 170 2504 2674
Condition75%6/8
not exists $self->{"_reset"} && defined $self->{"_reset"} && length $self->{"_reset"} and scalar @_
!ll
2424250
exists $self->{'_reset'} && defined $self->{'_reset'} && length $self->{'_reset'}
!ll&&!rl&&r
25002424
exists $self->{"_reset"} and defined $self->{"_reset"}
!ll&&!rl&&r
25002424
MC/DC33%1/3
not exists $self->{"_reset"} && defined $self->{"_reset"} && length $self->{"_reset"} and scalar @_
exists $self->{"_reset"} defined $self->{"_reset"} length $self->{'_reset'}
Truth table50%2/4
not(A and B && C)
A= exists $self->{"_reset"}B= defined $self->{"_reset"}C= length $self->{'_reset'}
ABCresult
1110
0XX1
10X1
1101
675 !exists( $self->{_reset} ) ||
676 !defined( $self->{_reset} ) ||
677 !CORE::length( $self->{_reset} )
678 ) && scalar( @_ ) )
679 {
680 170 $self->{_reset} = scalar( @_ );
681 170 ▶ if( defined( $self->{major} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"major"}) 73 97 170
682 {
683 73 my $str = $self->_stringify;
684 # try-catch
685 73 local $@;
686 eval
687 73 {
688 73 my $v = version->parse( "$str" );
689 73 $self->{_version} = $v;
690 };
691 73 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 73 73
692 {
693 0 ▶ warn( "Warning only: error trying to get a version object from version string '$str': $@\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
694 }
695 }
696 }
697 2674 return( $self );
698 }
699  
700 # Credit: Data::VString
701 sub satisfy
702 7 ▶{
Subroutine satisfy: called CC=11 SCAR=26.7
Pod documented
703 7 my $this = shift( @_ );
704 7 ▶ my $self = ( __PACKAGE__->_is_object( $this ) && $this->isa( 'Changes::Version' ) ) ? $this : $this->parse( shift( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
__PACKAGE__->_is_object($this) && $this->isa('Changes::Version') ? : 0 7 7
Condition33%1/3
__PACKAGE__->_is_object($this) and $this->isa("Changes::Version")
!ll&&!rl&&r
700
MC/DC0%0/2
__PACKAGE__->_is_object($this) and $this->isa("Changes::Version")
__PACKAGE__->_is_object($this) $this->isa("Changes::Version")
Truth table33%1/3
A and B
A= __PACKAGE__->_is_object($this)B= $this->isa("Changes::Version")
ABresult
0X0
100
111
705 7 my $predicate = shift( @_ );
706 # spaces are irrelevant
707 7 $predicate =~ s/[[:blank:]\h\v]+//g;
708 7 my $vers = $self->_version;
709 7 my @p = split( ',', $predicate );
710 my $cmp =
711 {
712 0 ▶ '==' => sub{ $_[0] == $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
713 1 ▶ '!=' => sub{ $_[0] != $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
714 0 ▶ '<=' => sub{ $_[0] <= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
715 0 ▶ '>=' => sub{ $_[0] >= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
716 1 ▶ '<' => sub{ $_[0] < $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
717 2 ▶ '>' => sub{ $_[0] > $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
718 7 };
719 7 for( @p )
720 {
721 9 ▶ if( /^(\d+([._]\d+)*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d+([._]\d+)*)$/) 3 6 9
722 {
723 3 ▶ next if( $vers == version->parse( $1 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $vers == "version"->parse($1) 1 2 3
724 2 return(0);
725 }
726 6 ▶ if( /^([=!<>]=|[<>])(\d+([._]\d+)*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^([=!<>]=|[<>])(\d+([._]\d+)*)$/) 4 2 6
727 {
728 4 ▶ next if( $cmp->{ $1 }->( $vers, version->parse( $2 ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if $cmp->{$1}->($vers, "version"->parse($2)) 4 0 4
729 0 return(0);
730 }
731 2 ▶ if( /^(\d+([._]\d+)*)\.\.(\d+([._]\d+)*)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d+([._]\d+)*)\.\.(\d+([._]\d+)*)$/) 2 0 2
732 {
733 2 ▶ if( ( version->parse( $1 ) <= $vers ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse($1) <= $vers and $vers <= "version"->parse($3)) 2 0 2
Condition33%1/3
"version"->parse($1) <= $vers and $vers <= "version"->parse($3)
!ll&&!rl&&r
002
MC/DC0%0/2
"version"->parse($1) <= $vers and $vers <= "version"->parse($3)
"version"->parse($1) <= $vers $vers <= "version"->parse($3)
Truth table33%1/3
A and B
A= "version"->parse($1) <= $versB= $vers <= "version"->parse($3)
ABresult
0X0
100
111
734 ( $vers <= version->parse( $3 ) ) )
735 {
736 2 next;
737 }
738 0 return(0);
739 }
740 0 return( $self->error( "Bad predicate '$_'" ) );
741 }
742 5 return(1);
743 }
744  
745 0 ▶sub target { return( shift->_set_get_scalar_as_object( 'target', @_ ) ); }
Subroutine target: not called CC=1 SCAR=6.9
Pod documented
746  
747 491 ▶sub type { return( shift->reset(@_)->_set_get_scalar_as_object({
Subroutine type: called CC=1 SCAR=0.0
Pod documented
748 field => 'type',
749 callbacks =>
750 {
751 add => sub
752 101 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
753 101 my $self = shift( @_ );
754 101 ▶ if( $self->{type} eq 'decimal' )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'decimal') { } 88 13 101
elsif ($self->{'type'} eq 'dotted') { } 13 0 13
755 {
756 88 $self->{qv} = 0;
757 }
758 elsif( $self->{type} eq 'dotted' )
759 {
760 # By default
761 13 $self->{qv} = 1;
762 }
763 101 return( $self->{type} );
764 }
765 }
766 491 }, @_ ) ); }
767  
768 sub _bool
769 0 ▶{
Subroutine _bool: not called CC=1 SCAR=6.9
770 0 my $self = shift( @_ );
771 # return( $self->_compare( $self->_version, version->new("0"), 1 ) );
772 0 return( $self->_compare( $self, "0", 1 ) );
773 }
774  
775 sub _bubble
776 0 ▶{
Subroutine _bubble: not called CC=21 SCAR=61.4
777 0 my $self = shift( @_ );
778 0 my $frag = shift( @_ );
779 0 my $val = shift( @_ );
780 # We die, because this is an internal method and those cases should not happen unless this were a design bug
781 0 ▶ if( !defined( $frag ) || !length( $frag ) )
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $frag && length $frag) { } 0 0 0
elsif (not $frag =~ /^(major|minor|patch|alpha|\d+)$/) { } 0 0 0
elsif ($val >= 0) { } 0 0 0
Condition0%0/3
defined $frag && length $frag
!ll&&!rl&&r
000
MC/DC0%0/2
defined $frag && length $frag
defined $frag length $frag
Truth table0%0/3
A && B
A= defined $fragB= length $frag
ABresult
0X0
100
111
782 {
783 0 die( "No fragment was provided to cascade" );
784 }
785 elsif( $frag !~ /^(major|minor|patch|alpha|\d+)$/ )
786 {
787 0 die( "Unsupported version fragment '$frag'. Only use 'major', 'minor', 'patch' or 'alpha' or a number starting from 1 (1 = major, 2 = minor, etc)." );
788 }
789 # Not for us. We bubble only when a value is negative resulting from a cascading decrease
790 # e.g. 3.12.-1 -> 3.11.0, or 3.0.-1 -> 2.9.0, or 2.-1 -> 1.0
791 elsif( $val >= 0 )
792 {
793 0 return;
794 }
795 0 my $type = $self->type;
796 0 my $extra = $self->extra;
797 0 ▶ my $frag_is_int = ( $frag =~ /^\d+$/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$frag =~ /^\d+$/ ? : 0 0 0
798 0 my $frag2num =
799 {
800 major => 1,
801 minor => 2,
802 patch => 3,
803 };
804 0 my $num2frag =
805 {
806 1 => 'major',
807 2 => 'minor',
808 3 => 'patch',
809 };
810  
811 0 ▶ if( $frag eq 'alpha' )
Branch: 1 branch
BranchTrueFalseTotal
if ($frag eq "alpha") 0 0 0
812 {
813 0 $self->alpha( undef );
814 0 return;
815 }
816 0 ▶ die( "Fragment provided '$frag' cannot be 0." ) if( $frag_is_int && $frag == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $frag_is_int and $frag == 0 0 0 0
Condition0%0/3
$frag_is_int and $frag == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$frag_is_int and $frag == 0
$frag_is_int $frag == 0
Truth table0%0/3
A and B
A= $frag_is_intB= $frag == 0
ABresult
0X0
100
111
817 0 ▶ my $level = $frag_is_int ? $frag : $frag2num->{ $frag };
Branch: 1 branch
BranchTrueFalseTotal
$frag_is_int ? : 0 0 0
818  
819 # Should not be happening
820 0 ▶ if( $type eq 'decimal' && $level > 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "decimal" and $level > 2) 0 0 0
Condition0%0/3
$type eq "decimal" and $level > 2
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "decimal" and $level > 2
$type eq "decimal" $level > 2
Truth table0%0/3
A and B
A= $type eq "decimal"B= $level > 2
ABresult
0X0
100
111
821 {
822 0 $self->patch( undef );
823 0 $self->alpha( undef );
824 0 @$extra = ();
825 0 return;
826 }
827  
828 0 ▶ for( my $i = $level; $level >= 1; $i-- )
Branch: 1 branch
BranchTrueFalseTotal
if ($level >= 1) 0 0 0
829 {
830 0 ▶ if( $val < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($val < 0) { } 0 0 0
831 {
832 0 my $new_val = 0;
833 0 ▶ unless( $i == 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($i == 1) 0 0 0
834 {
835 0 my $up_val;
836 0 my $j = $i - 1;
837 0 ▶ if( exists( $num2frag->{ $j } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $num2frag->{$j}) { } 0 0 0
838 {
839 my $coderef = $self->can( $num2frag->{ $j } ) ||
840 0 ▶ die( "Cannot find reference for method ", $num2frag->{ $j } );
Condition0%0/2
$self->can($num2frag->{$j}) || die('Cannot find reference for method ', $num2frag->{$j})
l!l
00
MC/DC0%0/1
$self->can($num2frag->{$j}) || die('Cannot find reference for method ', $num2frag->{$j})
$self->can($num2frag->{$j})
Truth table0%0/2
A
A= $self->can($num2frag->{$j})
Aresult
11
00
841 0 $up_val = $coderef->( $self );
842 }
843 else
844 {
845 0 $up_val = $extra->[ $j - 4 ];
846 }
847 # Set value for next iteration
848 0 ▶ $val = ( $up_val // 0 ) - 1;
Condition0%0/2
$up_val // 0
l!l
00
MC/DC0%0/1
$up_val // 0
$up_val
Truth table0%0/2
A
A= $up_val
Aresult
11
00
849 0 ▶ $new_val = ( $up_val > 0 ) ? 9 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$up_val > 0 ? : 0 0 0
850 }
851  
852 0 ▶ if( exists( $num2frag->{ $i } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $num2frag->{$i}) { } 0 0 0
853 {
854 # my $coderef = $self->can( $num2frag->{ $i } ) ||
855 # die( "Cannot find reference for method ", $num2frag->{ $i } );
856 # $coderef->( $self, 0 );
857 0 $self->{ $num2frag->{ $i } } = $new_val;
858 }
859 else
860 {
861 0 $extra->[ $i - 4 ] = $new_val;
862 }
863 }
864 else
865 {
866 0 ▶ if( exists( $num2frag->{ $i } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $num2frag->{$i}) { } 0 0 0
867 {
868 # my $coderef = $self->can( $num2frag->{ $i } ) ||
869 # die( "Cannot find reference for method ", $num2frag->{ $i } );
870 # $coderef->( $self, 0 );
871 0 $self->{ $num2frag->{ $i } } = $val;
872 }
873 else
874 {
875 0 $extra->[ $i - 4 ] = $val;
876 }
877 0 last;
878 }
879 }
880 0 $self->_cascade( $level );
881 }
882  
883 sub _cascade
884 84 ▶{
Subroutine _cascade: called CC=23 SCAR=47.8
885 84 my $self = shift( @_ );
886 84 my $frag = shift( @_ );
887 # We die, because this is an internal method and those cases should not happen unless this were a design bug
888 84 ▶ if( !defined( $frag ) || !length( $frag ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $frag && length $frag) { } 0 84 84
elsif (not $frag =~ /^(major|minor|patch|alpha|\d+)$/) { } 0 84 84
Condition33%1/3
defined $frag && length $frag
!ll&&!rl&&r
0084
MC/DC0%0/2
defined $frag && length $frag
defined $frag length $frag
Truth table33%1/3
A && B
A= defined $fragB= length $frag
ABresult
0X0
100
111
889 {
890 0 die( "No fragment was provided to cascade" );
891 }
892 elsif( $frag !~ /^(major|minor|patch|alpha|\d+)$/ )
893 {
894 0 die( "Unsupported version fragment '$frag'. Only use 'major', 'minor', 'patch' or 'alpha' or a number starting from 1 (1 = major, 2 = minor, etc)." );
895 }
896 84 my $type = $self->type;
897 84 my $extra = $self->extra;
898 84 ▶ my $frag_is_int = ( $frag =~ /^\d+$/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$frag =~ /^\d+$/ ? : 0 84 84
899 84 ▶ if( $frag eq 'major' || ( $frag_is_int && $frag == 1 ) )
Branch: 5 branches
BranchTrueFalseTotal
if ($frag eq 'major' or $frag_is_int and $frag == 1) { } 21 63 84
elsif ($frag eq 'minor' or $frag_is_int and $frag == 2) { } 21 42 63
elsif ($frag eq 'patch' or $frag_is_int and $frag == 3) { } 21 21 42
elsif ($frag eq 'alpha') { } 21 0 21
elsif ($type eq 'dotted' and $frag_is_int) { } 0 0 0
Condition50%3/6
$frag eq "major" or $frag_is_int and $frag == 1
l!l&&r!l&&!r
21063
$frag_is_int and $frag == 1
!ll&&!rl&&r
6300
MC/DC33%1/3
$frag eq "major" or $frag_is_int and $frag == 1
$frag eq "major" $frag_is_int $frag == 1
Truth table50%2/4
A or B and C
A= $frag eq "major"B= $frag_is_intC= $frag == 1
ABCresult
1XX1
0111
00X0
0100
900 {
901 21 $self->alpha( undef );
902 21 $self->patch(0);
903 # $self->patch( $type eq 'decimal' ? undef : 0 );
904 21 $self->minor(0);
905 }
906 ▶ elsif( $frag eq 'minor' || ( $frag_is_int && $frag == 2 ) )
Condition50%3/6
$frag eq "minor" or $frag_is_int and $frag == 2
l!l&&r!l&&!r
21042
$frag_is_int and $frag == 2
!ll&&!rl&&r
4200
MC/DC33%1/3
$frag eq "minor" or $frag_is_int and $frag == 2
$frag eq "minor" $frag_is_int $frag == 2
Truth table50%2/4
A or B and C
A= $frag eq "minor"B= $frag_is_intC= $frag == 2
ABCresult
1XX1
0111
00X0
0100
907 {
908 21 $self->alpha( undef );
909 21 $self->patch(0);
910 # $self->patch( $type eq 'decimal' ? undef : 0 );
911 }
912 ▶ elsif( $frag eq 'patch' || ( $frag_is_int && $frag == 3 ) )
Condition50%3/6
$frag eq "patch" or $frag_is_int and $frag == 3
l!l&&r!l&&!r
21021
$frag_is_int and $frag == 3
!ll&&!rl&&r
2100
MC/DC33%1/3
$frag eq "patch" or $frag_is_int and $frag == 3
$frag eq "patch" $frag_is_int $frag == 3
Truth table50%2/4
A or B and C
A= $frag eq "patch"B= $frag_is_intC= $frag == 3
ABCresult
1XX1
0111
00X0
0100
913 {
914 21 $self->alpha( undef );
915 }
916 elsif( $frag eq 'alpha' )
917 {
918 # Nothing to do
919 }
920 ▶ elsif( $type eq 'dotted' && $frag_is_int )
Condition0%0/3
$type eq "dotted" and $frag_is_int
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "dotted" and $frag_is_int
$type eq "dotted" $frag_is_int
Truth table0%0/3
A and B
A= $type eq "dotted"B= $frag_is_int
ABresult
0X0
100
111
921 {
922 0 my $offset = ( $frag - 4 );
923 0 my $len = $extra->length;
924 # Before the fragment offset, we set the value to 0 if it is undefined or empty, and
925 # after the fragment offset everything else is reset to 0
926 0 ▶ for( my $i = 0; $i < ( $offset < $len ? $len : $offset ); $i++ )
Branch: 2 branches
BranchTrueFalseTotal
if ($i < ($offset < $len ? $len : $offset)) 0 0 0
$offset < $len ? : 0 0 0
927 {
928 0 ▶ if( (
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $offset and not defined $extra->[$i] && length $extra->[$i] or $i > $offset) 0 0 0
Condition0%0/9
$i < $offset and not defined $extra->[$i] && length $extra->[$i] or $i > $offset
l!l&&r!l&&!r
000
$i < $offset and not defined $extra->[$i] && length $extra->[$i]
!ll&&!rl&&r
000
defined $extra->[$i] && length $extra->[$i]
!ll&&!rl&&r
000
MC/DC0%0/4
$i < $offset and not defined $extra->[$i] && length $extra->[$i] or $i > $offset
$i < $offset defined $extra->[$i] length $extra->[$i] $i > $offset
Truth table0%0/6
A and not(B && C) or D
A= $i < $offsetB= defined $extra->[$i]C= length $extra->[$i]D= $i > $offset
ABCDresult
10XX1
110X1
0XX11
11111
0XX00
11100
929 $i < $offset &&
930 ( !defined( $extra->[$i] ) || !length( $extra->[$i] ) )
931 ) || $i > $offset )
932 {
933 0 $extra->[$i] = 0;
934 }
935 }
936 0 $self->alpha( undef );
937 }
938 }
939  
940 sub _compare
941 40 ▶{
Subroutine _compare: called CC=8 SCAR=26.7
942 40 my( $left, $right, $swap ) = @_;
943 40 my $class = ref( $left );
944 40 ▶ return(0) if( ${^GLOBAL_PHASE} eq 'DESTRUCT' );
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 40 40
945 40 ▶ unless( $left->_is_a( $right => $class ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($left->_is_a($right, $class)) 40 0 40
946 {
947 40 $right = $class->new( $right, debug => $left->debug );
948 }
949  
950 40 ▶ if( $swap )
Branch: 1 branch
BranchTrueFalseTotal
if ($swap) 0 40 40
951 {
952 0 ( $left, $right ) = ( $right, $left );
953 }
954  
955 40 ▶ unless( _verify( $left ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($left)) 0 40 40
956 {
957 0 ▶ warn( "Invalid version for left argument: ", ( $swap ? 'format' : 'object ' . overload::StrVal( $left ) ), "." );
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 0 0
958 0 return(0);
959 }
960 40 ▶ unless( _verify( $right ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (_verify($right)) 0 40 40
961 {
962 0 ▶ warn( "Invalid version for right argument: ", ( $swap ? 'format' : 'object' . overload::StrVal( $right ) ), "." );
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 0 0
963 0 return(0);
964 }
965 40 my $lv = $left->_version;
966 40 my $rv = $right->_version;
967 # TODO: better compare version. perl's version fails at comparing version that have alpha.
968 # For example, the documentation states:
969 # Note that "alpha" version objects (where the version string contains a trailing underscore segment) compare as less than the equivalent version without an underscore:
970 # $bool = version->parse("1.23_45") < version->parse("1.2345"); # TRUE
971 # However, this is not true. The above doc example will yield FALSE, not TRUE, and even the following too:
972 # perl -Mversion -lE 'my $v = version->parse("v1.2.3"); my $v2 = version->parse("v1.2.3_4"); say $v > $v2'
973 # See RT#145290: <https://rt.cpan.org/Ticket/Display.html?id=145290>
974 # return( $left->{_version} == $right->{_version} );
975 # return( $lv == $rv );
976 40 return( $lv <=> $rv );
977 }
978  
979 sub _compute
980 96 ▶{
Subroutine _compute: called CC=33 SCAR=44.9
981 96 my $self = shift( @_ );
982 96 my $opts = pop( @_ );
983 96 my( $other, $swap, $nomethod, $bitwise ) = @_;
984 96 ▶ my $frag = $self->default_frag // 'minor';
Condition50%1/2
$self->default_frag // "minor"
l!l
960
MC/DC0%0/1
$self->default_frag // "minor"
$self->default_frag
Truth table50%1/2
A
A= $self->default_frag
Aresult
11
00
985 96 ▶ $frag = 'minor' if( $frag !~ /^(major|minor|patch|alpha|\d+)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $frag =~ /^(major|minor|patch|alpha|\d+)$/ 0 96 96
986 96 ▶ if( !defined( $opts ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"} or not length $opts->{"op"}) 0 96 96
Condition33%4/12
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"} or not length $opts->{"op"}
l!l&&r!l&&!r
0096
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"}
l!l&&r!l&&!r
0096
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"}
l!l&&r!l&&!r
0096
not defined $opts or ref $opts ne "HASH"
l!l&&r!l&&!r
0096
MC/DC0%0/5
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"} or not length $opts->{"op"}
not defined $opts ref $opts ne "HASH" not exists $opts->{"op"} not defined $opts->{"op"} not length $opts->{"op"}
Truth table16%1/6
not(A) or B or not(C) or not(D) or not(E)
A= not defined $optsB= ref $opts ne "HASH"C= not exists $opts->{"op"}D= not defined $opts->{"op"}E= not length $opts->{"op"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
987 ref( $opts ) ne 'HASH' ||
988 !exists( $opts->{op} ) ||
989 !defined( $opts->{op} ) ||
990 !length( $opts->{op} ) )
991 {
992 0 die( "No argument 'op' provided" );
993 }
994 96 my $op = $opts->{op};
995 96 my $clone = $self->clone;
996 96 my $extra = $self->extra;
997 96 ▶ my $frag_is_int = ( $frag =~ /^\d+$/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$frag =~ /^\d+$/ ? : 0 96 96
998 96 my $map =
999 {
1000 1 => 'major',
1001 2 => 'minor',
1002 3 => 'patch',
1003 };
1004 96 my $coderef;
1005 96 ▶ if( ( $frag_is_int && exists( $map->{ $frag } ) ) || !$frag_is_int )
Branch: 1 branch
BranchTrueFalseTotal
if ($frag_is_int and exists $map->{$frag} or not $frag_is_int) 96 0 96
Condition33%2/6
$frag_is_int and exists $map->{$frag} or not $frag_is_int
l!l&&r!l&&!r
0960
$frag_is_int and exists $map->{$frag}
!ll&&!rl&&r
9600
MC/DC0%0/3
$frag_is_int and exists $map->{$frag} or not $frag_is_int
$frag_is_int exists $map->{$frag} not $frag_is_int
Truth table20%1/5
A and B or not(C)
A= $frag_is_intB= exists $map->{$frag}C= not $frag_is_int
ABCresult
11X1
0X11
1011
0X00
1000
1006 {
1007 $coderef = $self->can( $map->{ $frag } // $frag ) ||
1008 96 ▶ die( "Cannot find code reference for method ", ( $frag_is_int ? $map->{ $frag } : $frag ) );
Branch: 1 branch
BranchTrueFalseTotal
$frag_is_int ? : 0 0 0
Condition40%2/5
$self->can($map->{$frag} // $frag) || die('Cannot find code reference for method ', $frag_is_int ? $map->{$frag} : $frag)
l!l
960
$map->{$frag} // $frag
l!l&&r!l&&!r
0960
MC/DC0%0/1
$self->can($map->{$frag} // $frag) || die('Cannot find code reference for method ', $frag_is_int ? $map->{$frag} : $frag)
$self->can($map->{$frag} // $frag)
MC/DC0%0/2
$map->{$frag} // $frag
$map->{$frag} $frag
Truth table50%1/2
A
A= $self->can($map->{$frag} // $frag)
Aresult
11
00
Truth table33%1/3
A // B
A= $map->{$frag}B= $frag
ABresult
1X1
011
000
1009 }
1010 96 ▶ my $val = defined( $coderef ) ? $coderef->( $self ) : $extra->[ $frag - 4 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $coderef ? : 96 0 96
1011 96 my $err;
1012 96 ▶ if( !defined( $val ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $val) { } 0 96 96
elsif (not $self->_is_a($val, 'Module::Generic::Number')) { } 0 96 96
1013 {
1014 0 $val = $self->new_number(0);
1015 }
1016 elsif( !$self->_is_a( $val => 'Module::Generic::Number' ) )
1017 {
1018 0 $val = $self->new_number( "$val" );
1019 0 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
1020 {
1021 0 $err = $self->error->message;
1022 }
1023 }
1024 96 my $n = $val->scalar;
1025 96 my $eval;
1026 96 ▶ if( $op eq '++' || $op eq '--' )
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '++' or $op eq '--') { } 16 80 96
Condition100%3/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
8880
MC/DC100%2/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table100%3/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
1027 {
1028 16 $eval = "\$n${op}";
1029 }
1030 else
1031 {
1032 80 ▶ $eval = $swap ? ( defined( $other ) ? $other : 'undef' ) . "${op} \$n" : "\$n ${op} " . ( defined( $other ) ? $other : 'undef' );
Branch: 3 branches
BranchTrueFalseTotal
$swap ? : 16 64 80
defined $other ? : 16 0 16
defined $other ? : 64 0 64
1033 }
1034 96 my $rv = eval( $eval );
1035 96 ▶ $err = $@ if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 96 96
1036 96 ▶ if( defined( $err ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 0 96 96
1037 {
1038 0 ▶ warn( $err, "\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1039 # Return unchanged
1040 # return( $swap ? $other : $self );
1041 0 return;
1042 }
1043  
1044 96 ▶ if( $swap )
Branch: 1 branch
BranchTrueFalseTotal
if ($swap) { } 16 80 96
1045 {
1046 16 ▶ return( ref( $rv ) ? $rv->scalar : $rv );
Branch: 1 branch
BranchTrueFalseTotal
ref $rv ? : 0 16 16
1047 }
1048 else
1049 {
1050 80 my $new = $clone;
1051 80 my $new_val;
1052 80 ▶ if( $op eq '++' || $op eq '--' )
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '++' or $op eq '--') { } 16 64 80
Condition100%3/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
8864
MC/DC100%2/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table100%3/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
1053 {
1054 16 $new = $self;
1055 16 $new_val = $n;
1056 }
1057 else
1058 {
1059 64 $new_val = int( $rv );
1060 }
1061  
1062 80 ▶ if( $new_val < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val < 0) { } 0 80 80
1063 {
1064 0 $new->_bubble( $frag, $new_val );
1065 }
1066 else
1067 {
1068 80 ▶ if( defined( $coderef ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef) { } 80 0 80
1069 {
1070 80 $coderef->( $new, $new_val );
1071 }
1072 else
1073 {
1074 0 $extra->[( $frag - 4 )] = $new_val;
1075 }
1076 80 $new->_cascade( $frag );
1077 }
1078 80 $new->reset(1);
1079 80 return( $new );
1080 }
1081 }
1082  
1083 sub _inc_dec
1084 4 ▶{
Subroutine _inc_dec: called CC=28 SCAR=49.9
1085 4 my $self = shift( @_ );
1086 4 ▶ my $op = shift( @_ ) || return( $self->error( "No op was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No op was provided.'))
l!l
40
MC/DC0%0/1
shift @_ || (return $self->error('No op was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1087 4 ▶ return( $self->error( "Op can only be 'inc' or 'dec'" ) ) if( $op !~ /^(inc|dec)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $op =~ /^(inc|dec)$/ 0 4 4
1088 4 my $frag = shift( @_ );
1089 4 my $unit = shift( @_ );
1090 4 ▶ if( !defined( $frag ) || !length( "$frag" ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $frag && length "$frag") { } 0 4 4
elsif (not $frag =~ /^(major|minor|patch|alpha|\d+)$/) { } 0 4 4
Condition33%1/3
defined $frag && length "$frag"
!ll&&!rl&&r
004
MC/DC0%0/2
defined $frag && length "$frag"
defined $frag length "$frag"
Truth table33%1/3
A && B
A= defined $fragB= length "$frag"
ABresult
0X0
100
111
1091 {
1092 0 ▶ return( $self->error( "No version fragment was specified to ", ( $op eq 'inc' ? 'increase' : 'decrease' ), " the version number." ) );
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'inc' ? : 0 0 0
1093 }
1094 elsif( $frag !~ /^(major|minor|patch|alpha|\d+)$/ )
1095 {
1096 0 ▶ return( $self->error( "Unsupported version fragment '$frag' to ", ( $op eq 'inc' ? 'increase' : 'decrease' ), ". Only use 'major', 'minor', 'patch' or 'alpha' or a number starting from 1 (1 = major, 2 = minor, etc)." ) );
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'inc' ? : 0 0 0
1097 }
1098 4 ▶ if( defined( $unit ) && $unit !~ /^\d+$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unit and not $unit =~ /^\d+$/) 0 4 4
Condition33%1/3
defined $unit and not $unit =~ /^\d+$/
!ll&&!rl&&r
400
MC/DC0%0/2
defined $unit and not $unit =~ /^\d+$/
defined $unit not $unit =~ /^\d+$/
Truth table33%1/3
A and not(B)
A= defined $unitB= not $unit =~ /^\d+$/
ABresult
0X0
100
111
1099 {
1100 0 ▶ return( $self->error( "Unit to ", ( $op eq 'inc' ? 'increase' : 'decrease' ), " fragment $frag value must be an integer." ) );
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'inc' ? : 0 0 0
1101 }
1102 4 my $extra = $self->extra;
1103 4 ▶ my $frag_is_int = ( $frag =~ /^\d+$/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$frag =~ /^\d+$/ ? : 0 4 4
1104 4 my $map =
1105 {
1106 1 => 'major',
1107 2 => 'minor',
1108 3 => 'patch',
1109 };
1110 4 my $coderef;
1111 4 ▶ if( ( $frag_is_int && exists( $map->{ $frag } ) ) || !$frag_is_int )
Branch: 1 branch
BranchTrueFalseTotal
if ($frag_is_int and exists $map->{$frag} or not $frag_is_int) 4 0 4
Condition33%2/6
$frag_is_int and exists $map->{$frag} or not $frag_is_int
l!l&&r!l&&!r
040
$frag_is_int and exists $map->{$frag}
!ll&&!rl&&r
400
MC/DC0%0/3
$frag_is_int and exists $map->{$frag} or not $frag_is_int
$frag_is_int exists $map->{$frag} not $frag_is_int
Truth table20%1/5
A and B or not(C)
A= $frag_is_intB= exists $map->{$frag}C= not $frag_is_int
ABCresult
11X1
0X11
1011
0X00
1000
1112 {
1113 $coderef = $self->can( $map->{ $frag } // $frag ) ||
1114 4 ▶ die( "Cannot find code reference for method ", ( $frag_is_int ? $map->{ $frag } : $frag ) );
Branch: 1 branch
BranchTrueFalseTotal
$frag_is_int ? : 0 0 0
Condition40%2/5
$self->can($map->{$frag} // $frag) || die('Cannot find code reference for method ', $frag_is_int ? $map->{$frag} : $frag)
l!l
40
$map->{$frag} // $frag
l!l&&r!l&&!r
040
MC/DC0%0/1
$self->can($map->{$frag} // $frag) || die('Cannot find code reference for method ', $frag_is_int ? $map->{$frag} : $frag)
$self->can($map->{$frag} // $frag)
MC/DC0%0/2
$map->{$frag} // $frag
$map->{$frag} $frag
Truth table50%1/2
A
A= $self->can($map->{$frag} // $frag)
Aresult
11
00
Truth table33%1/3
A // B
A= $map->{$frag}B= $frag
ABresult
1X1
011
000
1115 }
1116 4 ▶ my $n = defined( $coderef ) ? $coderef->( $self ) : $extra->[ $frag - 4 ];
Branch: 1 branch
BranchTrueFalseTotal
defined $coderef ? : 4 0 4
1117 # The offset specified is out of bound
1118 4 ▶ if( $frag_is_int && ( $frag - 4 ) > $extra->size )
Branch: 2 branches
BranchTrueFalseTotal
if ($frag_is_int and $frag - 4 > $extra->size) { } 0 4 4
elsif (defined $unit and $unit == 1) { } 0 4 4
Condition33%1/3
$frag_is_int and $frag - 4 > $extra->size
!ll&&!rl&&r
400
MC/DC0%0/2
$frag_is_int and $frag - 4 > $extra->size
$frag_is_int $frag - 4 > $extra->size
Truth table33%1/3
A and B
A= $frag_is_intB= $frag - 4 > $extra->size
ABresult
0X0
100
111
1119 {
1120 0 ▶ $n = (
Branch: 2 branches
BranchTrueFalseTotal
$op eq 'inc' ? : 0 0 0
defined $unit ? : 0 0 0
1121 $op eq 'inc'
1122 ? ( defined( $unit ) ? $unit : 1 )
1123 : 0
1124 );
1125 }
1126 ▶ elsif( defined( $unit ) && $unit == 1 )
Condition33%1/3
defined $unit and $unit == 1
!ll&&!rl&&r
400
MC/DC0%0/2
defined $unit and $unit == 1
defined $unit $unit == 1
Truth table33%1/3
A and B
A= defined $unitB= $unit == 1
ABresult
0X0
100
111
1127 {
1128 0 ▶ $op eq 'inc' ? ( $n += $unit ) : ( $n -= $unit );
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'inc' ? : 0 0 0
1129 }
1130 else
1131 {
1132 4 ▶ $op eq 'inc' ? $n++ : $n--;
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'inc' ? : 4 0 4
1133 }
1134  
1135 4 ▶ if( defined( $coderef ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coderef) { } 4 0 4
1136 {
1137 4 $coderef->( $self, $n );
1138 }
1139 else
1140 {
1141 0 $extra->[( $frag - 4 )] = $n;
1142 }
1143 4 $self->_cascade( $frag );
1144 4 $self->reset(1);
1145 4 return( $self );
1146 }
1147  
1148 sub _noop
1149 0 ▶{
Subroutine _noop: not called CC=2 SCAR=17.9
1150 0 my( $self, $other, $swap, $nomethod, $bitwise ) = @_;
1151 0 ▶ warn( "This operation $nomethod is not supported by Changes::Version\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1152 }
1153  
1154 sub _stringify
1155 189 ▶{
Subroutine _stringify: called CC=24 SCAR=38.3
1156 189 my $self = shift( @_ );
1157 189 my $comp = $self->new_array;
1158 189 my $def = {};
1159 189 for( qw( major minor patch alpha ) )
1160 {
1161 756 $def->{ $_ } = $self->$_;
1162 }
1163 189 my $type = $self->type;
1164 189 ▶ $def->{major} = 0 if( !defined( $def->{major} ) || !length( $def->{major} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{"major"} and length $def->{"major"} 0 189 189
Condition33%1/3
defined $def->{"major"} and length $def->{"major"}
!ll&&!rl&&r
00189
MC/DC0%0/2
defined $def->{"major"} and length $def->{"major"}
defined $def->{"major"} length $def->{"major"}
Truth table33%1/3
A and B
A= defined $def->{"major"}B= length $def->{"major"}
ABresult
0X0
100
111
1165 189 ▶ if( $self->qv || ( ( $type // '' ) eq 'dotted' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->qv or ($type // '') eq 'dotted') { } 94 95 189
elsif (($type // '') eq 'decimal') { } 95 0 95
Condition60%3/5
$self->qv or ($type // "") eq "dotted"
l!l&&r!l&&!r
94095
$type // ""
l!l
950
MC/DC0%0/2
$self->qv or ($type // "") eq "dotted"
$self->qv $type
Truth table66%2/3
A or B
A= $self->qvB= $type
ABresult
1X1
011
000
1166 {
1167 94 ▶ $def->{minor} = 0 if( !defined( $def->{minor} ) || !length( "$def->{minor}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{"minor"} and length qq[$def->{"minor"}] 0 94 94
Condition33%1/3
defined $def->{"minor"} and length qq[$def->{"minor"}]
!ll&&!rl&&r
0094
MC/DC0%0/2
defined $def->{"minor"} and length qq[$def->{"minor"}]
defined $def->{"minor"} length qq[$def->{"minor"}]
Truth table33%1/3
A and B
A= defined $def->{"minor"}B= length qq[$def->{"minor"}]
ABresult
0X0
100
111
1168 94 ▶ $def->{patch} = 0 if( !defined( $def->{patch} ) || !length( "$def->{patch}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $def->{"patch"} and length qq[$def->{"patch"}] 0 94 94
Condition33%1/3
defined $def->{"patch"} and length qq[$def->{"patch"}]
!ll&&!rl&&r
0094
MC/DC0%0/2
defined $def->{"patch"} and length qq[$def->{"patch"}]
defined $def->{"patch"} length qq[$def->{"patch"}]
Truth table33%1/3
A and B
A= defined $def->{"patch"}B= length qq[$def->{"patch"}]
ABresult
0X0
100
111
1169 }
1170 ▶ elsif( ( $type // '' ) eq 'decimal' )
Condition50%1/2
$type // ""
l!l
950
MC/DC0%0/1
$type // ""
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
1171 {
1172 # We need to avoid the scenario where we would have a major and alpha, but not minor.
1173 # For example: 3_6 would trigger version error "Invalid version format (alpha without decimal)"
1174 95 ▶ $def->{minor} = 0 if( ( !defined( $def->{minor} ) || !length( "$def->{minor}" ) ) && defined( $def->{alpha} ) && length( "$def->{alpha}" ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $def->{"minor"} && length qq[$def->{"minor"}] and defined $def->{"alpha"} and length qq[$def->{"alpha"}] 0 95 95
Condition33%3/9
not defined $def->{"minor"} && length qq[$def->{"minor"}] and defined $def->{"alpha"} and length qq[$def->{"alpha"}]
!ll&&!rl&&r
9500
not defined $def->{"minor"} && length qq[$def->{"minor"}] and defined $def->{"alpha"}
!ll&&!rl&&r
9500
defined $def->{'minor'} && length "$def->{'minor'}"
!ll&&!rl&&r
0095
MC/DC0%0/4
not defined $def->{"minor"} && length qq[$def->{"minor"}] and defined $def->{"alpha"} and length qq[$def->{"alpha"}]
defined $def->{'minor'} length "$def->{'minor'}" defined $def->{"alpha"} length qq[$def->{"alpha"}]
Truth table14%1/7
not(A && B) and C and D
A= defined $def->{'minor'}B= length "$def->{'minor'}"C= defined $def->{"alpha"}D= length qq[$def->{"alpha"}]
ABCDresult
11XX0
0X0X0
100X0
0X100
10100
0X111
10111
1175 }
1176 189 my $ok = 0;
1177 189 ▶ if( !$self->extra->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->extra->is_empty) 0 189 189
1178 {
1179 0 $ok++;
1180 0 $comp->push( $self->extra->list );
1181 }
1182 189 for( qw( patch minor major ) )
1183 {
1184 567 ▶ next if( !length( $def->{ $_ } ) && !$ok );
Branch: 1 branch
BranchTrueFalseTotal
unless length $def->{$_} or $ok 3 564 567
Condition66%2/3
length $def->{$_} or $ok
l!l&&r!l&&!r
56403
MC/DC50%1/2
length $def->{$_} or $ok
length $def->{$_} $ok
Truth table66%2/3
A or B
A= length $def->{$_}B= $ok
ABresult
1X1
011
000
1185 # We stop skipping version fragments as soon as one is defined
1186 564 $ok++;
1187 564 $comp->unshift( $def->{ $_ } );
1188 }
1189 189 ▶ my $v = ( $self->qv ? 'v' : '' ) . $comp->map(sub{ 0 + $_ })->join( '.' )->scalar;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$self->qv ? : 94 95 189
1190 189 ▶ $v .= '_' . $def->{alpha} if( defined( $def->{alpha} ) && length( $def->{alpha} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $def->{"alpha"} and length $def->{"alpha"} 94 95 189
Condition66%2/3
defined $def->{"alpha"} and length $def->{"alpha"}
!ll&&!rl&&r
95094
MC/DC50%1/2
defined $def->{"alpha"} and length $def->{"alpha"}
defined $def->{"alpha"} length $def->{"alpha"}
Truth table66%2/3
A and B
A= defined $def->{"alpha"}B= length $def->{"alpha"}
ABresult
0X0
100
111
1191 189 return( $v );
1192 }
1193  
1194 sub _verify
1195 80 ▶{
Subroutine _verify: called CC=6 SCAR=22.3
1196 80 my $self = shift( @_ );
1197 80 ▶ return(0) if( ${^GLOBAL_PHASE} eq 'DESTRUCT' );
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 80 80
1198 80 ▶ unless( defined( $self ) && ref( $self ) eq 'Changes::Version' )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and ref $self eq "Changes::Version") 0 80 80
Condition33%1/3
defined $self and ref $self eq "Changes::Version"
!ll&&!rl&&r
0080
MC/DC0%0/2
defined $self and ref $self eq "Changes::Version"
defined $self ref $self eq "Changes::Version"
Truth table33%1/3
A and B
A= defined $selfB= ref $self eq "Changes::Version"
ABresult
0X0
100
111
1199 {
1200 0 return(0);
1201 }
1202 80 ▶ if( eval{ exists( $self->{_version} ) } &&
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { exists $self->{'_version'} } } and 'Module::Generic'->_is_a($self->{'_version'}, 'version')) { } 80 0 80
Condition33%1/3
eval { do { exists $self->{"_version"} } } and "Module::Generic"->_is_a($self->{"_version"}, "version")
!ll&&!rl&&r
0080
MC/DC0%0/2
eval { do { exists $self->{"_version"} } } and "Module::Generic"->_is_a($self->{"_version"}, "version")
eval { do { exists $self->{"_version"} } } "Module::Generic"->_is_a($self->{"_version"}, "version")
Truth table33%1/3
A and B
A= eval { do { exists $self->{"_version"} } }B= "Module::Generic"->_is_a($self->{"_version"}, "version")
ABresult
0X0
100
111
1203 Module::Generic->_is_a( $self->{_version} => 'version' ) )
1204 {
1205 80 return(1);
1206 }
1207 else
1208 {
1209 0 return(0);
1210 }
1211 }
1212  
1213 sub _version
1214 87 ▶{
Subroutine _version: called CC=7 SCAR=33.2
1215 87 my $self = shift( @_ );
1216 87 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 87 87
elsif (not exists $self->{'_version'} && defined $self->{'_version'}) { } 0 87 87
1217 {
1218 0 my $v = shift( @_ );
1219 0 ▶ return( $self->error( "Value provided is not a version object." ) ) if( !$self->_is_a( $v => 'version' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($v, "version") 0 0 0
1220 }
1221 ▶ elsif( !exists( $self->{_version} ) || !defined( $self->{_version} ) )
Condition33%1/3
exists $self->{'_version'} && defined $self->{'_version'}
!ll&&!rl&&r
0087
MC/DC0%0/2
exists $self->{'_version'} && defined $self->{'_version'}
exists $self->{'_version'} defined $self->{'_version'}
Truth table33%1/3
A && B
A= exists $self->{'_version'}B= defined $self->{'_version'}
ABresult
0X0
100
111
1222 {
1223 0 my $str = $self->_stringify;
1224 # try-catch
1225 0 local $@;
1226 eval
1227 0 {
1228 0 $self->{_version} = version->parse( "$str" );
1229 };
1230 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1231 {
1232 0 ▶ warn( "Warning only: error trying to get a version object from version string '$str': $@\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1233 }
1234 }
1235 87 return( $self->{_version} );
1236 }
1237  
1238 sub DESTROY
1239 456 ▶{
Subroutine DESTROY: called CC=3 SCAR=11.3
1240 # <https://perldoc.perl.org/perlobj#Destructors>
1241 456 CORE::local( $., $@, $!, $^E, $? );
1242 456 my $self = CORE::shift( @_ );
1243 456 ▶ CORE::return if( !CORE::defined( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 456 456
1244 456 %$self = ();
1245 456 ▶ CORE::return if( ${^GLOBAL_PHASE} eq 'DESTRUCT' );
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 456 456
1246 };
1247  
1248 20 1;
1249 # NOTE: POD
1250 __END__
« Changes.pm ↑ Summary Changes/Release.pm »