Mark Overmeer > IOMux > IOMux::IPC

Download:
IOMux-0.12.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.12   Source  

NAME ^

IOMux::IPC - exchange data with external command

INHERITANCE ^

 IOMux::IPC
   is a IOMux::Bundle
   is a IOMux::Handler::Read
   is a IOMux::Handler

   IOMux::Bundle also extends IOMux::Handler::Write
   is a IOMux::Handler::Write
   is a IOMux::Handler

SYNOPSIS ^

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

  use IOMux::Open '|-|', '|=|';
  my $pipe = $mux->open('|-|', $cmd, @cmdopts);

  use IOMux::IPC;
  my $ipc = IOMux::IPC->new(command => [$cmd, @cmdopts]);
  $mux->add($ipc);

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

DESCRIPTION ^

With this handler, you set-up a two way communication between the current process and some other process. This is not easy to program: you may need to play with timeouts every once in a while.

This module is based on IOMux::Bundle, because it will use two or three pipes to facilitate the communication.

METHODS ^

Constructors

IOMux::IPC->new(OPTIONS)
 -Option    --Defined in     --Default
  command                      <required>
  errors                       <true>
  fh          IOMux::Handler   <required>
  mode                         |=|
  name        IOMux::Handler   '|$cmd|'
  read_size   IOMux::Handler::Read  32768
  stderr      IOMux::Bundle    <undef>
  stdin       IOMux::Bundle    <required>
  stdout      IOMux::Bundle    <required>
  write_size  IOMux::Handler::Write  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.

errors => BOOLEAN

Include the stderr channel in the communication as well. These will be printed to STDERR by default.

fh => FILEHANDLE
mode => |-| or |=|

In the |-| mode, only STDIN and STDOUT are processed. Specifing the |=| has the same effect as setting the errors option: open a connection for STDERR as well.

name => STRING
read_size => INTEGER
stderr => IOMux::Handler::Read object
stdin => IOMux::Handler::Write object
stdout => IOMux::Handler::Read object
write_size => INTEGER
IOMux::IPC->open(MODE, (CMD, CMDOPTS)|(CMDARRAY, OPTIONS))

Open the pipe to read. MODE is either |-| or |=|. 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 = IOMux::Poll->new;
  $mux->open('|-|', 'sort', '-u');  # no opts
  $mux->open('|-|', ['sort', '-u'], %opts);
  $mux->open('|-|', 'sort');        # no opts
  $mux->open('|-|', ['sort'], %opts);

Accessors

$obj->childPid

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

$obj->connections See "Accessors" in IOMux::Bundle
$obj->fh See "Accessors" in IOMux::Handler
$obj->fh See "Accessors" in IOMux::Handler
$obj->fileno See "Accessors" in IOMux::Handler
$obj->fileno See "Accessors" in IOMux::Handler
$obj->mode

The bits of the open mode.

$obj->mux See "Accessors" in IOMux::Handler
$obj->mux See "Accessors" in IOMux::Handler
$obj->name See "Accessors" in IOMux::Handler
$obj->name See "Accessors" in IOMux::Handler
$obj->readSize([INTEGER]) See "Accessors" in IOMux::Handler::Read
$obj->stderr See "Accessors" in IOMux::Bundle
$obj->stdin See "Accessors" in IOMux::Bundle
$obj->stdout See "Accessors" in IOMux::Bundle
$obj->usesSSL See "Accessors" in IOMux::Handler
$obj->usesSSL See "Accessors" in IOMux::Handler
$obj->writeSize([INTEGER]) See "Accessors" in IOMux::Handler::Write

User interface

Connection

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

Reading

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

Writing

$obj->print(STRING|SCALAR|LIST|ARRAY) See "Writing" in IOMux::Handler::Write
$obj->printf(FORMAT, PARAMS) See "Writing" in IOMux::Handler::Write
$obj->say(STRING|SCALAR|LIST|ARRAY) See "Writing" in IOMux::Handler::Write
$obj->write(SCALAR, [MORE]) See "Writing" in IOMux::Handler::Write

Multiplexer

Connection

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

Reading

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

Writing

$obj->mux_outbuffer_empty See "Writing" in IOMux::Handler::Write
$obj->mux_output_waiting See "Writing" in IOMux::Handler::Write
$obj->mux_write_flagged(FILENO) See "Writing" in IOMux::Handler
$obj->mux_write_flagged(FILENO) See "Writing" in IOMux::Handler

Service

Errors

$obj->mux_error(BUFFER) See "Errors" in IOMux::Bundle

Helpers

$obj->extractSocket(HASH)
IOMux::IPC->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->extractSocket(HASH)
IOMux::IPC->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IOMux::Handler
$obj->show See "Helpers" in IOMux::Handler
$obj->show See "Helpers" in IOMux::Handler

SEE ALSO ^

This module is part of IOMux distribution version 0.12, built on January 27, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IOMux", and "IOMux::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

syntax highlighting: