IOMux/IPC.pm

filter: Statementstmt 89.2% 58 / 65 Branchbran 43.3% 13 / 30 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 78.5% 11 / 14 Podpod 80.0% 4 / 5 totaltotal 72.5% 87 / 120 CC 18 SCAR 28.3
CC
18
Cov
73%
init
29.4
open
6.0
mode
2.0
CRAP 17.0
« IOMux/Net/TCP.pm ↑ Summary IOMux.pm »
1 # Copyrights 2011-2020 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution IOMux. Meta-POD processed with OODoc
6 # into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package IOMux::IPC;
10 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = '1.01';
12  
13 3 ▶use base 'IOMux::Bundle';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use Log::Report 'iomux';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use IOMux::Pipe::Read ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use IOMux::Pipe::Write ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use POSIX qw/:errno_h :sys_wait_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use File::Basename 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27 sub init($)
28 2 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=17 SCAR=33.8
Pod undocumented
29 my $command = $args->{command}
30 2 ▶ or error __x"no command to run specified in {pkg}", pkg => __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
my $command = $args->{"command"} or &error(&__x("no command to run specified in {pkg}", "pkg", __PACKAGE__)) 2 0 2
31  
32 2 ▶ my ($cmd, @cmdopts) = ref $command eq 'ARRAY' ? @$command : $command;
Branch: 1 branch
BranchTrueFalseTotal
ref $command eq 'ARRAY' ? : 2 0 2
33 2 my $name = $args->{name} = '|'.(basename $cmd).'|';
34  
35 2 ▶ my $mode = $args->{mode} || '|-|';
Condition50%1/2
$args->{'mode'} || '|-|'
l!l
02
MC/DC0%0/1
$args->{'mode'} || '|-|'
$args->{'mode'}
Truth table50%1/2
A
A= $args->{'mode'}
Aresult
11
00
36 2 my $errors = $args->{errors};
37 0 ▶ if($mode eq '|=|') { $errors //= 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq '|=|') { } 0 2 2
elsif ($mode eq '|-|') { } 2 0 2
Condition0%0/2
$errors //= 1
l!l
00
MC/DC0%0/1
$errors //= 1
$errors
Truth table0%0/2
A
A= $errors
Aresult
11
00
38 2 ▶ elsif($mode eq '|-|') { $mode = '|=|' if $errors }
Branch: 1 branch
BranchTrueFalseTotal
if $errors 0 2 2
39 else
40 0 { error __x"unknown mode {mode} for {pkg}"
41 , mode => $mode, pkg => __PACKAGE__;
42 }
43  
44 2 ($args->{stdin}, my $in_rh)
45 = IOMux::Pipe::Write->bare(name => 'stdin');
46 2 ($args->{stdout}, my $out_wh)
47 = IOMux::Pipe::Read->bare(name => 'stdout');
48 2 ▶ ($args->{stderr}, my $err_wh)
Branch: 1 branch
BranchTrueFalseTotal
$errors ? : 0 2 2
49 = $errors ? IOMux::Pipe::Read->bare(name => 'stderr') : ();
50  
51 2 my $pid = fork;
52 2 ▶ defined $pid
Branch: 1 branch
BranchTrueFalseTotal
defined $pid or &fault(&__x("failed to fork for ipc {cmd}", "cmd", $name)) 2 0 2
53 or fault __x"failed to fork for ipc {cmd}", cmd => $name;
54  
55 2 ▶ if($pid==0)
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 1 1 2
56 { # client
57 1 ▶ open STDIN, '<&', $in_rh
Branch: 1 branch
BranchTrueFalseTotal
CORE::open STDIN, "<&", $in_rh or &fault(&__x("failed to redirect STDIN for ipc {cmd}", "cmd", $name)) 1 0 1
58 or fault __x"failed to redirect STDIN for ipc {cmd}", cmd=>$name;
59 1 ▶ open STDOUT, '>&', $out_wh
Branch: 1 branch
BranchTrueFalseTotal
CORE::open STDOUT, ">&", $out_wh or &fault(&__x("failed to redirect STDOUT for ipc {cmd}", "cmd", $name)) 1 0 1
60 or fault __x"failed to redirect STDOUT for ipc {cmd}", cmd=>$name;
61 1 ▶ if($err_wh)
Branch: 1 branch
BranchTrueFalseTotal
if ($err_wh) { } 0 1 1
62 0 ▶ { open STDERR, '>&', $err_wh
Branch: 1 branch
BranchTrueFalseTotal
CORE::open STDERR, ">&", $err_wh or &fault(&__x("failed to redirect STDERR for ipc {cmd}", "cmd", $name)) 0 0 0
63 or fault __x"failed to redirect STDERR for ipc {cmd}"
64 , cmd => $name;
65 }
66 else
67 1 { open STDERR, '>', File::Spec->devnull;
68 }
69  
70 1 ▶ exec $cmd, @cmdopts
Branch: 1 branch
BranchTrueFalseTotal
exec $cmd, @cmdopts or &fault(&__x("failed to exec for pipe {cmd}", "cmd", $name)) 0 0 0
71 or fault __x"failed to exec for pipe {cmd}", cmd => $name;
72 }
73  
74 # parent
75  
76 1 close $in_rh;
77 1 close $out_wh;
78 1 ▶ close $err_wh if $err_wh;
Branch: 1 branch
BranchTrueFalseTotal
if $err_wh 0 1 1
79  
80 1 $self->{IMI_pid} = $pid;
81 1 $self->SUPER::init($args);
82 1 $self;
83 }
84  
85  
86 sub open($$@)
87 0 ▶{ my ($class, $mode, $cmd) = (shift, shift, shift);
Subroutine open: not called CC=2 SCAR=17.9
Pod documented
88 0 ▶ ref $cmd eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $cmd eq 'ARRAY' ? : 0 0 0
89 ? $class->new(command => $cmd, mode => $mode, @_)
90 : $class->new(command => [$cmd, @_] , mode => $mode);
91 }
92  
93 #-------------------
94  
95 0 ▶sub mode() {shift->{IMI_mode}}
Subroutine mode: not called CC=1 SCAR=6.9
Pod documented
96 0 ▶sub childPid() {shift->{IMI_pid}}
Subroutine childPid: not called CC=1 SCAR=6.9
Pod documented
97  
98 #-------------------
99  
100 sub close($)
101 1 ▶{ my ($self, $cb) = @_;
Subroutine close: called CC=1 SCAR=0.0
Pod documented
102 1 waitpid $self->{IMI_pid}, WNOHANG;
103 1 local $?;
104 1 $self->SUPER::close($cb);
105 }
106  
107 3 1;
« IOMux/Net/TCP.pm ↑ Summary IOMux.pm »