| 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 | |||||||||||
| 12 | 4 | our $VERSION = '0.08'; | |||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | sub MODINFO { "Modify structure using external process" } | ||||||||
|
Subroutine
MODINFO: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | 13 | ▶ | sub arg_opts { | ||||||||
|
Subroutine
arg_opts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 13 | my $self = shift; | |||||||||
| 18 | |||||||||||
| 19 | return ( | ||||||||||
| 20 | $self->SUPER::arg_opts(), | ||||||||||
| 21 | 'command|cmd=s' => \$self->{OPTS}->{command}, | ||||||||||
| 22 | 'strict' => \$self->{OPTS}->{strict}, | ||||||||||
| 23 | ) | ||||||||||
| 24 | 13 | } | |||||||||
| 25 | |||||||||||
| 26 | 9 | ▶ | sub check_rule { | ||||||||
|
Subroutine
check_rule: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 27 | 9 | my ($self, $rule) = @_; | |||||||||
| 28 | 9 | my $out = $self; | |||||||||
| 29 | |||||||||||
| 30 | 9 | ▶ | push @{$rule->{path}}, '' unless (@{$rule->{path}}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 9 | ▶ | unless (defined $rule->{command}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 1 | ▶ | log_error { 'Command to run should be defined' }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 1 | $out = undef; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 9 | return $out; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 7 | ▶ | sub process_path { | ||||||||
|
Subroutine
process_path: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||
| 41 | 7 | my ($self, $data, $path, $spath, $opts) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 7 | my @refs = eval { path(${$data}, $spath, strict => $opts->{strict}) }; | |||||||||
| 44 | 7 | ▶ | die_fatal "Failed to lookup path '$path'", 4 if ($@); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 6 | for my $r (@refs) { | |||||||||
| 47 | 6 | my $in = s_encode(${$r}, 'JSON', { pretty => 1 }); | |||||||||
| 48 | |||||||||||
| 49 | 6 | my ($out, $err); | |||||||||
| 50 | 6 | run3($opts->{command}, \$in, \$out, \$err, { return_if_system_error => 1}); | |||||||||
| 51 | 6 | ▶ | die_fatal "Failed to run '$opts->{command}' ($!)", 2 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | if ($? == -1); # run3 specific | ||||||||||
| 53 | 6 | ▶ | unless ($? == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 1 | ▶ | die_fatal "'$opts->{command}' exited with " . ($? >> 8) . | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | ($err ? " (" . join(" ", split("\n", $err)) . ")" : ""), 16; | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 5 | ${$r} = s_decode($out, 'JSON'); | |||||||||
| 59 | } | ||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 4 | 1; # End of App::NDTools::NDProc::Module::Pipe | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||