blib/lib/App/NDTools/NDProc/Module/Pipe.pm

filter: Statementstmt 100% 57 / 57 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 4 totaltotal 92.0% 81 / 88 CC 9 SCAR 12.0
CC
9
Cov
96%
process_path
7.1
check_rule
3.0
BEGIN
1.0
CRAP 3.3
« blib/lib/App/NDTools/NDTool.pm ↑ Summary blib/lib/App/NDTools/NDProc/Module/Remove.pm »
1 package App::NDTools::NDProc::Module::Pipe;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use parent 'App::NDTools::NDProc::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use IPC::Run3;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Log::Log4Cli;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use App::NDTools::Slurp qw(s_decode s_encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Struct::Path 0.80 qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Struct::Path::PerlStyle 0.80 qw(str2path);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = '0.06';
14  
15 1 ▶sub MODINFO { "Modify structure using external process" }
Subroutine MODINFO: called CC=1 SCAR=0.0
Pod undocumented
16  
17 sub arg_opts {
18 8 ▶ my $self = shift;
Subroutine arg_opts: called CC=1 SCAR=0.0
Pod undocumented
19  
20 return (
21 $self->SUPER::arg_opts(),
22 'command|cmd=s' => \$self->{OPTS}->{command},
23 'strict' => \$self->{OPTS}->{strict},
24 )
25 8 }
26  
27 sub check_rule {
28 8 ▶ my ($self, $rule) = @_;
Subroutine check_rule: called CC=3 SCAR=11.0
Pod undocumented
29 8 my $out = $self;
30  
31 # process full source if no paths defined # FIXME: move it to parent and make common for all mods
32 8 ▶ push @{$rule->{path}}, '' unless (@{$rule->{path}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$rule->{"path"};} 3 5 8
33  
34 8 ▶ unless (defined $rule->{command}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rule->{"command"}) 1 7 8
35 1 ▶ log_error { 'Command to run should be defined' };
Subroutine __ANON__: called CC=1 SCAR=0.0
36 1 $out = undef;
37 }
38  
39 8 return $out;
40 }
41  
42 sub process_path {
43 7 ▶ my ($self, $data, $path, $opts) = @_;
Subroutine process_path: called CC=7 SCAR=19.5
Pod undocumented
44  
45 7 my $spath = eval { str2path($path) };
46 7 ▶ die_fatal "Failed to parse path ($@)", 4 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
47  
48 7 my @refs = eval { path(${$data}, $spath, strict => $opts->{strict}) };
49 7 ▶ die_fatal "Failed to lookup path '$path'", 4 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 6 7
50  
51 6 for my $r (@refs) {
52 6 my $in = s_encode(${$r}, 'JSON', { pretty => 1 });
53  
54 6 my ($out, $err);
55 6 run3($opts->{command}, \$in, \$out, \$err, { return_if_system_error => 1});
56 6 ▶ die_fatal "Failed to run '$opts->{command}' ($!)", 2
Branch: 1 branch
BranchTrueFalseTotal
if $? == -1 0 6 6
57 if ($? == -1); # run3 specific
58 6 ▶ unless ($? == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? == 0) 1 5 6
59 1 ▶ die_fatal "'$opts->{command}' exited with " . ($? >> 8) .
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 1 1
60 ($err ? " (" . join(" ", split("\n", $err)) . ")" : ""), 16;
61 }
62  
63 5 ${$r} = s_decode($out, 'JSON');
64 }
65 }
66  
67 4 1; # End of App::NDTools::NDProc::Module::Pipe
68  
69 __END__
« blib/lib/App/NDTools/NDTool.pm ↑ Summary blib/lib/App/NDTools/NDProc/Module/Remove.pm »