The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IOMux::Pipe::Write - write to an external command

INHERITANCE

 IOMux::Pipe::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('|-', $command, @cmd_options);

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

  $pipe->write($text);
  $pipe->print($text);

  write $pipe $text;
  print $pipe $text;

DESCRIPTION

In an event driven program, you must be careful with every Operation System call, because it can block the event mechanism, hence the program as a whole. Often you can be lazy with writes, because its communication buffers are usually working quite asynchronous... but not always. You may skip the callbacks for small writes and prints.

METHODS

Constructors

IOMux::Pipe::Write->bare(OPTIONS)

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

All OPTIONS which are available to IOMux::Handler::Write::new() can be used here as well.

 -Option   --Default
  read_size  4096
read_size => INTEGER

example:

  my ($in, $in_rh)
      = IOMux::Pipe::Write->bare(name => 'stdin');
IOMux::Pipe::Write->new(OPTIONS)
 -Option    --Defined in     --Default
  command                      <required>
  fh          IOMux::Handler   <required>
  name        IOMux::Handler   '|$cmd'
  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.

fh => FILEHANDLE
name => STRING
write_size => INTEGER
IOMux::Pipe::Write->open(MODE, (CMD, CMDOPTS)|(CMDARRAY, OPTIONS))

Open the pipe to write. 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 = IOMux::Poll->new;
  $mux->open('|-', 'lpr', '-#4');  # no opts
  $mux->open('|-', ['lpr', '-#4'], %opts);
  $mux->open('|-', 'lpr');        # no opts
  $mux->open('|-', ['lpr'], %opts);

Accessors

$obj->childPid

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

$obj->fh 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->name 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->timeout([TIMEOUT]) See "Connection" in IOMux::Handler

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_remove See "Connection" in IOMux::Handler
$obj->mux_timeout See "Connection" in IOMux::Handler

Reading

$obj->mux_except_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

Service

Helpers

$obj->extractSocket(HASH)
IOMux::Pipe::Write->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) 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