Module::Generic::File::IO - File IO Object Wrapper
use Module::Generic::File::IO; my $io = Module::Generic::File::IO->new || die( Module::Generic::File::IO->error, "\n" ); my $io = Module::Generic::File::IO->new( fileno => $fileno ) || die( Module::Generic::File::IO->error, "\n" ); use Module::Generic::File::IO qw( wraphandle ); my $io = wraphandle( $fh ); my $io = wraphandle( $fh, '>' );
v0.1.3
This is a thin wrapper that inherits from IO::File with the purpose of providing a uniform api in conformity with standard api call throughout the Module::Generic modules family and to ensure call to any IO::File will never die, but instead set an error and return undef
undef
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 make sure to check the IO::File documentation for more information.
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 a "fdopen" on the file descriptor provided.
mode
A mode which will be used along with fileno to fdopen the file descriptor. Possible values can be <, +<, >+, +>, etc and r, r+, w, w+. a and a+
<
+<
>+
+>
r
r+
w
w+
a
a+
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 and this will return a newly created Module::Generic::File::IO
By default, the mode will be '<'
Returns an array reference containing the original arguments passed during object instantiation.
See "autoflush" in IO::Handle for details
See "binmode" in IO::File for details
See "blocking" in IO::Handle for details
Returns true if one can read from this filehandle, or false otherwise.
Returns true if one can write from this filehandle, or false otherwise.
See "close" in IO::Handle for details
See "eof" in IO::Handle for details
See "fcntl" in IO::Handle for details
See "fdopen" in IO::Handle for details
See "fileno" in IO::Handle for details
Returns the filehandle flags value using "fcntl" in perlfunc
See "flush" in IO::Handle for details
See "format_formfeed" in IO::Handle for details
See "format_line_break_characters" in IO::Handle for details
See "format_lines_left" in IO::Handle for details
See "format_lines_per_page" in IO::Handle for details
See "format_name" in IO::Handle for details
See "format_page_number" in IO::Handle for details
See "format_top_name" in IO::Handle for details
See "format_write" in IO::Handle for details
See "formline" in IO::Handle for details
See "getc" in IO::Handle for details
See "getline" in IO::Handle for details
See "getlines" in IO::Handle for details
See "getpos" in IO::Seekable for details
See "input_line_number" in IO::Handle for details
See "input_record_separator" in IO::Handle for details
See "ioctl" in IO::Handle for details
See "new_from_fd" in IO::Handle for details
See "new_tmpfile" in IO::File for details
See "opened" in IO::Handle for details
See "output_field_separator" in IO::Handle for details
See "output_record_separator" in IO::Handle for details
See "print" in IO::Handle for details
See "printf" in IO::Handle for details
See "printflush" in IO::Handle for details
See "read" in IO::Handle for details
See "say" in IO::Handle for details
See "seek" in IO::Seekable for details
See "setpos" in IO::Seekable for details
See "stat" in IO::Handle for details
See "sync" in IO::Handle for details
See "sysread" in IO::Handle for details
See "sysseek" in IO::Seekable for details
See "syswrite" in IO::Handle for details
See "tell" in IO::Seekable for details
See "truncate" in IO::Handle for details
See "ungetc" in IO::Handle for details
See "untaint" in IO::Handle for details
See "write" in IO::Handle for details
Module::Generic::File::IO automatically exports the following constants taken from Fcntl:
O_*
F_GETFL
F_SETFL
LOCK_SH
LOCK_EX
LOCK_NB
LOCK_UN
See also the manual page for fcntl for more detail about those constants.
fcntl
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
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 mitigate those issues.
STORABLE_freeze
STORABLE_thaw
3.26
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.
SCALAR
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.
$THAW_REOPENS_FILE
Jacques Deguest <jack@deguest.jp>
IO::Handle, IO::File, IO::Seekable
Copyright(c) 2022 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.
To install Module::Generic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::Generic
CPAN shell
perl -MCPAN -e shell install Module::Generic
For more information on module installation, please visit the detailed CPAN module installation guide.