PDRUtils/DistIniCmd/add_prereq.pm

filter: Statementstmt 41.5% 22 / 53 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 24.3% 29 / 119 CC 22 SCAR 59.9
CC
22
Cov
22%
handle_cmd
506.0
BEGIN
1.0
BEGIN
1.0
CRAP 397.8
« PDRUtils/DistIniCmd/sort_prereqs.pm ↑ Summary PDRUtils/DistIniCmd/_modify_prereq_version.pm »
1 package App::PDRUtils::DistIniCmd::add_prereq;
2  
3 3 our $DATE = '2021-05-25'; # DATE
4 3 our $VERSION = '0.122'; # VERSION
5  
6 3 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use App::PDRUtils::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use App::PDRUtils::DistIniCmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 our %SPEC;
15  
16 $SPEC{handle_cmd} = {
17 3 v => 1.1,
18 summary => 'Add a prereq',
19 args => {
20 %App::PDRUtils::DistIniCmd::common_args,
21 %App::PDRUtils::Cmd::mod_args,
22 %App::PDRUtils::Cmd::opt_mod_ver_args,
23 phase => {
24 summary => 'Select prereq phase',
25 schema => ['str*', match=>qr/\A(build|configure|develop|runtime|test|x_\w+)\z/],
26 default => 'runtime',
27 },
28 rel => {
29 summary => 'Select prereq relationship',
30 schema => ['str*', match=>qr/\A(requires|suggests|recommends|x_\w+)\z/],
31 default => 'requires',
32 },
33 # TODO: replace option
34 },
35 };
36 0 ▶sub handle_cmd {
Subroutine handle_cmd: not called CC=22 SCAR=62.3
Pod documented
37 0 my %args = @_;
38  
39 0 my $iod = $args{parsed_dist_ini};
40 0 my $mod = $args{module};
41 0 ▶ my $ver = $args{module_version} // 0;
Condition0%0/2
$args{"module_version"} // 0
l!l
00
MC/DC0%0/1
$args{"module_version"} // 0
$args{"module_version"}
Truth table0%0/2
A
A= $args{"module_version"}
Aresult
11
00
42 0 ▶ my $phase = $args{phase} // 'runtime';
Condition0%0/2
$args{"phase"} // "runtime"
l!l
00
MC/DC0%0/1
$args{"phase"} // "runtime"
$args{"phase"}
Truth table0%0/2
A
A= $args{"phase"}
Aresult
11
00
43 0 ▶ my $rel = $args{rel} // 'requires';
Condition0%0/2
$args{"rel"} // "requires"
l!l
00
MC/DC0%0/1
$args{"rel"} // "requires"
$args{"rel"}
Truth table0%0/2
A
A= $args{"rel"}
Aresult
11
00
44  
45 0 ▶ if (App::PDRUtils::Cmd::_has_prereq($iod, $mod)) {
Branch: 1 branch
BranchTrueFalseTotal
if (App::PDRUtils::Cmd::_has_prereq($iod, $mod)) 0 0 0
46 0 return [304, "Already has prereq to '$mod'"];
47 }
48  
49 0 my $section;
50 0 for my $s ($iod->list_sections) {
51 0 ▶ next unless $s =~ m!\Aprereqs(?:\s*/\s*(\w+))?\z!ix;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ m[\Aprereqs(?:\s*/\s*(\w+))?\z]xi 0 0 0
52 0 ▶ if ($phase eq 'runtime' && $rel eq 'requires') {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase eq 'runtime' and $rel eq 'requires') { } 0 0 0
Condition0%0/3
$phase eq "runtime" and $rel eq "requires"
!ll&&!rl&&r
000
MC/DC0%0/2
$phase eq "runtime" and $rel eq "requires"
$phase eq "runtime" $rel eq "requires"
Truth table0%0/3
A and B
A= $phase eq "runtime"B= $rel eq "requires"
ABresult
0X0
100
111
53 0 ▶ next unless !$1 || lc($1) eq 'runtimerequires';
Branch: 1 branch
BranchTrueFalseTotal
unless not $1 or lc $1 eq "runtimerequires" 0 0 0
Condition0%0/3
not $1 or lc $1 eq "runtimerequires"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $1 or lc $1 eq "runtimerequires"
not $1 lc $1 eq "runtimerequires"
Truth table0%0/3
not(A) or B
A= not $1B= lc $1 eq "runtimerequires"
ABresult
1X1
011
000
54 } else {
55 0 ▶ next unless $1 && lc($1) eq $phase.$rel;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 and lc $1 eq $phase . $rel 0 0 0
Condition0%0/3
$1 and lc $1 eq $phase . $rel
!ll&&!rl&&r
000
MC/DC0%0/2
$1 and lc $1 eq $phase . $rel
$1 lc $1 eq $phase . $rel
Truth table0%0/3
A and B
A= $1B= lc $1 eq $phase . $rel
ABresult
0X0
100
111
56 }
57 0 $section = $s;
58 0 last;
59 }
60 0 ▶ unless ($section) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($section) 0 0 0
61 0 ▶ if ($phase eq 'runtime' && $rel eq 'requires') {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase eq 'runtime' and $rel eq 'requires') { } 0 0 0
Condition0%0/3
$phase eq "runtime" and $rel eq "requires"
!ll&&!rl&&r
000
MC/DC0%0/2
$phase eq "runtime" and $rel eq "requires"
$phase eq "runtime" $rel eq "requires"
Truth table0%0/3
A and B
A= $phase eq "runtime"B= $rel eq "requires"
ABresult
0X0
100
111
62 0 $section = 'Prereqs';
63 } else {
64 0 $section = 'Prereqs / '.ucfirst($phase).ucfirst($rel);
65 }
66 }
67  
68 0 my ($modified, $linum);
69  
70 0 ▶ if ($phase =~ /\Ax_/ || $rel =~ /\Ax_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase =~ /\Ax_/ or $rel =~ /\Ax_/) 0 0 0
Condition0%0/3
$phase =~ /\Ax_/ or $rel =~ /\Ax_/
l!l&&r!l&&!r
000
MC/DC0%0/2
$phase =~ /\Ax_/ or $rel =~ /\Ax_/
$phase =~ /\Ax_/ $rel =~ /\Ax_/
Truth table0%0/3
A or B
A= $phase =~ /\Ax_/B= $rel =~ /\Ax_/
ABresult
1X1
011
000
71 0 $linum = $iod->insert_key(
72 {create_section=>1, ignore=>1}, $section, "-phase", $phase);
73 0 ▶ $modified = 1 if defined $linum;
Branch: 1 branch
BranchTrueFalseTotal
if defined $linum 0 0 0
74 0 $linum = $iod->insert_key(
75 {create_section=>1, ignore=>1}, $section, "-relationship", $rel);
76 0 ▶ $modified = 1 if defined $linum;
Branch: 1 branch
BranchTrueFalseTotal
if defined $linum 0 0 0
77 }
78  
79 0 $linum = $iod->insert_key(
80 {create_section=>1, ignore=>1}, $section, $mod, $ver);
81 0 ▶ $modified = 1 if defined $linum;
Branch: 1 branch
BranchTrueFalseTotal
if defined $linum 0 0 0
82  
83 0 ▶ if ($modified) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modified) { } 0 0 0
84 0 return [200, "Added prereq '$mod=$ver' to section [$section]", $iod];
85 } else {
86 0 return [304, "Not modified"];
87 }
88 }
89  
90 3 1;
91 # ABSTRACT: Add a prereq
92  
93 __END__
« PDRUtils/DistIniCmd/sort_prereqs.pm ↑ Summary PDRUtils/DistIniCmd/_modify_prereq_version.pm »