IO::Pipe#
Native implementation of IO::Pipe
Provides object-oriented pipe operations compatible with Perl’s IO::Pipe. IO::Pipe objects are blessed hashrefs storing reader/writer fh_ids.
For fork-based communication, reader()/writer() without args just
configures the object to the appropriate end of the pipe.
Functions#
new#
Creates a pipe pair via pipe(2). Returns a blessed IO::Pipe object
holding both reader and writer filehandle IDs internally.
use IO::Pipe;
my $pipe = IO::Pipe->new();
handles#
Returns two unopened IO::Pipe::End objects (reader, writer) that can be configured independently.
my ($reader, $writer) = $pipe->handles();
reader#
Configures the pipe as the reader end. Without arguments, closes the write end and re-blesses as IO::Pipe::End. With a command, forks a child that execvp’s the command with its stdout connected to the pipe; the parent reads from the pipe.
$pipe->reader("ls", "-l"); # fork+exec, parent reads
$pipe->reader(); # just configure reader end
writer#
Configures the pipe as the writer end. Without arguments, closes the read end and re-blesses as IO::Pipe::End. With a command, forks a child that execvp’s the command with its stdin connected to the pipe; the parent writes to the pipe.
$pipe->writer("sort"); # fork+exec, parent writes
$pipe->writer(); # just configure writer end
IO::Pipe::End Methods#
IO::Pipe::End inherits from IO::Handle and adds:
IO::Pipe::End::new#
Constructor. Returns an unopened IO::Pipe::End blessed hashref.
IO::Pipe::End::close#
Closes the pipe end. If the pipe was created with a command (via
reader(CMD) or writer(CMD)), also waits for the child process
to exit.