Hevy.pm

filter: Statementstmt 97.2% 71 / 73 Branchbran 90.0% 36 / 40 Conditioncond 77.4% 24 / 31 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 85.6% 143 / 167 CC 30 SCAR 32.1
CC
30
Cov
91%
exec
31.2
BEGIN
1.0
BEGIN
1.0
CRAP 24.8
↑ Summary Hevy/Reader.pm »
1 package Proc::Hevy;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Errno qw( EWOULDBLOCK );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use IO::Pipe;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use Proc::Hevy::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Proc::Hevy::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 103 ▶sub exec {
Subroutine exec: called CC=30 SCAR=34.4
Pod documented
15 103 my ( $class, @args ) = @_;
16  
17 103 ▶ confess 'Odd number of parameters'
Branch: 1 branch
BranchTrueFalseTotal
unless @args % 2 == 0 6 97 103
18 unless @args % 2 == 0;
19 97 my %args = @args;
20  
21 confess 'command: Required parameter not defined'
22 97 ▶ unless defined $args{command};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"command"} 6 91 97
23  
24 91 ▶ if( ref( $args{command} ) =~ /^(?:CODE)?\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($args{'command'}) =~ /^(?:CODE)?\z/) { } 70 21 91
elsif (ref $args{'command'} ne 'ARRAY') { } 6 15 21
25 70 $args{command} = [ $args{command} ];
26 }
27 elsif( ref( $args{command} ) ne 'ARRAY' ) {
28 6 confess 'command: Must be an ARRAY reference';
29 }
30  
31 ref( $args{stdin} ) =~ /^(?:ARRAY|CODE|GLOB)\z/
32 or confess 'stdin: Must be one of ARRAY, CODE or GLOB reference'
33 85 ▶ if exists $args{stdin} and ref $args{stdin};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"stdin"} and ref $args{"stdin"} 15 70 85
Condition87%7/8
exists $args{'stdin'} && ref $args{'stdin'} && (ref($args{'stdin'}) =~ /^(?:ARRAY|CODE|GLOB)\z/ || confess('stdin: Must be one of ARRAY, CODE or GLOB reference'))
!ll&&!rl&&r
70150
exists $args{"stdin"} and ref $args{"stdin"}
!ll&&!rl&&r
462415
ref($args{"stdin"}) =~ /^(?:ARRAY|CODE|GLOB)\z/ or confess("stdin: Must be one of ARRAY, CODE or GLOB reference")
l!l
96
MC/DC0%0/3
exists $args{'stdin'} && ref $args{'stdin'} && (ref($args{'stdin'}) =~ /^(?:ARRAY|CODE|GLOB)\z/ || confess('stdin: Must be one of ARRAY, CODE or GLOB reference'))
exists $args{"stdin"} ref $args{"stdin"} ref($args{"stdin"}) =~ /^(?:ARRAY|CODE|GLOB)\z/
Truth table50%2/4
A and B && C
A= exists $args{"stdin"}B= ref $args{"stdin"}C= ref($args{"stdin"}) =~ /^(?:ARRAY|CODE|GLOB)\z/
ABCresult
0XX0
10X0
1100
1111
34  
35 ref( $args{stdout} ) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/
36 or confess 'stdout: Must be one of ARRAY, CODE, GLOB or SCALAR reference'
37 79 ▶ if exists $args{stdout};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"stdout"} 59 20 79
Condition80%4/5
exists $args{'stdout'} && (ref($args{'stdout'}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/ || confess('stdout: Must be one of ARRAY, CODE, GLOB or SCALAR reference'))
!ll&&!rl&&r
20590
ref($args{"stdout"}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/ or confess("stdout: Must be one of ARRAY, CODE, GLOB or SCALAR reference")
l!l
536
MC/DC0%0/2
exists $args{'stdout'} && (ref($args{'stdout'}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/ || confess('stdout: Must be one of ARRAY, CODE, GLOB or SCALAR reference'))
exists $args{'stdout'} ref($args{"stdout"}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/
Truth table66%2/3
A && B
A= exists $args{'stdout'}B= ref($args{"stdout"}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/
ABresult
0X0
100
111
38  
39 ref( $args{stderr} ) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/
40 or confess 'stderr: Must be one of ARRAY, CODE, GLOB or SCALAR reference'
41 73 ▶ if exists $args{stderr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"stderr"} 59 14 73
Condition80%4/5
exists $args{'stderr'} && (ref($args{'stderr'}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/ || confess('stderr: Must be one of ARRAY, CODE, GLOB or SCALAR reference'))
!ll&&!rl&&r
14590
ref($args{"stderr"}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/ or confess("stderr: Must be one of ARRAY, CODE, GLOB or SCALAR reference")
l!l
536
MC/DC0%0/2
exists $args{'stderr'} && (ref($args{'stderr'}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/ || confess('stderr: Must be one of ARRAY, CODE, GLOB or SCALAR reference'))
exists $args{'stderr'} ref($args{"stderr"}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/
Truth table66%2/3
A && B
A= exists $args{'stderr'}B= ref($args{"stderr"}) =~ /^(?:ARRAY|CODE|GLOB|SCALAR)\z/
ABresult
0X0
100
111
42  
43 ref( $args{parent} ) eq 'CODE'
44 or confess 'parent: Must be a CODE reference'
45 67 ▶ if defined $args{parent};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"parent"} 6 61 67
Condition60%3/5
defined $args{'parent'} && (ref $args{'parent'} eq 'CODE' || confess('parent: Must be a CODE reference'))
!ll&&!rl&&r
6160
ref $args{"parent"} eq "CODE" or confess("parent: Must be a CODE reference")
l!l
60
MC/DC0%0/2
defined $args{'parent'} && (ref $args{'parent'} eq 'CODE' || confess('parent: Must be a CODE reference'))
defined $args{'parent'} ref $args{"parent"} eq "CODE"
Truth table33%1/3
A && B
A= defined $args{'parent'}B= ref $args{"parent"} eq "CODE"
ABresult
0X0
100
111
46  
47 ref( $args{child} ) eq 'CODE'
48 or confess 'child: Must be a CODE reference'
49 67 ▶ if defined $args{child};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"child"} 6 61 67
Condition60%3/5
defined $args{'child'} && (ref $args{'child'} eq 'CODE' || confess('child: Must be a CODE reference'))
!ll&&!rl&&r
6160
ref $args{"child"} eq "CODE" or confess("child: Must be a CODE reference")
l!l
60
MC/DC0%0/2
defined $args{'child'} && (ref $args{'child'} eq 'CODE' || confess('child: Must be a CODE reference'))
defined $args{'child'} ref $args{"child"} eq "CODE"
Truth table33%1/3
A && B
A= defined $args{'child'}B= ref $args{"child"} eq "CODE"
ABresult
0X0
100
111
50  
51 $args{priority} = 0
52 67 ▶ unless defined $args{priority};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"priority"} 63 4 67
53  
54 67 my $std_i = Proc::Hevy::Writer->new( stdin => $args{stdin} );
55 67 my $std_o = Proc::Hevy::Reader->new( stdout => $args{stdout} );
56 67 my $std_e = Proc::Hevy::Reader->new( stderr => $args{stderr} );
57  
58 # fork
59 67 my $pid = fork;
60 67 ▶ confess "fork: $!\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 67 67
61 unless defined $pid;
62  
63 67 ▶ if( $pid == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 20 47 67
64 # child
65  
66 # run callback, if needed
67 $args{child}->( getppid )
68 20 ▶ if defined $args{child};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"child"} 2 18 20
69  
70 # set filehandles
71 20 $std_i->child( \*STDIN, 0 );
72 20 $std_o->child( \*STDOUT, 1 );
73 20 $std_e->child( \*STDERR, 2 );
74  
75 # set process priority, if needed
76 20 ▶ if( $args{priority} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"priority"}) 2 18 20
77 2 my $priority = getpriority( 0, $$ );
78 2 ▶ defined $priority
Branch: 1 branch
BranchTrueFalseTotal
defined $priority or die "getpriority(): ${$}: $!\n" 2 0 2
79 or die "getpriority(): $$: $!\n";
80  
81 2 $priority += $args{priority};
82  
83 2 ▶ setpriority( 0, $$, $priority )
Branch: 1 branch
BranchTrueFalseTotal
setpriority 0, $$, $priority or die "setpriority(): ${$}: $!\n" 2 0 2
84 or die "setpriority(): $$: $!\n";
85 }
86  
87 # exec
88 20 ▶ if( ref( $args{command}->[0] ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"command"}[0] eq "CODE") 18 2 20
89 18 my $sub = shift @{ $args{command} };
90 18 $sub->( @{ $args{command} } );
91 13 exit 0;
92 }
93  
94 2 exec @{ $args{command} };
95 0 warn "exec: $args{command}->[0]: $!\n";
96 0 exit 1;
97 }
98  
99 # parent
100  
101 # run callback, if needed
102 $args{parent}->( $pid )
103 47 ▶ if defined $args{parent};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"parent"} 4 43 47
104  
105 # set filehandles
106 47 my ( $select_w, $select_r ) = ( IO::Select->new, IO::Select->new );
107  
108 47 my %handles = (
109 $std_i->parent( $select_w ),
110 $std_o->parent( $select_r ),
111 $std_e->parent( $select_r ),
112 );
113  
114 # loop
115 47 ▶ while( $select_r->count or $select_w->count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($select_r->count or $select_w->count) 96 47 143
Condition100%3/3
$select_r->count or $select_w->count
l!l&&r!l&&!r
643247
MC/DC100%2/2
$select_r->count or $select_w->count
$select_r->count $select_w->count
Truth table100%3/3
A or B
A= $select_r->countB= $select_w->count
ABresult
1X1
011
000
116 96 my ( $readers, $writers ) = IO::Select->select( $select_r, $select_w );
117  
118 $handles{$_}->read
119 96 for @$readers;
120  
121 $handles{$_}->write
122 96 for @$writers;
123 }
124  
125 # use waitpid() to avoid signal handlers
126 47 my $rc = waitpid $pid, 0;
127 47 ▶ confess "waitpid: $!"
Branch: 1 branch
BranchTrueFalseTotal
if $rc == -1 0 47 47
128 if $rc == -1;
129  
130 47 return $?;
131 }
132  
133  
134 25 1
135 __END__
↑ Summary Hevy/Reader.pm »