PDRUtils/DistIniCmd/_modify_prereq_version.pm

filter: Statementstmt 21.5% 14 / 65 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 17.3% 18 / 104 CC 20 SCAR 58.6
CC
20
Cov
14%
_modify_prereq_version
420.0
BEGIN
1.0
BEGIN
1.0
CRAP 350.2
« PDRUtils/DistIniCmd/add_prereq.pm ↑ Summary PDRUtils/DistIniCmd/list_prereqs.pm »
1 package App::PDRUtils::DistIniCmd::_modify_prereq_version;
2  
3 16 our $DATE = '2021-05-25'; # DATE
4 16 our $VERSION = '0.122'; # VERSION
5  
6 16 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 16 ▶use Version::Util qw(version_eq version_gt version_lt
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 add_version subtract_version);
12  
13 0 ▶sub _modify_prereq_version {
Subroutine _modify_prereq_version: not called CC=20 SCAR=60.4
14 0 require Config::IOD;
15 0 require File::Slurper;
16  
17 0 my $which = shift;
18 0 my %args = @_;
19  
20 0 my $iod = $args{parsed_dist_ini};
21 0 my $mod = $args{module};
22  
23 0 my $found;
24 my $modified;
25 0 my ($old_v, $new_v);
26  
27 SECTION:
28 0 for my $section ($iod->list_sections) {
29 0 ▶ next unless $section =~ m!\APrereqs(?:\s*/\s*\w+)?\z!;
Branch: 1 branch
BranchTrueFalseTotal
unless $section =~ m[\APrereqs(?:\s*/\s*\w+)?\z] 0 0 0
30 0 for my $param ($iod->list_keys($section)) {
31 0 ▶ next unless $param eq $mod;
Branch: 1 branch
BranchTrueFalseTotal
unless $param eq $mod 0 0 0
32 0 $old_v = $iod->get_value($section, $param);
33 0 ▶ return [412, "Prereq '$mod' is specified multiple times"]
Branch: 1 branch
BranchTrueFalseTotal
if ref $old_v eq "ARRAY" 0 0 0
34 if ref($old_v) eq 'ARRAY';
35 0 $found++;
36 0 ▶ if ($which eq 'set_to') {
Branch: 5 branches
BranchTrueFalseTotal
if ($which eq 'set_to') { } 0 0 0
elsif ($which eq 'inc_to') { } 0 0 0
elsif ($which eq 'dec_to') { } 0 0 0
elsif ($which eq 'inc_by') { } 0 0 0
elsif ($which eq 'dec_by') { } 0 0 0
37 0 $new_v = $args{module_version};
38 0 ▶ if (version_eq($old_v, $new_v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (version_eq($old_v, $new_v)) 0 0 0
39 0 return [304, "Version of '$mod' already the same ($old_v)"];
40 }
41 0 $iod->set_value({all=>1}, $section, $param, $new_v);
42 0 $modified++;
43 } elsif ($which eq 'inc_to') {
44 0 $new_v = $args{module_version};
45 0 ▶ unless (version_gt($new_v, $old_v)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (version_gt($new_v, $old_v)) 0 0 0
46 0 return [304, "Version of '$mod' ($old_v) already >= $new_v"];
47 }
48 0 $iod->set_value({all=>1}, $section, $param, $new_v);
49 0 $modified++;
50 } elsif ($which eq 'dec_to') {
51 0 $new_v = $args{module_version};
52 0 ▶ unless (version_lt($new_v, $old_v)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (version_lt($new_v, $old_v)) 0 0 0
53 0 return [304, "Version of '$mod' ($old_v) already <= $new_v"];
54 }
55 0 $iod->set_value({all=>1}, $section, $param, $new_v);
56 0 $modified++;
57 } elsif ($which eq 'inc_by') {
58 0 eval { $new_v = add_version($old_v, $args{by}) };
59 0 ▶ return [500, "Can't add version ($old_v + $args{by}): $@"] if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
60 0 ▶ if (version_eq($new_v, $old_v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (version_eq($new_v, $old_v)) 0 0 0
61 0 return [304, "Version of '$mod' ($old_v) already = $new_v"];
62 }
63 0 $iod->set_value({all=>1}, $section, $param, $new_v);
64 0 $modified++;
65 } elsif ($which eq 'dec_by') {
66 0 eval { $new_v = subtract_version($old_v, $args{by}) };
67 0 ▶ return [500, "Can't subtract version ($old_v - $args{by}): $@"] if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
68 0 ▶ if (version_eq($new_v, $old_v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (version_eq($new_v, $old_v)) 0 0 0
69 0 return [304, "Version of '$mod' ($old_v) already = $new_v"];
70 }
71 0 $iod->set_value({all=>1}, $section, $param, $new_v);
72 0 $modified++;
73 } else {
74 0 return [500, "BUG: Unknown which '$which'"];
75 }
76 }
77 }
78  
79 0 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 0 0 0
80 0 ▶ if ($modified) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modified) { } 0 0 0
81 0 return [200, "Set prereq '$mod' version from $old_v to $new_v", $iod];
82 } else {
83 0 return [304, "Not modified"];
84 }
85 } else {
86 0 return [304, "No prereq to '$mod' specified"];
87 }
88 }
89  
90 16 1;
91 # ABSTRACT: Common routines for set_prereq_version_to, {inc,dec}_prereq_version_{to,by}
92  
93 __END__
« PDRUtils/DistIniCmd/add_prereq.pm ↑ Summary PDRUtils/DistIniCmd/list_prereqs.pm »