blib/lib/IPC/Run/Fused/Win32.pm

filter: Statementstmt 21.6% 24 / 111 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 40.0% 6 / 15 Podpod 100% 1 / 1 totaltotal 14.6% 31 / 211 SCAR 64.2
CC
30
Cov
13%
_win32_command_find_invocant
182.0
_run_fused_job
56.0
_run_fused_coderef
56.0
CRAP 612.8
↑ Summary blib/lib/IPC/Run/Fused/POSIX.pm »
1  
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package IPC::Run::Fused::Win32;
6 BEGIN {
7 1 ▶ $IPC::Run::Fused::Win32::AUTHORITY = 'cpan:KENTNL';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 }
9 {
10 1 $IPC::Run::Fused::Win32::VERSION = '0.04000100';
11 }
12  
13 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: Implementation of IPC::Run::Fused for Win32
17  
18  
19 0 ▶sub _fail { goto \&IPC::Run::Fused::_fail }
Subroutine _fail: not called CC=1 SCAR=6.9
20  
21 BEGIN {
22  
23 1 ▶ Module::Runtime::require_module('Socket');
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 Socket->import();
26  
27 }
28  
29 sub run_fused {
30 0 ▶ my ( $read_handle, @params ) = @_;
Subroutine run_fused: not called CC=3 SCAR=24.8
Pod documented
31 0 ▶ if ( ref $params[0] and ref $params[0] eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params[0] and ref $params[0] eq "CODE") 0 0 0
Condition0%0/3
ref $params[0] and ref $params[0] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $params[0] and ref $params[0] eq "CODE"
ref $params[0] ref $params[0] eq "CODE"
Truth table0%0/3
A and B
A= ref $params[0]B= ref $params[0] eq "CODE"
ABresult
0X0
100
111
32 0 goto \&_run_fused_coderef;
33 }
34 0 goto \&_run_fused_job;
35 }
36  
37 sub _run_fused_job {
38 0 ▶ my ( $read_handle, @params ) = @_;
Subroutine _run_fused_job: not called CC=7 SCAR=40.3
39  
40 0 my $config = _run_fused_jobdecode(@params);
41  
42 0 Module::Runtime::require_module('File::Which');
43  
44 0 $config->{which} = File::Which::which( $config->{executable} );
45  
46 0 local $IPC::Run::Fused::FAIL_CONTEXT{which} = $config->{which};
47 0 local $IPC::Run::Fused::FAIL_CONTEXT{executable} = $config->{executable};
48 0 local $IPC::Run::Fused::FAIL_CONTEXT{command} = $config->{command};
49  
50 0 ▶ if ( not $config->{which} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"which"}) 0 0 0
51 0 _fail('Failed to resolve executable to path');
52 }
53  
54 0 Module::Runtime::require_module('Win32::Job');
55  
56 0 pipe( $_[0], my $writer );
57  
58 0 ▶ if ( my $pid = fork() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) 0 0 0
59 0 return $pid;
60 }
61  
62 0 my $job = Win32::Job->new();
63 $job->spawn(
64 $config->{which},
65 $config->{command},
66 {
67 0 ▶ stdout => $writer,
Branch: 1 branch
BranchTrueFalseTotal
$job->spawn($config->{"which"}, $config->{"command"}, {"stdout", $writer, "stderr", $writer}) or _fail("Could not spawn job") 0 0 0
68 stderr => $writer,
69 }
70 ) or _fail('Could not spawn job');
71 0 my $result = $job->run( -1, 0 );
72 0 ▶ if ( not $result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 0 0
73 0 my $status = $job->status();
74 0 ▶ if ( exists $status->{exitcode} and $status->{exitcode} == 293 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $status->{"exitcode"} and $status->{"exitcode"} == 293) 0 0 0
Condition0%0/3
exists $status->{"exitcode"} and $status->{"exitcode"} == 293
!ll&&!rl&&r
000
MC/DC0%0/2
exists $status->{"exitcode"} and $status->{"exitcode"} == 293
exists $status->{"exitcode"} $status->{"exitcode"} == 293
Truth table0%0/3
A and B
A= exists $status->{"exitcode"}B= $status->{"exitcode"} == 293
ABresult
0X0
100
111
75 0 _fail('Process used more than allotted time');
76 }
77 0 _fail( 'Child process terminated with exit code' . $status->{exitcode} );
78 }
79 0 exit;
80 }
81  
82 sub _run_fused_jobdecode {
83 0 ▶ my (@params) = @_;
Subroutine _run_fused_jobdecode: not called CC=3 SCAR=24.8
84  
85 0 ▶ if ( ref $params[0] and ref $params[0] eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params[0] and ref $params[0] eq "SCALAR") 0 0 0
Condition0%0/3
ref $params[0] and ref $params[0] eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $params[0] and ref $params[0] eq "SCALAR"
ref $params[0] ref $params[0] eq "SCALAR"
Truth table0%0/3
A and B
A= ref $params[0]B= ref $params[0] eq "SCALAR"
ABresult
0X0
100
111
86 0 my $command = ${ $params[0] };
87 0 $command =~ s/^\s*//;
88 return {
89 0 command => $command,
90 executable => _win32_command_find_invocant($command),
91 };
92 }
93 return {
94 0 executable => $params[0],
95 command => _win32_escape_command(@params),
96 };
97 }
98  
99 sub _run_fused_coderef {
100 0 ▶ my ( $read_handle, $code ) = @_;
Subroutine _run_fused_coderef: not called CC=7 SCAR=40.3
101 0 my ( $reader, $writer );
102  
103 0 ▶ socketpair( $reader, $writer, AF_UNIX, SOCK_STREAM, PF_UNSPEC ), and shutdown( $reader, 1 ), and shutdown( $writer, 0 ),
Branch: 1 branch
BranchTrueFalseTotal
socketpair $reader, $writer, 1, 1, 0 and shutdown $reader, 1 and shutdown $writer, 0 or _fail("creating socketpair") 0 0 0
Condition0%0/6
socketpair $reader, $writer, 1, 1, 0 and shutdown $reader, 1 and shutdown $writer, 0
!ll&&!rl&&r
000
socketpair $reader, $writer, 1, 1, 0 and shutdown $reader, 1
!ll&&!rl&&r
000
MC/DC0%0/3
socketpair $reader, $writer, 1, 1, 0 and shutdown $reader, 1 and shutdown $writer, 0
socketpair $reader, $writer, 1, 1, 0 shutdown $reader, 1 shutdown $writer, 0
Truth table0%0/4
A and B and C
A= socketpair $reader, $writer, 1, 1, 0B= shutdown $reader, 1C= shutdown $writer, 0
ABCresult
0XX0
10X0
1100
1111
104 or _fail("creating socketpair");
105  
106 0 ▶ if ( my $pid = fork() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) 0 0 0
107 0 $_[0] = $reader;
108 0 return $pid;
109 }
110  
111 0 close *STDERR;
112 0 close *STDOUT;
113 0 ▶ open *STDOUT, '>>&=', $writer or _fail('Assigning to STDOUT');
Branch: 1 branch
BranchTrueFalseTotal
open *STDOUT, ">>&=", $writer or _fail("Assigning to STDOUT") 0 0 0
114 0 ▶ open *STDERR, '>>&=', $writer or _fail('Assigning to STDERR');
Branch: 1 branch
BranchTrueFalseTotal
open *STDERR, ">>&=", $writer or _fail("Assigning to STDERR") 0 0 0
115 0 $code->();
116 0 exit;
117  
118 }
119  
120 1 our $BACKSLASH = chr(92);
121 1 our $DBLBACKSLASH = $BACKSLASH x 2;
122 1 our $DOS_SPECIAL_CHARS = {
123 chr(92) => [ 'backslash ', $BACKSLASH x 2 ],
124 chr(34) => [ 'double-quotes', $BACKSLASH . chr(34) ],
125  
126 #chr(60) => ['open angle bracket', $backslash . chr(60)],
127 #chr(62) => ['close angle bracket', $backslash . chr(62)],
128 };
129 our $DOS_REV_CHARS = {
130 2 map { ( $DOS_SPECIAL_CHARS->{$_}->[1], [ $DOS_SPECIAL_CHARS->{$_}->[0], $_ ] ) }
131 1 keys %{$DOS_SPECIAL_CHARS}
132 };
133  
134 sub _win32_escape_command_char {
135 0 ▶ return $_[0] unless exists $DOS_SPECIAL_CHARS->{ $_[0] };
Subroutine _win32_escape_command_char: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$IPC::Run::Fused::Win32::DOS_SPECIAL_CHARS{$_[0]} 0 0 0
136 0 return $DOS_SPECIAL_CHARS->{ $_[0] }->[1];
137 }
138  
139 sub _win32_escape_command_token {
140 0 ▶ my $chars = join q{}, map { _win32_escape_command_char($_) } split //, shift;
Subroutine _win32_escape_command_token: not called CC=1 SCAR=6.9
141 0 return qq{"$chars"};
142 }
143  
144 sub _win32_escape_command {
145 0 ▶ return join q{ }, map { _win32_escape_command_token($_) } @_;
Subroutine _win32_escape_command: not called CC=1 SCAR=6.9
146 }
147  
148 sub _win32_command_find_invocant {
149 0 ▶ my ($command) = "$_[0]";
Subroutine _win32_command_find_invocant: not called CC=13 SCAR=52.0
150 0 my $first = "";
151 0 my @chars = split //, $command;
152 0 my $inquote;
153  
154 0 ▶ while (@chars) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chars) 0 0 0
155 0 my $char = $chars[0];
156 0 my $dchar = $chars[0] . $chars[1];
157  
158 0 ▶ if ( not $inquote and $char eq q{"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $inquote and $char eq "\"") 0 0 0
Condition0%0/3
not $inquote and $char eq "\""
!ll&&!rl&&r
000
MC/DC0%0/2
not $inquote and $char eq "\""
not $inquote $char eq "\""
Truth table0%0/3
not(A) and B
A= not $inquoteB= $char eq "\""
ABresult
0X0
100
111
159 0 $inquote = 1;
160 0 shift @chars;
161 0 next;
162 }
163 0 ▶ if ( $inquote and $char eq q{"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inquote and $char eq "\"") 0 0 0
Condition0%0/3
$inquote and $char eq "\""
!ll&&!rl&&r
000
MC/DC0%0/2
$inquote and $char eq "\""
$inquote $char eq "\""
Truth table0%0/3
A and B
A= $inquoteB= $char eq "\""
ABresult
0X0
100
111
164 0 $inquote = undef;
165 0 shift @chars;
166 0 next;
167 }
168 0 ▶ if ( exists $DOS_REV_CHARS->{$dchar} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $IPC::Run::Fused::Win32::DOS_REV_CHARS->{$dchar}) 0 0 0
169 0 $first .= $DOS_REV_CHARS->{$dchar}->[1];
170 0 shift @chars;
171 0 shift @chars;
172 0 next;
173 }
174 0 ▶ if ( $char eq q{ } and not $inquote ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq " " and not $inquote) 0 0 0
Condition0%0/3
$char eq " " and not $inquote
!ll&&!rl&&r
000
MC/DC0%0/2
$char eq " " and not $inquote
$char eq " " not $inquote
Truth table0%0/3
A and not(B)
A= $char eq " "B= not $inquote
ABresult
0X0
100
111
175 0 ▶ if ( not length $first ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $first) 0 0 0
176 0 shift @chars;
177 0 next;
178 }
179 0 return $first;
180 }
181 0 ▶ if ( $char eq q{ } and $inquote ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq " " and $inquote) 0 0 0
Condition0%0/3
$char eq " " and $inquote
!ll&&!rl&&r
000
MC/DC0%0/2
$char eq " " and $inquote
$char eq " " $inquote
Truth table0%0/3
A and B
A= $char eq " "B= $inquote
ABresult
0X0
100
111
182 0 $first .= $char;
183 0 shift @chars;
184 0 next;
185 }
186 0 $first .= $char;
187 0 shift @chars;
188 }
189 0 ▶ if ($inquote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inquote) 0 0 0
190 0 _fail('Could not parse command from commandline');
191 }
192 0 return $first;
193 }
194  
195 1 1;
196  
197 __END__
↑ Summary blib/lib/IPC/Run/Fused/POSIX.pm »