
PerlIO::Layers - Querying your filehandle's capabilities

version 0.010

use PerlIO::Layers qw/query_handle/;
if (!query_handle(\*STDOUT, 'binary')) {
...
}

Perl's filehandles are implemented as a stack of layers, with the bottom-most usually doing the actual IO and the higher ones doing buffering, encoding/decoding or transformations. PerlIO::Layers allows you to query the filehandle's properties concerning these layers.

This query a filehandle for some information. All queries can take an optional argument, that will test for that layer's properties instead of all layers of the handle. Currently supported queries include:
Check the presence of a certain layer. Unlike most other properties $argument is mandatory for this query.
Check whether the filehandle/layer handles unicode
Check whether the filehandle/layer does crlf translation
Check whether the filehandle/layer is binary. This test is pessimistic (for unknown layers it will assume it's not binary).
Checks whether the filehandle/layer is memory mappable. It is the same as binary, except that the utf8 layer is accepted.
Check whether the filehandle/layer is buffered.
Check whether the filehandle/layer is readable.
Check whether the filehandle/layer is writeable.
Check whether the filehandle/layer is open.
Check whether the filehandle/layer refers to a temporary file.
Checks whether layer $argument (or any layer if $argument it not given) can do crlf translation.
Check whether the filehandle is in line-buffering mode.
Checks wheter the filehandle is in unbuffering mode. Note that this is not the opposite of buffering, but more similar to autoflush, hence the name of this test.
Check whether the buffer size is equal to $argument.
Gets information on the layers of a filehandle. It's a list with whose entries have 3 elements: the name of the layer, the arguments of the layer (may be undef) and an arrayref with the flags of the layer as strings. The flags array can contain any of these values. You probably want to use query_layers instead. query_handle provides a more high level interface to this, you should probably use that when you can.
Returns a list of buffer sizes for all buffered layers. Unbuffered layers are skipped.

Leon Timmermans <fawaka@gmail.com>

This software is copyright (c) 2010 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.