PerlIO::Layers(3pm)
π PerlIO::Layers π
okay bestie, listen β this is PerlIO::Layers, straight out of the User Contributed Perl Documentation, and it's literally your filehandle's vibe check. it tells you what your filehandle can actually do. no cap. π¦
β¨ VERSION β¨
version 0.012 β yes she's a real one π
πΈ SYNOPSIS πΈ
like, here's the whole thing in action:
use PerlIO::Layers qw/query_handle/;
if (!query_handle(\*STDOUT, 'binary')) {
...
}
see how easy that was? iconic. π
π DESCRIPTION π
so here's the tea: Perl's filehandles aren't just, like, one thing. they're a whole stack of layers, bestie. the bottom-most one is usually doing the actual IO (the heavy lifting, main character energy), and the ones stacked on top are doing buffering, encoding/decoding, or transformations. and PerlIO::Layers lets you query the filehandle's properties about all these layers. it's giving detective. it's giving nosy best friend. π
π FUNCTIONS π
π query_handle($fh, $query_name [, $argument]) π
this one queries a filehandle for some information. and get this β all the queries can take an optional argument, and if you pass it, it'll test for that layer's properties instead of checking every single layer of the handle. so flexible. so versatile. π
currently supported queries include:
layerβ checks if a certain layer is present. heads up though: unlike basically every other property,$argumentis mandatory for this one. you have to give it. fr fr.utf8β checks whether the filehandle/layer handles unicode β¨crlfβ checks whether the filehandle/layer does crlf translationbinaryβ checks whether the filehandle/layer is binary. and ngl, this test is pessimistic β for unknown layers it'll just assume it's not binary. it's a hater like that πmappableβ checks whether the filehandle/layer is memory mappable. it's the same asbinary, EXCEPT the"utf8"layer is accepted. so like, binary but with one (1) exception π«bufferedβ checks whether the filehandle/layer is buffered.readableβ checks whether the filehandle/layer is readable.writeableβ checks whether the filehandle/layer is writeable.openβ checks whether the filehandle/layer is open.tempβ checks whether the filehandle/layer refers to a temporary file.can_crlfβ checks whether layer$argument(or any layer, if$argumentisn't given) can do crlf translation.line_bufferedβ checks whether the filehandle is in line-buffering mode.autoflushβ checks whether the filehandle is in unbuffering mode. and okay, important note: this is not the opposite of buffering, it's more similar to autoflush β hence the name of this test. so don't come for me. π«Άbuffer_sizeβ checks whether the buffer size is equal to$argument.
π¦ get_layers($fh) π¦
gets you all the info on the layers of a filehandle. it returns a list, and each entry has 3 elements:
- the name of the layer
- the arguments of the layer (may be
undef) - an arrayref with the flags of the layer as strings
and the flags array can contain any of these values:
EOFβ end of file has been reached. that's it, that's the flag. π₯²CANWRITEβ writes are permitted, i.e. opened as">"or"+<"or">>", etc.CANREADβ reads are permitted i.e. opened"<"or"+>".ERRORβ an error has occurred. πTRUNCATEβ truncate file suggested by open mode.APPENDβ all writes should be appends.CRLFβ layer is performing Win32-like"\n"mapped to CR,LF for output and CR,LF mapped to"\n"for input. normally the provided"crlf"layer is the only layer that need bother about this."binmode"will mess with this flag rather than add/remove layers if thePERLIO_K_CANCRLFbit is set for the layers class.UTF8β data written to this layer should be UTF-8 encoded; data provided by this layer should be considered UTF-8 encoded. can be set on any layer by the":utf8"dummy layer. also set on the":encoding"layer.UNBUFβ layer is unbuffered β i.e. write to next layer down should occur for each write to this layer.WRBUFβ the buffer for this layer currently holds data written to it but not sent to next layer.RDBUFβ the buffer for this layer currently holds unconsumed data read from layer below.LINEBUFβ layer is line buffered. write data should be passed to next layer down whenever a"\n"is seen. any data beyond the"\n"should then be processed.TEMPβ file has beenunlink()ed, or should be deleted onclose().OPENβ handle is open.FASTGETSβ this instance of this layer supports the"fast gets"interface. normally set based onPERLIO_K_FASTGETSfor the class and by the existence of the function(s) in the table. however a class that normally provides that interface may need to avoid it on a particular instance. the"pending"layer needs to do this when it is pushed above a layer which does not support the interface.
and real talk: "query_handle" provides a more high level interface to all of this, so you should probably use that when you can. bestie advice. π
πΈ get_buffer_sizes($fh) πΈ
returns a list of buffer sizes for all buffered layers. unbuffered layers? skipped. not invited to the party. π βοΈ
π AUTHOR π
Leon Timmermans <fawaka@gmail.com>
π COPYRIGHT AND LICENSE π
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.
okay that's the whole page, we ate and left no crumbs π
signing off with the receipts: this was perl v5.42.3, dated 2026-08-19, and it's the PerlIO::Layers(3pm) page from the User Contributed Perl Documentation. go query a filehandle for me, bestie. mwah πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libperlio-layers-perl 0.012-3build5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms