blib/lib/IPC/Run/Debug.pm

filter: Statementstmt 66.6% 56 / 84 Branchbran 26.7% 15 / 56 Conditioncond 17.6% 6 / 34 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 72.7% 16 / 22 Podpod n/a totaltotal 43.6% 93 / 213 CC 39 SCAR 30.2
CC
39
Cov
44%
_debug_desc_fd
45.2
_debugging_level
33.1
_debug
27.7
CRAP 20.6
« blib/lib/IPC/Run/Win32IO.pm ↑ Summary blib/lib/IPC/Run/IO.pm »
1 package IPC::Run::Debug;
2  
3 =pod
4  
5 =head1 NAME
6  
7 IPC::Run::Debug - debugging routines for IPC::Run
8  
9 =head1 SYNOPSIS
10  
11 ##
12 ## Environment variable usage
13 ##
14 ## To force debugging off and shave a bit of CPU and memory
15 ## by compile-time optimizing away all debugging code in IPC::Run
16 ## (debug => ...) options to IPC::Run will be ignored.
17 export IPCRUNDEBUG=none
18  
19 ## To force debugging on (levels are from 0..10)
20 export IPCRUNDEBUG=basic
21  
22 ## Leave unset or set to "" to compile in debugging support and
23 ## allow runtime control of it using the debug option.
24  
25 =head1 DESCRIPTION
26  
27 Controls IPC::Run debugging. Debugging levels are now set by using words,
28 but the numbers shown are still supported for backwards compatibility:
29  
30 0 none disabled (special, see below)
31 1 basic what's running
32 2 data what's being sent/received
33 3 details what's going on in more detail
34 4 gory way too much detail for most uses
35 10 all use this when submitting bug reports
36 noopts optimizations forbidden due to inherited STDIN
37  
38 The C<none> level is special when the environment variable IPCRUNDEBUG
39 is set to this the first time IPC::Run::Debug is loaded: it prevents
40 the debugging code from being compiled in to the remaining IPC::Run modules,
41 saving a bit of cpu.
42  
43 To do this in a script, here's a way that allows it to be overridden:
44  
45 BEGIN {
46 unless ( defined $ENV{IPCRUNDEBUG} ) {
47 eval 'local $ENV{IPCRUNDEBUG} = "none"; require IPC::Run::Debug"'
48 or die $@;
49 }
50 }
51  
52 This should force IPC::Run to not be debuggable unless somebody sets
53 the IPCRUNDEBUG flag; modify this formula to grep @ARGV if need be:
54  
55 BEGIN {
56 unless ( grep /^--debug/, @ARGV ) {
57 eval 'local $ENV{IPCRUNDEBUG} = "none"; require IPC::Run::Debug"'
58 or die $@;
59 }
60  
61 Both of those are untested.
62  
63 =cut
64  
65 ## We use @EXPORT for the end user's convenience: there's only one function
66 ## exported, it's homonymous with the module, it's an unusual name, and
67 ## it can be suppressed by "use IPC::Run ();".
68  
69 127 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 127 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 127 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 127 ▶use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS};
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 BEGIN {
75 127 ▶ $VERSION = '20250715.0_01';
Subroutine BEGIN: called CC=1 SCAR=0.0
76 127 @ISA = qw( Exporter );
77 127 @EXPORT = qw(
78 _debug
79 _debug_desc_fd
80 _debugging
81 _debugging_data
82 _debugging_details
83 _debugging_gory_details
84 _debugging_not_optimized
85 _set_child_debug_name
86 );
87  
88 127 @EXPORT_OK = qw(
89 _debug_init
90 _debugging_level
91 _map_fds
92 );
93 127 %EXPORT_TAGS = (
94 default => \@EXPORT,
95 all => [ @EXPORT, @EXPORT_OK ],
96 );
97 }
98  
99 my $disable_debugging = defined $ENV{IPCRUNDEBUG}
100 && ( !$ENV{IPCRUNDEBUG}
101 127 ▶ || lc $ENV{IPCRUNDEBUG} eq "none" );
Condition16%1/6
defined $ENV{'IPCRUNDEBUG'} && (!$ENV{'IPCRUNDEBUG'} || lc $ENV{'IPCRUNDEBUG'} eq 'none')
!ll&&!rl&&r
12700
not $ENV{"IPCRUNDEBUG"} or lc $ENV{"IPCRUNDEBUG"} eq "none"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ENV{'IPCRUNDEBUG'} && (!$ENV{'IPCRUNDEBUG'} || lc $ENV{'IPCRUNDEBUG'} eq 'none')
defined $ENV{'IPCRUNDEBUG'} not $ENV{"IPCRUNDEBUG"} lc $ENV{"IPCRUNDEBUG"} eq "none"
Truth table0%0/4
A && not(B) or C
A= defined $ENV{'IPCRUNDEBUG'}B= not $ENV{"IPCRUNDEBUG"}C= lc $ENV{"IPCRUNDEBUG"} eq "none"
ABCresult
0XX0
1000
11X1
1011
102  
103 127 ▶eval( $disable_debugging ? <<'STUBS' : <<'SUBS' ) or die $@;
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine _debug: not called CC=9 SCAR=33.2
Subroutine _debug_desc_fd: not called CC=12 SCAR=38.1
Subroutine _debug_init: not called CC=1 SCAR=2.1
Subroutine _debugging: called CC=1 SCAR=2.1
Subroutine _debugging_atleast: called CC=3 SCAR=16.2
Subroutine _debugging_data: called CC=1 SCAR=2.1
Subroutine _debugging_details: called CC=1 SCAR=2.1
Subroutine _debugging_gory_details: not called CC=1 SCAR=2.1
Subroutine _debugging_level: called CC=10 SCAR=35.0
Subroutine _debugging_not_optimized: not called CC=2 SCAR=10.7
Subroutine _fd_is_open: called CC=3 SCAR=16.2
Subroutine _map_fds: called CC=5 SCAR=23.8
Subroutine _set_child_debug_name: not called CC=1 SCAR=2.1
Branch: 28 branches
BranchTrueFalseTotal
length pack('P', undef) == 4 ? : 0 127 127
defined &IPC::Run::_debug_fd ? : 0 0 0
defined $IPC::Run::cur_self && defined $IPC::Run::cur_self->{'ID'} ? : 0 0 0
defined $debug_name && length $debug_name ? : 0 0 0
&_debugging_details() ? : 0 0 0
length $debug_id ? : 0 0 0
defined $_ ? : 0 0 0
unless &_debugging() 0 0 0
if defined $op and UNIVERSAL::isa($op, "IO::Pty") 0 0 0
defined $op->{'FD'} ? : 0 0 0
$op->{'FD'} < 3 ? : 0 0 0
defined $op->{'KFD'} ? : 0 0 0
defined $kid ? : 0 0 0
$op->{'KFD'} < 3 ? : 0 0 0
defined $kid && defined $kid->{'DEBUG_FD'} && $op->{'KFD'} == $kid->{'DEBUG_FD'} ? : 0 0 0
$level >= $min_level ? : 0 87484 87484
if $IPC::Run::cur_self and ($IPC::Run::cur_self->{"debug"} || 0) >= $level 87277 207 87484
if (defined $ENV{"IPCRUNDEBUG"}) 0 87484 87484
if $v =~ /[a-zA-Z]/ 0 0 0
unless (defined $v) 0 0 0
if $v > $level 0 0 0
if (&Win32_MODE()) { } 0 145152 145152
if $in_use 15876 129276 145152
_fd_is_open($fd) ? : 15876 129276 145152
if ++$digit > 9 13608 131544 145152
unless $map =~ /\d/ 0 2268 2268
eval($disable_debugging ? "sub _map_fds() { \"\" }\nsub _debug {}\nsub _debug_desc_fd {}\nsub _debug_init {}\nsub _set_child_debug_name {}\nsub _debugging() { 0 }\nsub _debugging_level() { 0 }\nsub _debugging_data() { 0 }\nsub _debugging_details() { 0 }\nsub _debugging_gory_details() { 0 }\nsub _debugging_not_optimized() { 0 }\n\n1;\n" : "\nuse POSIX ();\nuse constant Win32_MODE => \$^O =~ /os2|Win32/i;\n\n# Replace Win32API::File::INVALID_HANDLE_VALUE, which does not match the C ABI\n# on 64-bit builds (https://github.com/chorny/Win32API-File/issues/13).\nuse constant C_ABI_INVALID_HANDLE_VALUE => length( pack 'P', undef ) == 4\n ? 0xffffffff\n : 0xffffffff << 32 | 0xffffffff;\n\nsub _fd_is_open {\n my (\$fd) = \@_;\n if (Win32_MODE) {\n # Many OS functions can crash on closed FDs. POSIX::close() can hang on\n # the read end of a pipe (https://github.com/Perl/perl5/issues/19963).\n # Borrow Gnulib's strategy.\n require Win32API::File;\n return Win32API::File::FdGetOsFHandle(\$fd) != C_ABI_INVALID_HANDLE_VALUE;\n }\n else {\n ## I'd like a quicker way (less user, cpu & especially sys and kernel\n ## calls) to detect open file descriptors. Let me know...\n ## Hmmm, could do a 0 length read and check for bad file descriptor...\n my \$test_fd = POSIX::dup( \$fd );\n my \$in_use = defined \$test_fd;\n POSIX::close \$test_fd if \$in_use;\n return \$in_use;\n }\n}\n\nsub _map_fds {\n my \$map = '';\n my \$digit = 0;\n my \$dummy;\n for my \$fd (0..63) {\n \$map .= _fd_is_open(\$fd) ? \$digit : '-';\n \$digit = 0 if ++\$digit > 9;\n }\n warn \"No fds open???\" unless \$map =~ /\\d/;\n \$map =~ s/(.{1,12})-*\$/\$1/;\n return \$map;\n}\n\nuse vars qw( \$parent_pid );\n\n\$parent_pid = \$\$;\n\n## TODO: move debugging to its own module and make it compile-time\n## optimizable.\n\n## Give kid process debugging nice names\nmy \$debug_name;\n\nsub _set_child_debug_name {\n \$debug_name = shift;\n}\n\n## There's a bit of hackery going on here.\n##\n## We want to have any code anywhere be able to emit\n## debugging statements without knowing what harness the code is\n## being called in/from, since we'd need to pass a harness around to\n## everything.\n##\n## Thus, \$cur_self was born.\n#\nmy %debug_levels = (\n none => 0,\n basic => 1,\n data => 2,\n details => 3,\n gore => 4,\n gory_details => 4,\n \"gory details\" => 4,\n gory => 4,\n gorydetails => 4,\n all => 10,\n notopt => 0,\n);\n\nmy \$warned;\n\nsub _debugging_level() {\n my \$level = 0;\n\n \$level = \$IPC::Run::cur_self->{debug} || 0\n if \$IPC::Run::cur_self\n && ( \$IPC::Run::cur_self->{debug} || 0 ) >= \$level;\n\n if ( defined \$ENV{IPCRUNDEBUG} ) {\n my \$v = \$ENV{IPCRUNDEBUG};\n \$v = \$debug_levels{lc \$v} if \$v =~ /[a-zA-Z]/;\n unless ( defined \$v ) {\n\t \$warned ||= warn \"Unknown debug level \$ENV{IPCRUNDEBUG}, assuming 'basic' (1)\\n\";\n\t \$v = 1;\n }\n \$level = \$v if \$v > \$level;\n }\n return \$level;\n}\n\nsub _debugging_atleast(\$) {\n my \$min_level = shift || 1;\n\n my \$level = _debugging_level;\n \n return \$level >= \$min_level ? \$level : 0;\n}\n\nsub _debugging() { _debugging_atleast 1 }\nsub _debugging_data() { _debugging_atleast 2 }\nsub _debugging_details() { _debugging_atleast 3 }\nsub _debugging_gory_details() { _debugging_atleast 4 }\nsub _debugging_not_optimized() { ( \$ENV{IPCRUNDEBUG} || \"\" ) eq \"notopt\" }\n\nsub _debug_init {\n ## This routine is called only in spawned children to fake out the\n ## debug routines so they'll emit debugging info.\n \$IPC::Run::cur_self = {};\n ( \$parent_pid,\n \$^T, \n \$IPC::Run::cur_self->{debug}, \n \$IPC::Run::cur_self->{DEBUG_FD}, \n \$debug_name \n ) = \@_;\n}\n\n\nsub _debug {\n# return unless _debugging || _debugging_not_optimized;\n\n my \$fd = defined &IPC::Run::_debug_fd\n ? IPC::Run::_debug_fd()\n : fileno STDERR;\n\n my \$s;\n my \$debug_id;\n \$debug_id = join( \n \" \",\n join(\n \"\",\n defined \$IPC::Run::cur_self && defined \$IPC::Run::cur_self->{ID}\n ? \"#\$IPC::Run::cur_self->{ID}\"\n : (),\n \"(\$\$)\",\n ),\n defined \$debug_name && length \$debug_name ? \$debug_name : (),\n );\n my \$prefix = join(\n \"\",\n \"IPC::Run\",\n sprintf( \" %04d\", time - \$^T ),\n ( _debugging_details ? ( \" \", _map_fds ) : () ),\n length \$debug_id ? ( \" [\", \$debug_id, \"]\" ) : (),\n \": \",\n );\n\n my \$msg = join( '', map defined \$_ ? \$_ : \"<undef>\", \@_ );\n chomp \$msg;\n \$msg =~ s{^}{\$prefix}gm;\n \$msg .= \"\\n\";\n POSIX::write( \$fd, \$msg, length \$msg );\n}\n\n\nmy \@fd_descs = ( 'stdin', 'stdout', 'stderr' );\n\nsub _debug_desc_fd {\n return unless _debugging;\n my \$text = shift;\n my \$op = pop;\n my \$kid = \$_[0];\n\nCarp::carp join \" \", caller(0), \$text, \$op if defined \$op && UNIVERSAL::isa( \$op, \"IO::Pty\" );\n\n _debug(\n \$text,\n ' ',\n ( defined \$op->{FD}\n ? \$op->{FD} < 3\n ? ( \$fd_descs[\$op->{FD}] )\n : ( 'fd ', \$op->{FD} )\n : \$op->{FD}\n ),\n ( defined \$op->{KFD}\n ? (\n ' (kid',\n ( defined \$kid ? ( ' ', \$kid->{NUM}, ) : () ),\n \"'s \",\n ( \$op->{KFD} < 3\n ? \$fd_descs[\$op->{KFD}]\n : defined \$kid\n && defined \$kid->{DEBUG_FD}\n && \$op->{KFD} == \$kid->{DEBUG_FD}\n ? ( 'debug (', \$op->{KFD}, ')' )\n : ( 'fd ', \$op->{KFD} )\n ),\n ')',\n )\n : ()\n ),\n );\n}\n\n1;\n\n") or die $@ 0 127 127
$disable_debugging ? : 0 127 127
Condition17%5/28
defined $IPC::Run::cur_self and defined $IPC::Run::cur_self->{"ID"}
!ll&&!rl&&r
000
defined $debug_name and length $debug_name
!ll&&!rl&&r
000
defined $op and UNIVERSAL::isa($op, "IO::Pty")
!ll&&!rl&&r
000
defined $kid and defined $kid->{"DEBUG_FD"} and $op->{"KFD"} == $kid->{"DEBUG_FD"}
!ll&&!rl&&r
000
defined $kid and defined $kid->{"DEBUG_FD"}
!ll&&!rl&&r
000
shift() || 1
l!l
874840
$IPC::Run::cur_self and ($IPC::Run::cur_self->{"debug"} || 0) >= $level
!ll&&!rl&&r
207087277
$IPC::Run::cur_self->{'debug'} || 0
l!l
087277
$IPC::Run::cur_self->{'debug'} || 0
l!l
087277
$warned ||= warn(qq[Unknown debug level $ENV{"IPCRUNDEBUG"}, assuming 'basic' (1)\n])
l!l
00
$ENV{'IPCRUNDEBUG'} || ''
l!l
00
MC/DC0%0/2
defined $IPC::Run::cur_self and defined $IPC::Run::cur_self->{"ID"}
defined $IPC::Run::cur_self defined $IPC::Run::cur_self->{"ID"}
MC/DC0%0/2
defined $debug_name and length $debug_name
defined $debug_name length $debug_name
MC/DC0%0/2
defined $op and UNIVERSAL::isa($op, "IO::Pty")
defined $op UNIVERSAL::isa($op, "IO::Pty")
MC/DC0%0/3
defined $kid and defined $kid->{"DEBUG_FD"} and $op->{"KFD"} == $kid->{"DEBUG_FD"}
defined $kid defined $kid->{"DEBUG_FD"} $op->{"KFD"} == $kid->{"DEBUG_FD"}
MC/DC0%0/1
shift() || 1
shift()
MC/DC0%0/2
$IPC::Run::cur_self and ($IPC::Run::cur_self->{"debug"} || 0) >= $level
$IPC::Run::cur_self $IPC::Run::cur_self->{'debug'}
MC/DC0%0/1
$warned ||= warn(qq[Unknown debug level $ENV{"IPCRUNDEBUG"}, assuming 'basic' (1)\n])
$warned
MC/DC0%0/1
$ENV{'IPCRUNDEBUG'} || ''
$ENV{'IPCRUNDEBUG'}
Truth table0%0/3
A and B
A= defined $IPC::Run::cur_selfB= defined $IPC::Run::cur_self->{"ID"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $debug_nameB= length $debug_name
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $opB= UNIVERSAL::isa($op, "IO::Pty")
ABresult
0X0
100
111
Truth table0%0/4
A and B and C
A= defined $kidB= defined $kid->{"DEBUG_FD"}C= $op->{"KFD"} == $kid->{"DEBUG_FD"}
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= shift()
Aresult
11
00
Truth table33%1/3
A and B
A= $IPC::Run::cur_selfB= $IPC::Run::cur_self->{'debug'}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $warned
Aresult
11
00
Truth table0%0/2
A
A= $ENV{'IPCRUNDEBUG'}
Aresult
11
00
104 sub _map_fds() { "" }
105 sub _debug {}
106 sub _debug_desc_fd {}
107 sub _debug_init {}
108 sub _set_child_debug_name {}
109 sub _debugging() { 0 }
110 sub _debugging_level() { 0 }
111 sub _debugging_data() { 0 }
112 sub _debugging_details() { 0 }
113 sub _debugging_gory_details() { 0 }
114 sub _debugging_not_optimized() { 0 }
115  
116 1;
117 STUBS
118  
119 use POSIX ();
120 use constant Win32_MODE => $^O =~ /os2|Win32/i;
121  
122 # Replace Win32API::File::INVALID_HANDLE_VALUE, which does not match the C ABI
123 # on 64-bit builds (https://github.com/chorny/Win32API-File/issues/13).
124 use constant C_ABI_INVALID_HANDLE_VALUE => length( pack 'P', undef ) == 4
125 ? 0xffffffff
126 : 0xffffffff << 32 | 0xffffffff;
127  
128 sub _fd_is_open {
129 my ($fd) = @_;
130 if (Win32_MODE) {
131 # Many OS functions can crash on closed FDs. POSIX::close() can hang on
132 # the read end of a pipe (https://github.com/Perl/perl5/issues/19963).
133 # Borrow Gnulib's strategy.
134 require Win32API::File;
135 return Win32API::File::FdGetOsFHandle($fd) != C_ABI_INVALID_HANDLE_VALUE;
136 }
137 else {
138 ## I'd like a quicker way (less user, cpu & especially sys and kernel
139 ## calls) to detect open file descriptors. Let me know...
140 ## Hmmm, could do a 0 length read and check for bad file descriptor...
141 my $test_fd = POSIX::dup( $fd );
142 my $in_use = defined $test_fd;
143 POSIX::close $test_fd if $in_use;
144 return $in_use;
145 }
146 }
147  
148 sub _map_fds {
149 my $map = '';
150 my $digit = 0;
151 my $dummy;
152 for my $fd (0..63) {
153 $map .= _fd_is_open($fd) ? $digit : '-';
154 $digit = 0 if ++$digit > 9;
155 }
156 warn "No fds open???" unless $map =~ /\d/;
157 $map =~ s/(.{1,12})-*$/$1/;
158 return $map;
159 }
160  
161 use vars qw( $parent_pid );
162  
163 $parent_pid = $$;
164  
165 ## TODO: move debugging to its own module and make it compile-time
166 ## optimizable.
167  
168 ## Give kid process debugging nice names
169 my $debug_name;
170  
171 sub _set_child_debug_name {
172 $debug_name = shift;
173 }
174  
175 ## There's a bit of hackery going on here.
176 ##
177 ## We want to have any code anywhere be able to emit
178 ## debugging statements without knowing what harness the code is
179 ## being called in/from, since we'd need to pass a harness around to
180 ## everything.
181 ##
182 ## Thus, $cur_self was born.
183 #
184 my %debug_levels = (
185 none => 0,
186 basic => 1,
187 data => 2,
188 details => 3,
189 gore => 4,
190 gory_details => 4,
191 "gory details" => 4,
192 gory => 4,
193 gorydetails => 4,
194 all => 10,
195 notopt => 0,
196 );
197  
198 my $warned;
199  
200 sub _debugging_level() {
201 my $level = 0;
202  
203 $level = $IPC::Run::cur_self->{debug} || 0
204 if $IPC::Run::cur_self
205 && ( $IPC::Run::cur_self->{debug} || 0 ) >= $level;
206  
207 if ( defined $ENV{IPCRUNDEBUG} ) {
208 my $v = $ENV{IPCRUNDEBUG};
209 $v = $debug_levels{lc $v} if $v =~ /[a-zA-Z]/;
210 unless ( defined $v ) {
211 $warned ||= warn "Unknown debug level $ENV{IPCRUNDEBUG}, assuming 'basic' (1)\n";
212 $v = 1;
213 }
214 $level = $v if $v > $level;
215 }
216 return $level;
217 }
218  
219 sub _debugging_atleast($) {
220 my $min_level = shift || 1;
221  
222 my $level = _debugging_level;
223
224 return $level >= $min_level ? $level : 0;
225 }
226  
227 sub _debugging() { _debugging_atleast 1 }
228 sub _debugging_data() { _debugging_atleast 2 }
229 sub _debugging_details() { _debugging_atleast 3 }
230 sub _debugging_gory_details() { _debugging_atleast 4 }
231 sub _debugging_not_optimized() { ( $ENV{IPCRUNDEBUG} || "" ) eq "notopt" }
232  
233 sub _debug_init {
234 ## This routine is called only in spawned children to fake out the
235 ## debug routines so they'll emit debugging info.
236 $IPC::Run::cur_self = {};
237 ( $parent_pid,
238 $^T,
239 $IPC::Run::cur_self->{debug},
240 $IPC::Run::cur_self->{DEBUG_FD},
241 $debug_name
242 ) = @_;
243 }
244  
245  
246 sub _debug {
247 # return unless _debugging || _debugging_not_optimized;
248  
249 my $fd = defined &IPC::Run::_debug_fd
250 ? IPC::Run::_debug_fd()
251 : fileno STDERR;
252  
253 my $s;
254 my $debug_id;
255 $debug_id = join(
256 " ",
257 join(
258 "",
259 defined $IPC::Run::cur_self && defined $IPC::Run::cur_self->{ID}
260 ? "#$IPC::Run::cur_self->{ID}"
261 : (),
262 "($$)",
263 ),
264 defined $debug_name && length $debug_name ? $debug_name : (),
265 );
266 my $prefix = join(
267 "",
268 "IPC::Run",
269 sprintf( " %04d", time - $^T ),
270 ( _debugging_details ? ( " ", _map_fds ) : () ),
271 length $debug_id ? ( " [", $debug_id, "]" ) : (),
272 ": ",
273 );
274  
275 my $msg = join( '', map defined $_ ? $_ : "<undef>", @_ );
276 chomp $msg;
277 $msg =~ s{^}{$prefix}gm;
278 $msg .= "\n";
279 POSIX::write( $fd, $msg, length $msg );
280 }
281  
282  
283 my @fd_descs = ( 'stdin', 'stdout', 'stderr' );
284  
285 sub _debug_desc_fd {
286 return unless _debugging;
287 my $text = shift;
288 my $op = pop;
289 my $kid = $_[0];
290  
291 Carp::carp join " ", caller(0), $text, $op if defined $op && UNIVERSAL::isa( $op, "IO::Pty" );
292  
293 _debug(
294 $text,
295 ' ',
296 ( defined $op->{FD}
297 ? $op->{FD} < 3
298 ? ( $fd_descs[$op->{FD}] )
299 : ( 'fd ', $op->{FD} )
300 : $op->{FD}
301 ),
302 ( defined $op->{KFD}
303 ? (
304 ' (kid',
305 ( defined $kid ? ( ' ', $kid->{NUM}, ) : () ),
306 "'s ",
307 ( $op->{KFD} < 3
308 ? $fd_descs[$op->{KFD}]
309 : defined $kid
310 && defined $kid->{DEBUG_FD}
311 && $op->{KFD} == $kid->{DEBUG_FD}
312 ? ( 'debug (', $op->{KFD}, ')' )
313 : ( 'fd ', $op->{KFD} )
314 ),
315 ')',
316 )
317 : ()
318 ),
319 );
320 }
321  
322 1;
323  
324 SUBS
325  
326 =pod
327  
328 =head1 AUTHOR
329  
330 Barrie Slaymaker <barries@slaysys.com>, with numerous suggestions by p5p.
331  
332 =cut
« blib/lib/IPC/Run/Win32IO.pm ↑ Summary blib/lib/IPC/Run/IO.pm »