PDRUtils/SingleCmd.pm

filter: Statementstmt 68.6% 46 / 67 Branchbran 7.1% 1 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 61.9% 57 / 92 CC 10 SCAR 30.4
CC
10
Cov
58%
__ANON__
51.7
create_cmd_from_dist_ini_cmd
6.9
BEGIN
1.0
CRAP 20.9
« PDRUtils/DistIniCmd/list_prereqs.pm ↑ Summary PDRUtils/Cmd.pm »
1 package App::PDRUtils::SingleCmd;
2  
3 10 our $DATE = '2021-05-25'; # DATE
4 10 our $VERSION = '0.122'; # VERSION
5  
6 10 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use App::PDRUtils::DistIniCmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Function::Fallback::CoreOrPP qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 our %common_args = (
15 );
16  
17 9 ▶sub create_cmd_from_dist_ini_cmd {
Subroutine create_cmd_from_dist_ini_cmd: called CC=4 SCAR=19.3
Pod documented
18 9 require Config::IOD;
19 9 require File::Slurper;
20  
21 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 9 my %cargs = @_;
24  
25 9 my $name = $cargs{dist_ini_cmd};
26  
27 9 my $source_pkg = "App::PDRUtils::DistIniCmd::$name";
28 9 my $target_pkg = caller();#"App::PDRUtils::SingleCmd::$name";
29  
30 9 ▶ eval "use $source_pkg"; die if $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 9 9
31  
32 9 my $source_specs = \%{"$source_pkg\::SPEC"};
33 9 my $spec = clone($source_specs->{handle_cmd});
34  
35 9 for (keys %App::PDRUtils::DistIniCmd::common_args) {
36 9 delete $spec->{args}{$_};
37 }
38 9 for (keys %common_args) {
39 0 $spec->{args}{$_} = $common_args{$_};
40 }
41 9 $spec->{features}{dry_run} = 1;
42  
43 9 ${"$target_pkg\::SPEC"}{handle_cmd} = $spec;
44 9 ▶ *{"$target_pkg\::handle_cmd"} = sub {
Subroutine __ANON__: not called CC=7 SCAR=39.5
45 0 my %fargs = @_;
46 0 ▶ return [412, "No dist.ini in current directory"] unless -f "dist.ini";
Branch: 1 branch
BranchTrueFalseTotal
unless -f "dist.ini" 0 0 0
47  
48 0 my $ciod = Config::IOD->new(
49 ignore_unknown_directive => 1,
50 );
51 0 my $iod;
52 0 eval { $iod = $ciod->read_file("dist.ini") };
53 0 ▶ return [500, "Can't parse dist.ini: $@"] if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
54 0 my $handle_cmd = \&{"$source_pkg\::handle_cmd"};
55 0 my $res = $handle_cmd->(
56 %fargs,
57 parsed_dist_ini => $iod,
58 );
59 0 ▶ if ($res->[0] == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] == 200) { } 0 0 0
60 log_info("%s%s",
61 0 ▶ $fargs{-dry_run} ? "[DRY-RUN] " : "",
Branch: 1 branch
BranchTrueFalseTotal
$fargs{'-dry_run'} ? : 0 0 0
62 $res->[1]);
63 0 ▶ if ($fargs{-dry_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fargs{'-dry_run'}) { } 0 0 0
64 0 $res->[0] = 304;
65 } else {
66 0 File::Slurper::write_text("dist.ini", $res->[2]->as_string);
67 }
68 0 undef $res->[2];
69 } else {
70 0 log_trace("%d - %s", $res->[0], $res->[1]);
71 }
72  
73 # move final result so users can see it
74 0 ▶ if (exists $res->[3]{'func.result'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $res->[3]{"func.result"}) 0 0 0
75 0 $res->[2] = delete $res->[3]{'func.result'};
76 }
77  
78 0 $res;
79 9 };
80 }
81  
82 10 1;
83 # ABSTRACT: Common stuffs for App::PDRUtils::SingleCmd::*
84  
85 __END__
« PDRUtils/DistIniCmd/list_prereqs.pm ↑ Summary PDRUtils/Cmd.pm »