| 1 | package IPC::Run::IO; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | IPC::Run::IO -- I/O channels for IPC::Run. | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | B<NOT IMPLEMENTED YET ON Win32! Win32 does not allow select() on | ||||||||||||||||||||||||||||||||
| 10 | normal file descriptors; IPC::RUN::IO needs to use IPC::Run::Win32Helper | ||||||||||||||||||||||||||||||||
| 11 | to do this.> | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | use IPC::Run qw( io ); | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | ## The sense of '>' and '<' is opposite of perl's open(), | ||||||||||||||||||||||||||||||||
| 16 | ## but agrees with IPC::Run. | ||||||||||||||||||||||||||||||||
| 17 | $io = io( "filename", '>', \$recv ); | ||||||||||||||||||||||||||||||||
| 18 | $io = io( "filename", 'r', \$recv ); | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | ## Append to $recv: | ||||||||||||||||||||||||||||||||
| 21 | $io = io( "filename", '>>', \$recv ); | ||||||||||||||||||||||||||||||||
| 22 | $io = io( "filename", 'ra', \$recv ); | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | $io = io( "filename", '<', \$send ); | ||||||||||||||||||||||||||||||||
| 25 | $io = io( "filename", 'w', \$send ); | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | $io = io( "filename", '<<', \$send ); | ||||||||||||||||||||||||||||||||
| 28 | $io = io( "filename", 'wa', \$send ); | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | ## Handles / IO objects that the caller opens: | ||||||||||||||||||||||||||||||||
| 31 | $io = io( \*HANDLE, '<', \$send ); | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | $f = IO::Handle->new( ... ); # Any subclass of IO::Handle | ||||||||||||||||||||||||||||||||
| 34 | $io = io( $f, '<', \$send ); | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | require IPC::Run::IO; | ||||||||||||||||||||||||||||||||
| 37 | $io = IPC::Run::IO->new( ... ); | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | ## Then run(), harness(), or start(): | ||||||||||||||||||||||||||||||||
| 40 | run $io, ...; | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | ## You can, of course, use io() or IPC::Run::IO->new() as an | ||||||||||||||||||||||||||||||||
| 43 | ## argument to run(), harness, or start(): | ||||||||||||||||||||||||||||||||
| 44 | run io( ... ); | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | This class and module allows filehandles and filenames to be harnessed for | ||||||||||||||||||||||||||||||||
| 49 | I/O when used IPC::Run, independent of anything else IPC::Run is doing | ||||||||||||||||||||||||||||||||
| 50 | (except that errors & exceptions can affect all things that IPC::Run is | ||||||||||||||||||||||||||||||||
| 51 | doing). | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | =head1 SUBCLASSING | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | INCOMPATIBLE CHANGE: due to the awkwardness introduced in ripping pseudohashes | ||||||||||||||||||||||||||||||||
| 56 | out of Perl, this class I<no longer> uses the fields pragma. | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | ## This class is also used internally by IPC::Run in a very intimate way, | ||||||||||||||||||||||||||||||||
| 61 | ## since this is a partial factoring of code from IPC::Run plus some code | ||||||||||||||||||||||||||||||||
| 62 | ## needed to do standalone channels. This factoring process will continue | ||||||||||||||||||||||||||||||||
| 63 | ## at some point. Don't know how far how fast. | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 127 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 66 | 127 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 67 | 127 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 68 | 127 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 69 | 127 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 127 | ▶ | use IPC::Run::Debug; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 72 | 127 | ▶ | use IPC::Run qw( Win32_MODE ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 127 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | BEGIN { | ||||||||||||||||||||||||||||||||
| 77 | 127 | ▶ | $VERSION = '20250715.0_01'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=5 SCAR=27.4
| |||||||||||||||||||||||||||||||||
| 78 | 127 | ▶ | if (Win32_MODE) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | eval "use IPC::Run::Win32Helper; require IPC::Run::Win32IO; 1" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
eval "use IPC::Run::Win32Helper; require IPC::Run::Win32IO; 1" or $@ and die
$@ and die
MC/DC0%0/2
eval "use IPC::Run::Win32Helper; require IPC::Run::Win32IO; 1" or $@ and die
eval "use IPC::Run::Win32Helper; require IPC::Run::Win32IO; 1"
$@
Truth table0%0/3
A or B
A= eval "use IPC::Run::Win32Helper; require IPC::Run::Win32IO; 1"B= $@
| |||||||||||||||||||||||||||||||||
| 80 | or ( $@ && die ) | ||||||||||||||||||||||||||||||||
| 81 | or die "$!"; | ||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | sub _empty($); | ||||||||||||||||||||||||||||||||
| 86 | 127 | *_empty = \&IPC::Run::_empty; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =head1 SUBROUTINES | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | =over 4 | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =item new | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | I think it takes >> or << along with some other data. | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | TODO: Needs more thorough documentation. Patches welcome. | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | sub new { | ||||||||||||||||||||||||||||||||
| 101 | 7 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 102 | 7 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 7 | my ( $external, $type, $internal ) = ( shift, shift, pop ); | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | croak "$class: '$_' is not a valid I/O operator" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | unless $type =~ /^(?:<<?|>>?)$/; | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 7 | my IPC::Run::IO $self = $class->_new_internal( $type, undef, undef, $internal, undef, @_ ); | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 7 | ▶ | if ( !ref $external ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 112 | 7 | $self->{FILENAME} = $external; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | ▶ | elsif ( ref $external eq 'GLOB' || UNIVERSAL::isa( $external, 'IO::Handle' ) ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $external eq "GLOB" or UNIVERSAL::isa($external, "IO::Handle")
MC/DC0%0/2
ref $external eq "GLOB" or UNIVERSAL::isa($external, "IO::Handle")
ref $external eq "GLOB"
UNIVERSAL::isa($external, "IO::Handle")
Truth table0%0/3
A or B
A= ref $external eq "GLOB"B= UNIVERSAL::isa($external, "IO::Handle")
| |||||||||||||||||||||||||||||||||
| 115 | 0 | $self->{HANDLE} = $external; | |||||||||||||||||||||||||||||||
| 116 | 0 | $self->{DONT_CLOSE} = 1; | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||
| 119 | 0 | croak "$class: cannot accept " . ref($external) . " to do I/O with"; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 7 | return $self; | |||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | ## IPC::Run uses this ctor, since it preparses things and needs more | ||||||||||||||||||||||||||||||||
| 126 | ## smarts. | ||||||||||||||||||||||||||||||||
| 127 | sub _new_internal { | ||||||||||||||||||||||||||||||||
| 128 | 2624 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_new_internal: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||
| 129 | 2624 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 2624 | ▶ | $class = "IPC::Run::Win32IO" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&Win32_MODE() and $class eq "IPC::Run::IO"
MC/DC0%0/2
&Win32_MODE() and $class eq "IPC::Run::IO"
&Win32_MODE()
$class eq "IPC::Run::IO"
Truth table33%1/3
A and B
A= &Win32_MODE()B= $class eq "IPC::Run::IO"
| |||||||||||||||||||||||||||||||||
| 132 | if Win32_MODE && $class eq "IPC::Run::IO"; | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 2624 | my IPC::Run::IO $self; | |||||||||||||||||||||||||||||||
| 135 | 2624 | $self = bless {}, $class; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 2624 | my ( $type, $kfd, $pty_id, $internal, $binmode, @filters ) = @_; | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | # Older perls (<=5.00503, at least) don't do list assign to | ||||||||||||||||||||||||||||||||
| 140 | # pseudo-hashes well. | ||||||||||||||||||||||||||||||||
| 141 | 2624 | $self->{TYPE} = $type; | |||||||||||||||||||||||||||||||
| 142 | 2624 | $self->{KFD} = $kfd; | |||||||||||||||||||||||||||||||
| 143 | 2624 | $self->{PTY_ID} = $pty_id; | |||||||||||||||||||||||||||||||
| 144 | 2624 | $self->binmode($binmode); | |||||||||||||||||||||||||||||||
| 145 | 2624 | $self->{FILTERS} = [@filters]; | |||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | ## Add an adapter to the end of the filter chain (which is usually just the | ||||||||||||||||||||||||||||||||
| 148 | ## read/writer sub pushed by IPC::Run) to the DEST or SOURCE, if need be. | ||||||||||||||||||||||||||||||||
| 149 | 2624 | ▶ | if ( $self->op =~ />/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | 1712 | ▶ | croak "'$_' missing a destination" if _empty $internal; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | 1712 | $self->{DEST} = $internal; | |||||||||||||||||||||||||||||||
| 152 | 1712 | ▶ | if ( UNIVERSAL::isa( $self->{DEST}, 'CODE' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | ## Put a filter on the end of the filter chain to pass the | ||||||||||||||||||||||||||||||||
| 154 | ## output on to the CODE ref. For SCALAR refs, the last | ||||||||||||||||||||||||||||||||
| 155 | ## filter in the chain writes directly to the scalar itself. See | ||||||||||||||||||||||||||||||||
| 156 | ## _init_filters(). For CODE refs, however, we need to adapt from | ||||||||||||||||||||||||||||||||
| 157 | ## the SCALAR to calling the CODE. | ||||||||||||||||||||||||||||||||
| 158 | unshift( | ||||||||||||||||||||||||||||||||
| 159 | 98 | @{ $self->{FILTERS} }, | |||||||||||||||||||||||||||||||
| 160 | sub { | ||||||||||||||||||||||||||||||||
| 161 | 182 | ▶ | my ($in_ref) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 182 | ▶ | return IPC::Run::input_avail() && do { | ||||||||||||||||||||||||||||||
|
Condition66%2/3
&IPC::Run::input_avail() && do {
$self->{'DEST'}->($$in_ref);
$$in_ref = '';
1
}
MC/DC50%1/2
&IPC::Run::input_avail() && do {
$self->{'DEST'}->($$in_ref);
$$in_ref = '';
1
}
&IPC::Run::input_avail()
do {
$self->{'DEST'}->($$in_ref);
$$in_ref = '';
1
}
Truth table66%2/3
A && B
A= &IPC::Run::input_avail()B= do {
$self->{'DEST'}->($$in_ref);
$$in_ref = '';
1
}
| |||||||||||||||||||||||||||||||||
| 164 | 90 | $self->{DEST}->($$in_ref); | |||||||||||||||||||||||||||||||
| 165 | 90 | $$in_ref = ''; | |||||||||||||||||||||||||||||||
| 166 | 90 | 1; | |||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | 98 | ); | |||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||||||||||||||
| 173 | 912 | ▶ | croak "'$_' missing a source" if _empty $internal; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | 912 | $self->{SOURCE} = $internal; | |||||||||||||||||||||||||||||||
| 175 | 912 | ▶ | if ( UNIVERSAL::isa( $internal, 'CODE' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 176 | push( | ||||||||||||||||||||||||||||||||
| 177 | 68 | @{ $self->{FILTERS} }, | |||||||||||||||||||||||||||||||
| 178 | sub { | ||||||||||||||||||||||||||||||||
| 179 | 82 | ▶ | my ( $in_ref, $out_ref ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 180 | 82 | ▶ | return 0 if length $$out_ref; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | return undef | ||||||||||||||||||||||||||||||||
| 183 | 82 | ▶ | if $self->{SOURCE_EMPTY}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 82 | my $in = $internal->(); | |||||||||||||||||||||||||||||||
| 186 | 82 | ▶ | unless ( defined $in ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 46 | $self->{SOURCE_EMPTY} = 1; | |||||||||||||||||||||||||||||||
| 188 | 46 | return undef; | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | 36 | ▶ | return 0 unless length $in; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | 29 | $$out_ref = $in; | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | 29 | return 1; | |||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||
| 195 | 68 | ); | |||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||
| 197 | elsif ( UNIVERSAL::isa( $internal, 'SCALAR' ) ) { | ||||||||||||||||||||||||||||||||
| 198 | push( | ||||||||||||||||||||||||||||||||
| 199 | 561 | @{ $self->{FILTERS} }, | |||||||||||||||||||||||||||||||
| 200 | sub { | ||||||||||||||||||||||||||||||||
| 201 | 2055 | ▶ | my ( $in_ref, $out_ref ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 202 | 2055 | ▶ | return 0 if length $$out_ref; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | ## pump() clears auto_close_ins, finish() sets it. | ||||||||||||||||||||||||||||||||
| 205 | return $self->{HARNESS}->{auto_close_ins} ? undef : 0 | ||||||||||||||||||||||||||||||||
| 206 | 2055 | ▶ | if IPC::Run::_empty ${ $self->{SOURCE} } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 207 | 2055 | ▶ | || $self->{SOURCE_EMPTY}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&IPC::Run::_empty(${$$self{"SOURCE"};}) or $self->{"SOURCE_EMPTY"}
MC/DC100%2/2
&IPC::Run::_empty(${$$self{"SOURCE"};}) or $self->{"SOURCE_EMPTY"}
&IPC::Run::_empty(${$$self{"SOURCE"};})
$self->{"SOURCE_EMPTY"}
Truth table100%3/3
A or B
A= &IPC::Run::_empty(${$$self{"SOURCE"};})B= $self->{"SOURCE_EMPTY"}
| |||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | 366 | $$out_ref = $$internal; | |||||||||||||||||||||||||||||||
| 210 | 109 | eval { $$internal = '' } | |||||||||||||||||||||||||||||||
| 211 | 366 | ▶ | if $self->{HARNESS}->{clear_ins}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 366 | $self->{SOURCE_EMPTY} = $self->{HARNESS}->{auto_close_ins}; | |||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 366 | return 1; | |||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||
| 217 | 561 | ); | |||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | 2624 | return $self; | |||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | =item filename | ||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | Gets/sets the filename. Returns the value after the name change, if | ||||||||||||||||||||||||||||||||
| 227 | any. | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | sub filename { | ||||||||||||||||||||||||||||||||
| 232 | 4 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
filename: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 233 | 4 | ▶ | $self->{FILENAME} = shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 234 | 4 | return $self->{FILENAME}; | |||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | =item init | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | Does initialization required before this can be run. This includes open()ing | ||||||||||||||||||||||||||||||||
| 240 | the file, if necessary, and clearing the destination scalar if necessary. | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | =cut | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | sub init { | ||||||||||||||||||||||||||||||||
| 245 | 2 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | 2 | $self->{SOURCE_EMPTY} = 0; | |||||||||||||||||||||||||||||||
| 248 | 1 | ${ $self->{DEST} } = '' | |||||||||||||||||||||||||||||||
| 249 | 2 | ▶ | if $self->mode =~ /r/ && ref $self->{DEST} eq 'SCALAR'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->mode =~ /r/ and ref $self->{"DEST"} eq "SCALAR"
MC/DC50%1/2
$self->mode =~ /r/ and ref $self->{"DEST"} eq "SCALAR"
$self->mode =~ /r/
ref $self->{"DEST"} eq "SCALAR"
Truth table66%2/3
A and B
A= $self->mode =~ /r/B= ref $self->{"DEST"} eq "SCALAR"
| |||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 2 | ▶ | $self->open if defined $self->filename; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 252 | 2 | $self->{FD} = $self->fileno; | |||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | if ( !$self->{FILTERS} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 255 | 0 | $self->{FBUFS} = undef; | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | else { | ||||||||||||||||||||||||||||||||
| 258 | 2 | @{ $self->{FBUFS} } = map { | |||||||||||||||||||||||||||||||
| 259 | 3 | my $s = ""; | |||||||||||||||||||||||||||||||
| 260 | 3 | \$s; | |||||||||||||||||||||||||||||||
| 261 | 2 | } ( @{ $self->{FILTERS} }, '' ); | |||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | $self->{FBUFS}->[0] = $self->{DEST} | ||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | if $self->{DEST} && ref $self->{DEST} eq 'SCALAR'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"DEST"} and ref $self->{"DEST"} eq "SCALAR"
MC/DC50%1/2
$self->{"DEST"} and ref $self->{"DEST"} eq "SCALAR"
$self->{"DEST"}
ref $self->{"DEST"} eq "SCALAR"
Truth table66%2/3
A and B
A= $self->{"DEST"}B= ref $self->{"DEST"} eq "SCALAR"
| |||||||||||||||||||||||||||||||||
| 265 | 2 | push @{ $self->{FBUFS} }, $self->{SOURCE}; | |||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 2 | return undef; | |||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | =item open | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | If a filename was passed in, opens it. Determines if the handle is open | ||||||||||||||||||||||||||||||||
| 274 | via fileno(). Throws an exception on error. | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 127 | my %open_flags = ( | |||||||||||||||||||||||||||||||
| 279 | '>' => O_RDONLY, | ||||||||||||||||||||||||||||||||
| 280 | '>>' => O_RDONLY, | ||||||||||||||||||||||||||||||||
| 281 | '<' => O_WRONLY | O_CREAT | O_TRUNC, | ||||||||||||||||||||||||||||||||
| 282 | '<<' => O_WRONLY | O_CREAT | O_APPEND, | ||||||||||||||||||||||||||||||||
| 283 | ); | ||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||
| 285 | sub open { | ||||||||||||||||||||||||||||||||
| 286 | 2 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | croak "IPC::Run::IO: Can't open() a file with no name" | ||||||||||||||||||||||||||||||||
| 289 | 2 | ▶ | unless defined $self->{FILENAME}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | $self->{HANDLE} = gensym unless $self->{HANDLE}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 2 | ▶ | _debug "opening '", $self->filename, "' mode '", $self->mode, "'" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 293 | if _debugging_data; | ||||||||||||||||||||||||||||||||
| 294 | sysopen( | ||||||||||||||||||||||||||||||||
| 295 | $self->{HANDLE}, | ||||||||||||||||||||||||||||||||
| 296 | $self->filename, | ||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | $open_flags{ $self->op }, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 298 | ) or croak "IPC::Run::IO: $! opening '$self->{FILENAME}', mode '" . $self->mode . "'"; | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 2 | return undef; | |||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | =item open_pipe | ||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | If this is a redirection IO object, this opens the pipe in a platform | ||||||||||||||||||||||||||||||||
| 306 | independent manner. | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | =cut | ||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | sub _do_open { | ||||||||||||||||||||||||||||||||
| 311 | 2093 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_do_open: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 312 | 2093 | my ( $child_debug_fd, $parent_handle ) = @_; | |||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | 2093 | ▶ | if ( $self->dir eq "<" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | 643 | ( $self->{TFD}, $self->{FD} ) = IPC::Run::_pipe_nb; | |||||||||||||||||||||||||||||||
| 316 | 643 | ▶ | if ($parent_handle) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 317 | 28 | ▶ | CORE::open $parent_handle, ">&=$self->{FD}" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 318 | or croak "$! duping write end of pipe for caller"; | ||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||
| 321 | else { | ||||||||||||||||||||||||||||||||
| 322 | 1450 | ( $self->{FD}, $self->{TFD} ) = IPC::Run::_pipe; | |||||||||||||||||||||||||||||||
| 323 | 1450 | ▶ | if ($parent_handle) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 324 | 52 | ▶ | CORE::open $parent_handle, "<&=$self->{FD}" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 325 | or croak "$! duping read end of pipe for caller"; | ||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | sub open_pipe { | ||||||||||||||||||||||||||||||||
| 331 | 2093 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
open_pipe: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | ## Hmmm, Maybe allow named pipes one day. But until then... | ||||||||||||||||||||||||||||||||
| 334 | croak "IPC::Run::IO: Can't pipe() when a file name has been set" | ||||||||||||||||||||||||||||||||
| 335 | 2093 | ▶ | if defined $self->{FILENAME}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||
| 337 | 2093 | $self->_do_open(@_); | |||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||
| 339 | ## return ( child_fd, parent_fd ) | ||||||||||||||||||||||||||||||||
| 340 | return $self->dir eq "<" | ||||||||||||||||||||||||||||||||
| 341 | ? ( $self->{TFD}, $self->{FD} ) | ||||||||||||||||||||||||||||||||
| 342 | 2093 | ▶ | : ( $self->{FD}, $self->{TFD} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||
| 345 | sub _cleanup { ## Called from Run.pm's _cleanup | ||||||||||||||||||||||||||||||||
| 346 | 2309 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_cleanup: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 347 | 2309 | undef $self->{FAKE_PIPE}; | |||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | =item close | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | Closes the handle. Throws an exception on failure. | ||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | =cut | ||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||
| 357 | sub close { | ||||||||||||||||||||||||||||||||
| 358 | 1837 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | 1837 | ▶ | if ( defined $self->{HANDLE} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 361 | close $self->{HANDLE} | ||||||||||||||||||||||||||||||||
| 362 | or croak( | ||||||||||||||||||||||||||||||||
| 363 | "IPC::Run::IO: $! closing " | ||||||||||||||||||||||||||||||||
| 364 | . ( | ||||||||||||||||||||||||||||||||
| 365 | defined $self->{FILENAME} | ||||||||||||||||||||||||||||||||
| 366 | 2 | ▶ | ? "'$self->{FILENAME}'" | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 367 | : "handle" | ||||||||||||||||||||||||||||||||
| 368 | ) | ||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||
| 371 | else { | ||||||||||||||||||||||||||||||||
| 372 | 1835 | IPC::Run::_close( $self->{FD} ); | |||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||
| 375 | 1837 | $self->{FD} = undef; | |||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | 1837 | return undef; | |||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | =item fileno | ||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | Returns the fileno of the handle. Throws an exception on failure. | ||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | =cut | ||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | sub fileno { | ||||||||||||||||||||||||||||||||
| 388 | 4 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
fileno: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | 4 | my $fd = fileno $self->{HANDLE}; | |||||||||||||||||||||||||||||||
| 391 | croak( | ||||||||||||||||||||||||||||||||
| 392 | "IPC::Run::IO: $! " | ||||||||||||||||||||||||||||||||
| 393 | . ( | ||||||||||||||||||||||||||||||||
| 394 | defined $self->{FILENAME} | ||||||||||||||||||||||||||||||||
| 395 | 4 | ▶ | ? "'$self->{FILENAME}'" | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 396 | : "handle" | ||||||||||||||||||||||||||||||||
| 397 | ) | ||||||||||||||||||||||||||||||||
| 398 | ) unless defined $fd; | ||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | 4 | return $fd; | |||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||
| 403 | =item mode | ||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | Returns the operator in terms of 'r', 'w', and 'a'. There is a state | ||||||||||||||||||||||||||||||||
| 406 | 'ra', unlike Perl's open(), which indicates that data read from the | ||||||||||||||||||||||||||||||||
| 407 | handle or file will be appended to the output if the output is a scalar. | ||||||||||||||||||||||||||||||||
| 408 | This is only meaningful if the output is a scalar, it has no effect if | ||||||||||||||||||||||||||||||||
| 409 | the output is a subroutine. | ||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | The redirection operators can be a little confusing, so here's a reference | ||||||||||||||||||||||||||||||||
| 412 | table: | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | > r Read from handle in to process | ||||||||||||||||||||||||||||||||
| 415 | < w Write from process out to handle | ||||||||||||||||||||||||||||||||
| 416 | >> ra Read from handle in to process, appending it to existing | ||||||||||||||||||||||||||||||||
| 417 | data if the destination is a scalar. | ||||||||||||||||||||||||||||||||
| 418 | << wa Write from process out to handle, appending to existing | ||||||||||||||||||||||||||||||||
| 419 | data if IPC::Run::IO opened a named file. | ||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | sub mode { | ||||||||||||||||||||||||||||||||
| 424 | 10 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
mode: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | 10 | ▶ | croak "IPC::Run::IO: unexpected arguments for mode(): @_" if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | ## TODO: Optimize this | ||||||||||||||||||||||||||||||||
| 429 | 10 | ▶ | return ( $self->{TYPE} =~ /</ ? 'w' : 'r' ) . ( $self->{TYPE} =~ /<<|>>/ ? 'a' : '' ); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | =item op | ||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | Returns the operation: '<', '>', '<<', '>>'. See L</mode> if you want | ||||||||||||||||||||||||||||||||
| 435 | to spell these 'r', 'w', etc. | ||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||
| 437 | =cut | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | sub op { | ||||||||||||||||||||||||||||||||
| 440 | 2626 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
op: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||
| 442 | 2626 | ▶ | croak "IPC::Run::IO: unexpected arguments for op(): @_" if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||
| 444 | 2626 | return $self->{TYPE}; | |||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||
| 447 | =item binmode | ||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||
| 449 | Sets/gets whether this pipe is in binmode or not. No effect off of Win32 | ||||||||||||||||||||||||||||||||
| 450 | OSs, of course, and on Win32, no effect after the harness is start()ed. | ||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||
| 452 | =cut | ||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | sub binmode { | ||||||||||||||||||||||||||||||||
| 455 | 2624 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
binmode: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | 2624 | ▶ | $self->{BINMODE} = shift if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||
| 459 | 2624 | return $self->{BINMODE}; | |||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||
| 462 | =item dir | ||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | Returns the first character of $self->op. This is either "<" or ">". | ||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||
| 466 | =cut | ||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||
| 468 | sub dir { | ||||||||||||||||||||||||||||||||
| 469 | 15221 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
dir: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | 15221 | ▶ | croak "IPC::Run::IO: unexpected arguments for dir(): @_" if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 15221 | return substr $self->{TYPE}, 0, 1; | |||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||
| 476 | ## | ||||||||||||||||||||||||||||||||
| 477 | ## Filter Scaffolding | ||||||||||||||||||||||||||||||||
| 478 | ## | ||||||||||||||||||||||||||||||||
| 479 | #my $filter_op ; ## The op running a filter chain right now | ||||||||||||||||||||||||||||||||
| 480 | #my $filter_num; ## Which filter is being run right now. | ||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | use vars ( | ||||||||||||||||||||||||||||||||
| 483 | 127 | '$filter_op', ## The op running a filter chain right now | |||||||||||||||||||||||||||||||
| 484 | '$filter_num' ## Which filter is being run right now. | ||||||||||||||||||||||||||||||||
| 485 | 127 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | sub _init_filters { | ||||||||||||||||||||||||||||||||
| 488 | 2740 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_init_filters: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||
| 490 | 2740 | ▶ | confess "\$self not an IPC::Run::IO" unless UNIVERSAL::isa( $self, "IPC::Run::IO" ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 491 | 2740 | $self->{FBUFS} = []; | |||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | $self->{FBUFS}->[0] = $self->{DEST} | ||||||||||||||||||||||||||||||||
| 494 | 2740 | ▶ | if $self->{DEST} && ref $self->{DEST} eq 'SCALAR'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"DEST"} and ref $self->{"DEST"} eq "SCALAR"
MC/DC100%2/2
$self->{"DEST"} and ref $self->{"DEST"} eq "SCALAR"
$self->{"DEST"}
ref $self->{"DEST"} eq "SCALAR"
Truth table100%3/3
A and B
A= $self->{"DEST"}B= ref $self->{"DEST"} eq "SCALAR"
| |||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | 2740 | ▶ | return unless $self->{FILTERS} && @{ $self->{FILTERS} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"FILTERS"} and @{$self->{"FILTERS"};}
MC/DC50%1/2
$self->{"FILTERS"} and @{$self->{"FILTERS"};}
$self->{"FILTERS"}
@{$self->{"FILTERS"};}
Truth table66%2/3
A and B
A= $self->{"FILTERS"}B= @{$self->{"FILTERS"};}
| |||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | 1035 | push @{ $self->{FBUFS} }, map { | |||||||||||||||||||||||||||||||
| 499 | 2692 | my $s = ""; | |||||||||||||||||||||||||||||||
| 500 | 2692 | \$s; | |||||||||||||||||||||||||||||||
| 501 | 1035 | } ( @{ $self->{FILTERS} }, '' ); | |||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||
| 503 | 1035 | push @{ $self->{FBUFS} }, $self->{SOURCE}; | |||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||
| 506 | =item poll | ||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||
| 508 | TODO: Needs confirmation that this is correct. Was previously undocumented. | ||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||
| 510 | I believe this is polling the IO for new input and then returns undef if there will never be any more input, 0 if there is none now, but there might be in the future, and TRUE if more input was gotten. | ||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||
| 512 | =cut | ||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | sub poll { | ||||||||||||||||||||||||||||||||
| 515 | 11067 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
poll: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 516 | 11067 | my ($harness) = @_; | |||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | 11067 | ▶ | if ( defined $self->{FD} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 519 | 11035 | my $d = $self->dir; | |||||||||||||||||||||||||||||||
| 520 | 11035 | ▶ | if ( $d eq "<" ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 521 | 1332 | ▶ | if ( vec $harness->{WOUT}, $self->{FD}, 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 522 | 890 | ▶ | _debug_desc_fd( "filtering data to", $self ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 523 | if _debugging_details; | ||||||||||||||||||||||||||||||||
| 524 | 890 | return $self->_do_filters($harness); | |||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||
| 527 | elsif ( $d eq ">" ) { | ||||||||||||||||||||||||||||||||
| 528 | 9703 | ▶ | if ( vec $harness->{ROUT}, $self->{FD}, 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 529 | 2633 | ▶ | _debug_desc_fd( "filtering data from", $self ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 530 | if _debugging_details; | ||||||||||||||||||||||||||||||||
| 531 | 2633 | return $self->_do_filters($harness); | |||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||
| 535 | 7544 | return 0; | |||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||
| 538 | sub _do_filters { | ||||||||||||||||||||||||||||||||
| 539 | 5861 | ▶ | my IPC::Run::IO $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_do_filters: called CC=5 SCAR=16.9
| |||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||
| 541 | 5861 | ( $self->{HARNESS} ) = @_; | |||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||
| 543 | 5861 | my ( $saved_op, $saved_num ) = ( $IPC::Run::filter_op, $IPC::Run::filter_num ); | |||||||||||||||||||||||||||||||
| 544 | 5861 | $IPC::Run::filter_op = $self; | |||||||||||||||||||||||||||||||
| 545 | 5861 | $IPC::Run::filter_num = -1; | |||||||||||||||||||||||||||||||
| 546 | 5861 | my $redos = 0; | |||||||||||||||||||||||||||||||
| 547 | 5861 | my $r; | |||||||||||||||||||||||||||||||
| 548 | { | ||||||||||||||||||||||||||||||||
| 549 | 5861 | $@ = ''; | |||||||||||||||||||||||||||||||
| 550 | 5861 | $r = eval { IPC::Run::get_more_input(); }; | |||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||
| 552 | # Detect Resource temporarily unavailable and re-try 200 times (2 seconds), assuming select behaves (which it doesn't always? need ref) | ||||||||||||||||||||||||||||||||
| 553 | 5861 | ▶ | if ( ( $@ || '' ) =~ $IPC::Run::_EAGAIN && $redos++ < 200 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
($@ || "") =~ /$IPC::Run::_EAGAIN/ and $redos++ < 200
$@ || ''
MC/DC0%0/2
($@ || "") =~ /$IPC::Run::_EAGAIN/ and $redos++ < 200
$@
$redos++ < 200
Truth table33%1/3
A and B
A= $@B= $redos++ < 200
| |||||||||||||||||||||||||||||||||
| 554 | 0 | select( undef, undef, undef, 0.01 ); | |||||||||||||||||||||||||||||||
| 555 | 0 | redo; | |||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||
| 558 | 5861 | ( $IPC::Run::filter_op, $IPC::Run::filter_num ) = ( $saved_op, $saved_num ); | |||||||||||||||||||||||||||||||
| 559 | 5861 | $self->{HARNESS} = undef; | |||||||||||||||||||||||||||||||
| 560 | 5861 | ▶ | die "ack ", $@ if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 561 | 5861 | return $r; | |||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||
| 564 | =back | ||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||
| 566 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||
| 568 | Barrie Slaymaker <barries@slaysys.com> | ||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||
| 570 | =head1 TODO | ||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||
| 572 | Implement bidirectionality. | ||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||
| 574 | =cut | ||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||
| 576 | 127 | 1; | |||||||||||||||||||||||||||||||