IO::Fi...lename(3pm)
π IO::File::WithFilename β from the IO::File::WithFilename page in the User Contributed Perl Documentation β¨
Okay bestie, sit down, because this one is short but it's so useful. π«Ά
πΈ NAME πΈ
IO::File::WithFilename β filehandles that know their origin π
Like. The filehandle literally remembers where it came from. Main character energy fr fr.
β¨ SYNOPSIS β¨
use IO::File::WithFilename;
my $fh = IO::File::WithFilename->new('../movies/kin-dza-dza.ogg', O_RDONLY);
print $fh->filename, "\n";
print "$fh\n"; # same as above
Notice the second print? You can just stringify the whole object and it gives you the same thing. No extra work. We love a low-effort slay. π
π¦ DESCRIPTION π¦
Okay so here's the tea: this module does everything that IO::File does β every single thing, no cap β plus it implements the filename method, the one that File::Temp objects already have.
Why do we care? Because it lets you write code that is ignorant of what classes of objects it's working with. β¨ Your code doesn't need to know or care whether it got handed an IO::File, a File::Temp, or this little icon right here β it just asks for the filename and moves on. Obsessed, honestly.
If you want to check whether it's safe to call the filename method, the recommendation is to call the can method rather than to go poking around at an object's inheritance. π Do it like this:
print $obj->filename, "\n" if eval { $obj->can('filename') };
That's the vibe. can first, inheritance-snooping never. π
π§ EXPORT π§
Same as IO::File, i. e. the O_XXX constants from the Fcntl module β if this module is available. (If it's not available, well, no constants for you, bestie. π)
π SEE ALSO π
IO::FileFile::Temp
Go read those too, they're the whole reason this module gets to exist. π
β AUTHOR β
Ivan Fomichev, <ifomichev@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright (C) 2010 by Ivan Fomichev
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
Real talk though: that license line is not a suggestion, it's the whole deal. Free software, same terms as Perl, version 5.10.1 or any later Perl 5 you've got lying around. Respect it and it respects you. π«Ά
And that's a wrap!! This page came from perl v5.36.0, dated 2023-02-05, straight out of the User Contributed Perl Documentation. Go forth and know your filenames. ππΈβ¨
π¦ where this page comes from
- debian bookworm: libio-file-withfilename-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libio-file-withfilename-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libio-file-withfilename-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libio-file-withfilename-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libio-file-withfilename-perl 0.01-2 Β· 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