| PerlIO-Util documentation | Contained in the PerlIO-Util distribution. |
PerlIO::Util - A selection of general PerlIO utilities
This document describes PerlIO::Util version 0.72.
use PerlIO::Util;
# utility layers
# open and flock(IN, LOCK_EX)
$io = PerlIO::Util->open('+< :flock', $file);
# open with O_CREAT | O_EXCL
$io = PerlIO::Util->open('+<:creat :excl', $file);
my $out = PerlIO::Util->open('>:tee', 'file.txt', \$scalar, \*STDERR);
print $out 'foo'; # print to 'file.txt', $scalar and *STDERR
# utility routines
*STDOUT->push_layer(scalar => \$scalar); # it dies on fail
print 'foo'; # to $scalar
print *STDOUT->pop_layer(); # => scalar
print $scalar; # to *STDOUT
PerlIO::Util provides general PerlIO utilities: utility layers and utility
methods.
Utility layers are a part of PerlIO::Util, but you don't need to
say use PerlIO::Util for loading them. They will be automatically loaded.
Easy interface to flock().
See PerlIO::flock.
Use of O_CREAT without Fcntl.
See PerlIO::creat.
Use of O_EXCL without Fcntl.
See PerlIO::excl.
Multiplex output stream.
See PerlIO::tee.
PerlIO interface to directory functions.
See PerlIO::dir.
Reverse input stream.
See PerlIO::reverse.
Mediation of filesystem encoding.
This layer was split into an independent distribution, PerlIO::fse.
See PerlIO::fse.
Calls built-in open(), and returns an IO::Handle instance named args.
It dies on fail.
Unlike Perl's open() (nor IO::File's), mode is always required.
Returns the known layer names.
Returns the names of the PerlIO layers on FILEHANDLE.
Almost equivalent to binmode(FILEHANDLE, ':layer(arg)'), but accepts
any type of arg, e.g. a scalar reference to the :scalar layer.
This method dies on fail. Otherwise, it returns FILEHANDLE.
Equivalent to binmode(FILEHANDLE, ':pop'). It removes a top level layer
from FILEHANDLE, but note that you cannot remove dummy layers such as
:utf8 or :flock.
This method returns the name of the popped layer.
Perl 5.8.1 or later, and a C compiler.
No bugs have been reported.
Please report any bugs or feature requests to <gfuji(at)cpan.org>, or through the web interface at http://rt.cpan.org/.
PerlIO::flock, PerlIO::creat, PerlIO::excl, PerlIO::tee, PerlIO::dir, PerlIO::reverse, PerlIO::fse.
PerlIO for push_layer() and pop_layer().
perliol for implementation details.
open in perlfunc.
perlopentut.
Goro Fuji (藤 吾郎) <gfuji(at)cpan.org>.
Copyright (c) 2008-2010, Goro Fuji <gfuji(at)cpan.org>. Some rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| PerlIO-Util documentation | Contained in the PerlIO-Util distribution. |
package PerlIO::Util; use 5.008_001; use strict; our $VERSION = '0.72'; require XSLoader; XSLoader::load(__PACKAGE__, $VERSION); *IO::Handle::get_layers = \&PerlIO::get_layers; sub open :method{ shift; # this class if(@_ < 2){ require Carp; Carp::croak('Usage: PerlIO::Util->open($mode, @args)'); } my $mode = shift; my $io = _gensym_ref(scalar caller, join ' ', @_); unless(open $io, $mode, @_){ require Carp; Carp::croak('Cannot open(%s): %s', join(', ', $mode, @_), $!); } return $io; } 1; __END__