| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::NDTools::NDProc::Module::Pipe; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 66004 | use strict; | 
|  | 4 |  |  |  |  | 16 |  | 
|  | 4 |  |  |  |  | 143 |  | 
| 4 | 4 |  |  | 4 |  | 22 | use warnings FATAL => 'all'; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 177 |  | 
| 5 | 4 |  |  | 4 |  | 463 | use parent 'App::NDTools::NDProc::Module'; | 
|  | 4 |  |  |  |  | 363 |  | 
|  | 4 |  |  |  |  | 25 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 4 |  |  | 4 |  | 2586 | use IPC::Run3; | 
|  | 4 |  |  |  |  | 63221 |  | 
|  | 4 |  |  |  |  | 252 |  | 
| 8 | 4 |  |  | 4 |  | 35 | use Log::Log4Cli; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 354 |  | 
| 9 | 4 |  |  | 4 |  | 26 | use App::NDTools::Slurp qw(s_decode s_encode); | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 231 |  | 
| 10 | 4 |  |  | 4 |  | 25 | use Struct::Path 0.80 qw(path); | 
|  | 4 |  |  |  |  | 93 |  | 
|  | 4 |  |  |  |  | 1952 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '0.07'; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 1 |  |  | 1 | 0 | 7 | sub MODINFO { "Modify structure using external process" } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub arg_opts { | 
| 17 | 11 |  |  | 11 | 0 | 22 | 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 | 11 |  |  |  |  | 68 | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub check_rule { | 
| 27 | 9 |  |  | 9 | 0 | 20 | my ($self, $rule) = @_; | 
| 28 | 9 |  |  |  |  | 15 | my $out = $self; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 9 | 100 |  |  |  | 14 | push @{$rule->{path}}, '' unless (@{$rule->{path}}); | 
|  | 3 |  |  |  |  | 11 |  | 
|  | 9 |  |  |  |  | 32 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 9 | 100 |  |  |  | 26 | unless (defined $rule->{command}) { | 
| 33 | 1 |  |  | 1 |  | 6 | log_error { 'Command to run should be defined' }; | 
|  | 1 |  |  |  |  | 154 |  | 
| 34 | 1 |  |  |  |  | 6 | $out = undef; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 9 |  |  |  |  | 41 | return $out; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub process_path { | 
| 41 | 7 |  |  | 7 | 0 | 26 | my ($self, $data, $path, $spath, $opts) = @_; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 7 |  |  |  |  | 48 | my @refs = eval { path(${$data}, $spath, strict => $opts->{strict}) }; | 
|  | 7 |  |  |  |  | 15 |  | 
|  | 7 |  |  |  |  | 73 |  | 
| 44 | 7 | 100 |  |  |  | 986 | die_fatal "Failed to lookup path '$path'", 4 if ($@); | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 6 |  |  |  |  | 16 | for my $r (@refs) { | 
| 47 | 6 |  |  |  |  | 13 | my $in = s_encode(${$r}, 'JSON', { pretty => 1 }); | 
|  | 6 |  |  |  |  | 33 |  | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 6 |  |  |  |  | 20 | my ($out, $err); | 
| 50 | 6 |  |  |  |  | 48 | run3($opts->{command}, \$in, \$out, \$err, { return_if_system_error => 1}); | 
| 51 | 6 | 50 |  |  |  | 41347 | die_fatal "Failed to run '$opts->{command}' ($!)", 2 | 
| 52 |  |  |  |  |  |  | if ($? == -1); # run3 specific | 
| 53 | 6 | 100 |  |  |  | 66 | unless ($? == 0) { | 
| 54 | 1 | 50 |  |  |  | 66 | die_fatal "'$opts->{command}' exited with " . ($? >> 8) . | 
| 55 |  |  |  |  |  |  | ($err ? " (" . join(" ", split("\n", $err)) . ")" : ""), 16; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 5 |  |  |  |  | 119 | ${$r} = s_decode($out, 'JSON'); | 
|  | 4 |  |  |  |  | 202 |  | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 1; # End of App::NDTools::NDProc::Module::Pipe | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | __END__ |