IO::Select::Trap - IO::Select() functionality on Scalar-based Filehandles


 use IO::Select::Trap;
 use IO::String;

 my $ios = new IO::String();
 my $sock = new IO::Socket();
 my $rb = new IO::Select::Trap(<{ trap=>'Scalar|String' }>, $ios, $sock);
 my $wb = new IO::Select::Trap(<{ trap=>'Scalar|String' }>, $ios, $sock);
 my ($rready, $wready) = IO::Select::Trap->select($rb, $wb);


IO::Select::Trap is a wrapper for IO::Select which enables use of the IO::Select->select() method on IO::Scalar or IO::String object/filehandles. Other filehandle object types (ie IO::Socket) are passed through to IO::Select for processing. Most of the IO::Select interface is supported.

An IO::String/Scalar object/filehandle is ready for reading when it contains some amount of data. It will always be ready for writing. Also, IO::String/Scalar objects will *never* block.

When calling select(), the trapped objects are evaluated first. If any are found to be ready, the IO::Select->select() is called with a timeout of '0'. Otherwise it is called with the supplied timeout (or undef).


trap experimental

REGEX that specifies the IO objects to trap.


Currently, the select(), can_read(), etc. methods only support trapped IO::Scalar or IO::String objects. Other trapped objects will probably break the tests that the methods use to determine read/write ability.

The is a bug when using IO::Scalar objects, in that two IO::Scalars can't be compared. Eg:

  $ios = new IO::Scalar;
  $ios2 = $ios;

  if ($ios == $ios2) { #...

.. causes a runtime error. A fix has been sent to to the author, and should be included in a future version.


Scott Scecina, <>

Except where otherwise noted, IO::Select::Trap is Copyright 2001 Scott Scecina. All rights reserved. IO::Select::Trap is free software; you may redistribute it and/or modify it under the same terms as Perl itself.