Rex::FS::File(3pm)

πŸ’– Rex::FS::File(3pm) πŸ’–

okay bestie, pull up a chair, we're reading a Perl manpage and it's gonna be cute. this is Rex::FS::File, from the User Contributed Perl Documentation section, and it's literally just called File Class. iconic behavior tbh. ✨


🌸 NAME 🌸

Rex::FS::File β€” it's a File Class. that's it, that's the name, she's simple and she knows it πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, this is the</**> File Class that gets used by file_write and file_read. that's the whole description bestie, she's not doing a TED talk about it. it's the file class those two functions lean on, no cap. 🫢


✨ SYNOPSIS ✨

here's the vibe, code and all, verbatim because we do not mess with code in this house:

use Rex::Interface::File;
my $fh = Rex::Interface::File->create('Local');
$fh->open( '<', 'filename' );

my $file = Rex::FS::File->new(fh => $fh);
$file->read($len);
$file->read_all;
$file->write($buf);
$file->close;

look at her go. create a file interface, pop it open, wrap it in a Rex::FS::File, and then read/write/close to your heart's content. main character energy fr fr. πŸ‘‘


πŸŽ€ CLASS METHODS πŸŽ€

πŸ“ new

this is the constructor, the birthing suite, the origin story. you have two options and you must pick one:

  • hand her a filehandle that the object should work on, or
  • hand her a filename.
little warning bestie: if you go the filehandle route, it has to be a Rex::Interface::File::* object. not just any old filehandle, okay? she's picky. πŸ’…

filehandle first, here's how:

my $fh = Rex::Interface::File->create('Local');
$fh->open( '<', 'filename' );

my $file = Rex::FS::File->new(fh => $fh);

and now the filename route, because sometimes you just wanna say the name and go:

# open a local file in read mode
my $file = Rex::FS::File->new(
  filename => 'filename',
  mode     => 'r', # or '<'
  type     => 'Local',
);

# or shorter
my $file = Rex::FS::File->new( filename => 'filename' );

# open a local file in write mode
my $file = Rex::FS::File->new(
  filename => 'filename',
  mode     => 'w', # or '>'
);

look how short that second one is. she said "less is more" and honestly? she ate. πŸ”₯

Allowed modes: here's the menu, memorize it:

<  read
r  read
>  write
w  write
>> append
a  append

and for the allowed types? those live over in the documentation of Rex::Interface::File β€” go read that one, bestie, she's got the list. πŸ“–

🌈 write($buf)

writes $buf straight into the filehandle. just shove your string in there and she'll take it from here.

$file->write("Hello World");

🧚 seek($offset)

seeks to the file position $offset. think of it as teleporting the little cursor wherever you want her to be. ✨

so like, to set the file pointer to the 5th byte:

$file->seek(5);

boom. teleported. πŸ¦‹

πŸ’œ read($len)

reads $len bytes out of the filehandle. you tell her how many bytes, she brings you back exactly that many. an icon.

my $content = $file->read(1024);

⭐ read_all

reads everything out of the filehandle. the whole thing. no crumbs left. she is thorough and she is obsessed with getting the full picture.

my $content = $file->read_all;

🌸 close

closes the file. say goodbye, shut the door, turn off the lights. πŸšͺ

$file->close;

πŸ’– SEE ALSO πŸ’–

ngl there's no SEE ALSO section in this one bestie β€” the only reference she name-drops is Rex::Interface::File (for the allowed types), so go bother that page next. πŸ‘€


okay that's the whole page, you made it, so proud of you πŸ₯ΉπŸ’–

this little masterpiece is from perl v5.40.1, dated 2025-10-03, and it lives in the User Contributed Perl Documentation corner of the world. no notes. slay. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from