Module:...File::IO(3)
π NAME π
bestie, you're on the Module:...File::IO(3) page from User Contributed Perl Documentation, and the module is Module::Generic::File::IO β File IO Object Wrapper. It's giving filehandle wrapper realness, no cap. π
β¨ SYNOPSIS β¨
use Module::Generic::File::IO;
my $io = Module::Generic::File::IO->new ||
die( Module::Generic::File::IO->error );
my $io = Module::Generic::File::IO->new( 'file.txt', '>' ) ||
die( Module::Generic::File::IO->error );
my $io = Module::Generic::File::IO->new( fileno => $fileno ) ||
die( Module::Generic::File::IO->error );
use Module::Generic::File::IO qw( wraphandle );
my $io = wraphandle( $fh );
my $io = wraphandle( $fh, '>' );
πΈ VERSION πΈ
v0.2.0 β short, sweet, iconic. π¦
π DESCRIPTION π
Okay so this is a thin wrapper that inherits from IO::File, and its whole thing is providing a uniform api in conformity with standard api call throughout the Module::Generic modules family. It also makes sure that a call to any IO::File will never die β instead it sets an error and returns undef in scalar context or an empty list in list context. Periodt.
Supported methods are rigorously the same as IO::File and IO::Handle on top of all the standard ones from Module::Generic.
The IO methods are listed below for convenience, but bestie, make sure to check the IO::File documentation for more information. π
π οΈ CONSTRUCTOR π οΈ
new
This instantiates a new Module::Generic::File::IO object and returns it. β¨
It optionally takes the following parameters:
filenoβ a file descriptor. When this is provided, the newly created object will perform afdopenon the file descriptor provided.modeβ a mode which will be used along withfilenoto fdopen the file descriptor. Possible values can be"<","+<",">+","+>", etc and"r","r+","w","w+"."a"and"a+".
See IO::File, and "open" in perlfunc for more information.
π§ FUNCTIONS π§
wraphandle
my $io = Module::Generic::File::IO::wraphandle( $fh, '>' );
# or
use Module::Generic::File::IO qw( wraphandle );
my $io = wraphandle( $fh, '>' );
Provided with a filehandle and an optional mode, this returns a newly created Module::Generic::File::IO. π«Ά
By default, the mode will be '<'.
π METHODS π
argsβ returns an array reference containing the original arguments passed during object instantiation.autoflushβ see"autoflush" in IO::Handlefor details.binmodeβ see"binmode" in IO::Filefor details.blockingβ see"blocking" in IO::Handlefor details.can_readβ returns true if one can read from this filehandle, or false otherwise.can_writeβ returns true if one can write from this filehandle, or false otherwise.closeβ see"close" in IO::Handlefor details.eofβ see"eof" in IO::Handlefor details.fcntlβ see"fcntl" in IO::Handlefor details.fdopenβ see"fdopen" in IO::Handlefor details.filenoβ see"fileno" in IO::Handlefor details.flagsβ returns the filehandle flags value using"fcntl" in perlfunc.flockβ returns the filehandle flock using"flock" in perlfunc.flushβ see"flush" in IO::Handlefor details.format_formfeedβ see"format_formfeed" in IO::Handlefor details.format_line_break_charactersβ see"format_line_break_characters" in IO::Handlefor details.format_lines_leftβ see"format_lines_left" in IO::Handlefor details.format_lines_per_pageβ see"format_lines_per_page" in IO::Handlefor details.format_nameβ see"format_name" in IO::Handlefor details.format_page_numberβ see"format_page_number" in IO::Handlefor details.format_top_nameβ see"format_top_name" in IO::Handlefor details.format_writeβ see"format_write" in IO::Handlefor details.formlineβ see"formline" in IO::Handlefor details.getcβ see"getc" in IO::Handlefor details.getlineβ see"getline" in IO::Handlefor details.getlinesβ see"getlines" in IO::Handlefor details.getposβ see"getpos" in IO::Seekablefor details.input_line_numberβ see"input_line_number" in IO::Handlefor details.input_record_separatorβ see"input_record_separator" in IO::Handlefor details.ioctlβ see"ioctl" in IO::Handlefor details.lock_stateβ returns a hash reference containing the state of the lock, if any, for the file handle. This data is set by"flock". This method is mainly used by"lock" in Module::Generic::File.lockedβ check if the file handle is locked, and returns the associated flags if it is, orundefotherwise.new_from_fdβ see"new_from_fd" in IO::Handlefor details.new_tmpfileβ see"new_tmpfile" in IO::Filefor details.openedβ see"opened" in IO::Handlefor details.output_field_separatorβ see"output_field_separator" in IO::Handlefor details.output_record_separatorβ see"output_record_separator" in IO::Handlefor details.printβ see"print" in IO::Handlefor details.printfβ see"printf" in IO::Handlefor details.printflushβ see"printflush" in IO::Handlefor details.readβ see"read" in IO::Handlefor details.sayβ see"say" in IO::Handlefor details.seekβ see"seek" in IO::Seekablefor details.selectβ returns the filehandle select using"select" in perlfunc.
$io->select;
my $oldfh = $io->select; $| = 1; $oldfh->select;
Or, more simply:
$io->autoflus(1);
setposβ see"setpos" in IO::Seekablefor details.statβ see"stat" in IO::Handlefor details.syncβ see"sync" in IO::Handlefor details.sysopenβ see"sysopen" in IO::Handlefor details.sysreadβ see"sysread" in IO::Handlefor details.sysseekβ see"sysseek" in IO::Seekablefor details.syswriteβ see"syswrite" in IO::Handlefor details.tellβ see"tell" in IO::Seekablefor details.truncateβ see"truncate" in IO::Handlefor details.ungetcβ see"ungetc" in IO::Handlefor details.untaintβ see"untaint" in IO::Handlefor details.writeβ see"write" in IO::Handlefor details.
π CONSTANTS π
Module::Generic::File::IO automatically exports the following constants taken from Fcntl:
O_*F_GETFLF_SETFLLOCK_SHLOCK_EXLOCK_NBLOCK_UN
See also the manual page for "fcntl" for more detail about those constants.
π§ SERIALISATION π§
Serialisation by CBOR, Sereal and Storable::Improved (or the legacy Storable) is supported by this package. To that effect, the following subroutines are implemented: FREEZE, THAW.
For STORABLE_freeze and STORABLE_thaw, they are not implemented, because as of version 3.26 Storable raises an exception without giving any chance to the IO module to return an object representing the deserialised data. So, instead of using Storable, use instead the drop-in replacement Storable::Improved, which addresses and mitigates those issues. iykyk β¨
If you use Storable::Improved, then serialisation and deserialisation will work seamlessly.
Failure to do use Storable::Improved, and Storable would instead return the Module::Generic::File::IO as a "SCALAR" object rather than a glob.
Note that by default $THAW_REOPENS_FILE is set to a true value, and this will have deserialisation recreate an object somewhat equivalent to the original one.
π§΅ THREAD SAFETY π§΅
This module is designed for use in single-threaded or forked applications where filehandles are not shared across threads.
It does not implement internal locking or reference counting.
- Do not share filehandle objects between threads unless externally synchronized.
- Serialized filehandles may not survive process or thread boundaries unless the underlying file is still available.
π AUTHOR π
Jacques Deguest β jack@deguest.jp
π SEE ALSO π
IO::HandleIO::FileIO::Seekable
π COPYRIGHT & LICENSE π
Copyright(c) 2022-2024 DEGUEST Pte. Ltd.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
cute sign-off: this page is from perl v5.42.2, dated 2026-02-15, and its manual name is Module:...File::IO(3). Byeee, bestie β go read some filehandles responsibly πβ¨
π¦ where this page comes from
- alpine 3.24: perl-module-generic-doc 1.1.3-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms