Minilla/Release/BumpVersion.pm

filter: Statementstmt 61.4% 51 / 83 Branchbran 52.2% 23 / 44 Conditioncond 37.5% 6 / 16 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 7 totaltotal 53.1% 93 / 175 CC 30 SCAR 35.3
CC
30
Cov
56%
bump_version
110.0
run
21.3
default_new_version
12.0
CRAP 34.2
« Module/BumpVersion.pm ↑ Summary Minilla/Release/UploadToCPAN.pm »
1 package Minilla::Release::BumpVersion;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use ExtUtils::MakeMaker qw(prompt);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Minilla::Util qw(find_file require_optional cmd is_interactive);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Minilla::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Module::BumpVersion;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
13 0 require_optional(
14 'Module/BumpVersion.pm', 'Release engineering'
15 );
16 0 require_optional(
17 'Version/Next.pm', 'Release engineering'
18 );
19 }
20  
21 9 ▶sub run {
Subroutine run: called CC=16 SCAR=30.6
Pod undocumented
22 9 my ($self, $project, $opts) = @_;
23  
24 9 ▶ if ($opts->{skip_prepare}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"skip_prepare"}) 1 8 9
25 1 my $ver = $project->version;
26 1 ▶ if (!$opts->{dry_run} && exists_tag($project->format_tag($ver))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"dry_run"} and exists_tag($project->format_tag($ver))) 0 1 1
Condition33%1/3
not $opts->{"dry_run"} and exists_tag($project->format_tag($ver))
!ll&&!rl&&r
100
MC/DC0%0/2
not $opts->{"dry_run"} and exists_tag($project->format_tag($ver))
not $opts->{"dry_run"} exists_tag($project->format_tag($ver))
Truth table33%1/3
not(A) and B
A= not $opts->{"dry_run"}B= exists_tag($project->format_tag($ver))
ABresult
0X0
100
111
27 0 errorf("Sorry, version '%s' is already tagged. Stopping.\n", $ver);
28 }
29 1 return;
30 }
31  
32 8 ▶ if (!defined $opts->{version} && !is_interactive()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"version"} or is_interactive()) 1 7 8
Condition100%3/3
defined $opts->{"version"} or is_interactive()
l!l&&r!l&&!r
611
MC/DC100%2/2
defined $opts->{"version"} or is_interactive()
defined $opts->{"version"} is_interactive()
Truth table100%3/3
A or B
A= defined $opts->{"version"}B= is_interactive()
ABresult
1X1
011
000
33 1 errorf("A version is required when standard input is not a terminal. Run 'minil prepare VERSION', then 'minil release --skip-prepare'.\n");
34 }
35  
36 my $ver = defined $opts->{version}
37 ? $opts->{version}
38 7 ▶ : prompt("Next Release?", $self->default_new_version($project));
Branch: 1 branch
BranchTrueFalseTotal
defined $opts->{'version'} ? : 6 1 7
39  
40 7 ▶ if (defined $opts->{version} || $ver) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"version"} or $ver) 7 0 7
Condition66%2/3
defined $opts->{"version"} or $ver
l!l&&r!l&&!r
610
MC/DC0%0/2
defined $opts->{"version"} or $ver
defined $opts->{"version"} $ver
Truth table66%2/3
A or B
A= defined $opts->{"version"}B= $ver
ABresult
1X1
011
000
41 # Do not use is_strict. is_strict rejects '5.00_01' style.
42 7 ▶ if (!version::is_lax($ver)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (version::is_lax($ver)) 2 5 7
43 2 errorf("Sorry, version '%s' is invalid. Stopping.\n", $ver);
44 }
45  
46 5 my $curr_ver = $project->metadata->version;
47 5 ▶ if (!check_version_compatibility($curr_ver, $ver)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (check_version_compatibility($curr_ver, $ver)) 2 3 5
48 2 ▶ unless (is_interactive()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_interactive()) 1 1 2
49 1 errorf("The version format doesn't match the current one (%s -> %s), and cannot be confirmed without a terminal.\n", $curr_ver, $ver);
50 }
51 1 my $msg = sprintf
52 "version: %s\n" .
53 "current: %s\n" .
54 "The version format doesn't match the current one.\n" .
55 "Continue the release with this version? [y/n]", $ver, $curr_ver;
56 1 ▶ if (prompt($msg) !~ /y/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&prompt($msg) =~ /y/i) 0 1 1
57 0 errorf("Stop the release due to version format mismatch\n");
58 }
59 }
60  
61 4 my @opts;
62 4 push @opts, '-set', $ver;
63 4 ▶ if ($opts->{dry_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"dry_run"}) 4 0 4
64 4 push @opts, '-dryrun';
65 }
66 4 ▶ unless ($opts->{dry_run}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"dry_run"}) 0 4 4
67 0 $self->bump_version($project, $ver);
68  
69 # clear old version information
70 0 $project->clear_metadata();
71 0 my $newver = $project->metadata->version;
72 0 ▶ if (exists_tag($project->format_tag($newver))) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists_tag($project->format_tag($newver))) 0 0 0
73 0 errorf("Sorry, version '%s' is already tagged. Stopping.\n", $newver);
74 }
75 }
76 }
77 }
78  
79 0 ▶sub bump_version {
Subroutine bump_version: not called CC=10 SCAR=47.0
Pod undocumented
80 0 my ($self, $project, $version) = @_;
81  
82 0 for my $file ($project->perl_files) {
83 0 ▶ next if $file =~ /\.t$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.t$/ 0 0 0
84 0 ▶ next if $file =~ m{\Ashare/};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[\Ashare/] 0 0 0
85  
86 0 ▶ next if $file eq 'Makefile.PL' || $file eq 'Build.PL';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "Makefile.PL" or $file eq "Build.PL" 0 0 0
Condition0%0/3
$file eq "Makefile.PL" or $file eq "Build.PL"
l!l&&r!l&&!r
000
MC/DC0%0/2
$file eq "Makefile.PL" or $file eq "Build.PL"
$file eq "Makefile.PL" $file eq "Build.PL"
Truth table0%0/3
A or B
A= $file eq "Makefile.PL"B= $file eq "Build.PL"
ABresult
1X1
011
000
87 # copy from Menlo::CLI::Compat
88 0 ▶ next if grep { $file =~ m!^$_/! } @{$project->no_index->{directory} || []};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$file =~ m[^$_/];} @{$project->no_index->{"directory"} or [];} 0 0 0
Condition0%0/2
$project->no_index->{'directory'} || []
l!l
00
MC/DC0%0/1
$project->no_index->{'directory'} || []
$project->no_index->{'directory'}
Truth table0%0/2
A
A= $project->no_index->{'directory'}
Aresult
11
00
89 0 ▶ next if grep { $file eq $_ } @{$project->no_index->{file} || []};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$file eq $_;} @{$project->no_index->{"file"} or [];} 0 0 0
Condition0%0/2
$project->no_index->{'file'} || []
l!l
00
MC/DC0%0/1
$project->no_index->{'file'} || []
$project->no_index->{'file'}
Truth table0%0/2
A
A= $project->no_index->{'file'}
Aresult
11
00
90  
91 0 my $bump = Module::BumpVersion->load($file);
92 0 $bump->set_version($version);
93 }
94 }
95  
96 0 ▶sub default_new_version {
Subroutine default_new_version: not called CC=3 SCAR=24.8
Pod undocumented
97 0 my ($self, $project) = @_;
98 0 ▶ @_==2 or die;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or die 0 0 0
99  
100 0 my $curver = $project->metadata->version;
101 0 ▶ if (not exists_tag($project->format_tag($curver))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists_tag($project->format_tag($curver))) { } 0 0 0
102 0 $curver;
103 } else {
104 # $project->metadata->version returns version.pm object.
105 # But stringify was needed by Version::Next.
106 0 return Version::Next::next_version("$curver");
107 }
108 }
109  
110 4 ▶sub check_version_compatibility {
Subroutine check_version_compatibility: called CC=1 SCAR=0.0
Pod undocumented
111 4 my ($curr, $next) = @_;
112  
113 4 return version_format($curr) eq version_format($next)
114 }
115  
116 23 ▶sub version_format {
Subroutine version_format: called CC=4 SCAR=13.9
Pod undocumented
117 23 local $_ = shift;
118 # All formats accept an optional alpha notation starting with '_'.
119 return
120 # ex. 0.11, 3.14, 9.4_1
121 23 ▶ /^(?:0|[1-9][0-9]*)\.[0-9]+(?:_[0-9]+)?$/ ? 'decimal' :
Branch: 3 branches
BranchTrueFalseTotal
/^(?:0|[1-9][0-9]*)\.[0-9]+(?:_[0-9]+)?$/ ? : 9 14 23
/^v(?:0|[1-9][0-9]*)(?:\.[0-9]+){1,2}(?:_[0-9]+)?$/ ? : 7 7 14
/^(?:0|[1-9][0-9]*)(?:\.[0-9]+){2}(?:_[0-9]+)?$/ ? : 3 4 7
122 # ex. v1.2.3, v1.2.3_4, v3.3, v3.4_5
123 /^v(?:0|[1-9][0-9]*)(?:\.[0-9]+){1,2}(?:_[0-9]+)?$/ ? 'dotted' :
124 # ex. 0.1.2, 3.4.5_67 (to distinguish it from the decimal version, it must have exactly two dots)
125 /^(?:0|[1-9][0-9]*)(?:\.[0-9]+){2}(?:_[0-9]+)?$/ ? 'lax dotted' :
126 'unknown';
127 }
128  
129 0 ▶sub exists_tag {
Subroutine exists_tag: not called CC=1 SCAR=6.9
Pod undocumented
130 0 my ( $tag ) = @_;
131  
132 0 my $x = `git tag -l $tag`;
133 0 chomp $x;
134 0 return !!$x;
135 }
136  
137 2 1;
« Module/BumpVersion.pm ↑ Summary Minilla/Release/UploadToCPAN.pm »