IO#

📦 std

Load the core IO modules - IO::Handle, IO::File, IO::Seekable, IO::Pipe, IO::Socket, IO::Dir - in one use.

This is the module every IO:: class rests on: IO::Handle, IO::File, IO::Seekable, IO::Dir, IO::Socket and IO::Pipe all require it, so use IO; is enough to have the whole family available.

IO itself defines nothing you call as IO::something. Every method lives in the class it belongs to - IO::Seekable, IO::File, IO::Handle, IO::Socket, IO::Poll - and use IO qw(File Handle) simply loads the named subset.

It also defines the numeric constants those classes need: POLLIN, POLLPRI, POLLOUT, POLLRDNORM, POLLWRNORM, POLLRDBAND, POLLWRBAND, POLLNORM, POLLERR, POLLHUP and POLLNVAL in IO::Poll, and _IOFBF, _IOLBF, _IONBF, SEEK_SET, SEEK_CUR and SEEK_END in IO::Handle.

use strict;
use IO qw(Handle File Seekable);
use IO::Seekable;                  # exports SEEK_SET, SEEK_CUR, SEEK_END

my $fh = IO::File->new($path, "w+") or die $!;
$fh->autoflush(1);
$fh->print("hello\n");
$fh->seek(0, SEEK_SET);
print "read back: ", $fh->getline;               # read back: hello
printf "SEEK_END %d, _IONBF %d\n", SEEK_END, IO::Handle::_IONBF;   # 2, 2

This is a native implementation of the XS half of IO 1.56 - the handle methods that need C (blocking, ungetc, error, clearerr, untaint, flush, sync, setbuf, setvbuf, getline/getlines/gets, IO::Seekable’s getpos/setpos, IO::File->new_tmpfile, IO::Poll’s _poll and IO::Socket’s sockatmark). Every IO::* module’s Perl is upstream’s, unchanged.

Differences from upstream#

None.

Modules#

  • IO::Compress - read/write compressed data in multiple formats

  • IO::Dir - supply object methods for directory handles

  • IO::File - supply object methods for filehandles

  • IO::Handle - supply object methods for I/O handles

  • IO::Pipe - supply object methods for pipes

  • IO::Poll - Object interface to system poll call

  • IO::Pty - Pseudo TTY object class

  • IO::Seekable - supply seek based methods for I/O objects

  • IO::Select - OO interface to the select system call

  • IO::Socket - Object interface to socket communications

  • IO::Tty - Pseudo-terminals and the terminal constants: the compiled part under IO::Pty (a pty master and its slave as handles) and IO::Tty.

  • IO::Uncompress

  • IO::Zlib - IO:: style interface to Compress::Zlib