NAME

IO::Mux::Pipe::Read - read from an external command

INHERITANCE

IO::Mux::Pipe::Read
  is a IO::Mux::Handler::Read
  is a IO::Mux::Handler

SYNOPSIS

my $mux = IO::Mux::Select->new;  # or ::Poll

use IO::Mux::Open '-|';
my $pipe = $mux->open('-|', $command, @cmd_options);

use IO::Mux::Pipe::Read;
my $pipe = IO::Mux::Pipe::Read->new
  ( command => [$command, @cmd_options] );
$mux->add($pipe);

$pipe->getline(sub {print "$_[0]\n"});

DESCRIPTION

In an event driven program, reading is harder to use than writing: the read will very probably be stalled until data has arrived, so you will need a callback to handle the resulting data.

METHODS

Constructors

IO::Mux::Pipe::Read->bare(OPTIONS)

Creates a pipe, but does not start a process (yet). Used by IO::Mux::IPC, which needs three pipes for one process. Returned is not only a new pipe object, but also a write handle to be connected to the other side.

All OPTIONS which are available to IO::Mux::Handler::Read::new() can be used here as well.

-Option   --Default
 read_size  4096
read_size => INTEGER

example:

my ($out, $out_rh)
    = IO::Mux::Pipe::Read->bare(name => 'stdout');
IO::Mux::Pipe::Read->new(OPTIONS)
-Option   --Defined in     --Default
 command                     <required>
 fh         IO::Mux::Handler  <required>
 name       IO::Mux::Handler  '$cmd|'
 read_size  IO::Mux::Handler::Read  4096
command => COMMAND|ARRAY

The external command to be executed. Either the COMMAND needs to parameters, or you need to pass an ARRAY of the command name and all its parameters.

fh => FILEHANDLE
name => STRING
read_size => INTEGER
IO::Mux::Pipe::Read->open(MODE, (CMD, CMDOPTS)|(CMDARRAY, OPTIONS))

Open the pipe to read. MODE is always -|. When you need to pass additional OPTIONS to the implied new(), then you must use an ARRAY for command name and its optional parameters.

example:

my $mux = IO::Mux::Poll->new;
$mux->open('-|', 'who', '-H');  # no opts
$mux->open('-|', ['who', '-H'], %opts);
$mux->open('-|', 'who');        # no opts
$mux->open('-|', ['who'], %opts);

Accessors

$obj->childPid

The process id of the child on the other side of the pipe.

$obj->fh See "Accessors" in IO::Mux::Handler
$obj->fileno See "Accessors" in IO::Mux::Handler
$obj->mode

The bits of the open mode.

$obj->mux See "Accessors" in IO::Mux::Handler
$obj->name See "Accessors" in IO::Mux::Handler
$obj->readSize([INTEGER]) See "Accessors" in IO::Mux::Handler::Read
$obj->usesSSL See "Accessors" in IO::Mux::Handler

User interface

Connection

$obj->close([CALLBACK]) See "Connection" in IO::Mux::Handler
$obj->timeout([TIMEOUT]) See "Connection" in IO::Mux::Handler

Reading

$obj->readline(CALLBACK) See "Reading" in IO::Mux::Handler::Read
$obj->slurp(CALLBACK) See "Reading" in IO::Mux::Handler::Read

Multiplexer

Connection

$obj->mux_init(MUX, [HANDLER]) See "Connection" in IO::Mux::Handler
$obj->mux_remove See "Connection" in IO::Mux::Handler
$obj->mux_timeout See "Connection" in IO::Mux::Handler

Reading

$obj->mux_eof(INPUT) See "Reading" in IO::Mux::Handler::Read
$obj->mux_except_flagged(FILENO) See "Reading" in IO::Mux::Handler
$obj->mux_input(BUFFER) See "Reading" in IO::Mux::Handler::Read
$obj->mux_read_flagged(FILENO) See "Reading" in IO::Mux::Handler

Writing

$obj->mux_write_flagged(FILENO) See "Writing" in IO::Mux::Handler

Service

Helpers

$obj->extractSocket(HASH)
IO::Mux::Pipe::Read->extractSocket(HASH) See "Helpers" in IO::Mux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IO::Mux::Handler
$obj->show See "Helpers" in IO::Mux::Handler

SEE ALSO

This module is part of IO-Mux distribution version 0.11, built on January 26, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IO::Mux", and "IO::Mux::HTTP".

Please post questions or ideas to perl@overmeer.net

LICENSE

Copyrights 2011 by Mark Overmeer. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html