FileHandle#

Native implementation of FileHandle

FileHandle is a compatibility module that wraps IO::File and IO::Handle. In perl5, it’s a thin shim that re-exports IO::File functionality. We provide a native Rust implementation because the perl5 FileHandle.pm does use IO::File which does use IO which tries XSLoader::load 'IO', and that fails under pperl since we have no XS support.

This module sets up the FileHandle package with proper @ISA inheritance from IO::File and IO::Seekable, registers method stubs, and provides dispatch for the key methods that FileHandle exposes.

Perl Equivalent#

package FileHandle;
require 5.000;
use strict;
use IO::File;
our @ISA = qw(IO::File);
our $VERSION = "2.05";

Methods#

Most methods are inherited from IO::File / IO::Handle. The ones registered here are stubs to ensure method resolution works and can() succeeds.

  • new() - Constructor, returns a blessed FileHandle reference

  • new_from_fd($fd, $mode) - Constructor from file descriptor

  • open($file [, $mode]) - Open a file

  • fdopen($fd, $mode) - Open from file descriptor

  • close() - Close handle

  • print(@args) - Output data

  • printf($fmt, @args) - Formatted output

  • say(@args) - Output with newline

  • getline() - Read one line

  • getlines() - Read all lines

  • autoflush([$val]) - Get/set autoflush

  • flush() - Flush output

  • eof() - Test end of file

  • fileno() - Get file descriptor

  • read($buf, $len [, $offset]) - Read bytes

  • sysread($buf, $len [, $offset]) - Low-level read

  • syswrite($buf [, $len [, $offset]]) - Low-level write

  • seek($pos, $whence) - Seek

  • tell() - Tell position

  • binmode([$layer]) - Set binary mode

  • truncate($len) - Truncate file

  • stat() - File stat

  • opened() - Check if open

  • blocking([$flag]) - Get/set blocking mode

Exports#

  • autoflush (default export)

  • SEEK_SET, SEEK_CUR, SEEK_END constants (via @EXPORT_OK)