IO::Ha...erator(3pm)
π IO::Handle::Iterator β iterator based read handle, bestie π
okay so this is the perl manual page for IO::Handle::Iterator (shipped in the User Contributed Perl Documentation, iykyk), and it's genuinely one of the cutest little classes you'll ever meet. It's giving "read handle, but make it a callback". Let's get into it. π¦
β¨ NAME β¨
IO::Handle::Iterator β iterator based read handle. That's the whole vibe. π
πΈ SYNOPSIS πΈ
IO::Handle::Iterator->new(sub {
return $next_line; # or undef on eof
});
literally that's it. one sub. one vibe. no cap. β¨
π DESCRIPTION π
So here's the tea β β this class lets you define a read handle using a single callback that behaves like getline, and then it wires up a few fallback methods (like read) on top of it. Main character energy fr fr.
It's similar to this, but much simpler:
IO::Handle::Prototype::Fallback->new(
__read => sub { ... },
);
And the reason for the simplicity? π IO::Handle::Prototype::Fallback will try its very best to behave correctly β i.e. it respects the value of $/ and all that. This implementation, on the other hand, just assumes it's fine to return things that aren't exactly lines from getline, so the values are simply passed through. No extra processing, no drama, no overthinking. periodt. π
π§ READ BUFFERING π§
When a method that requires buffering gets invoked, the handle is reblessed to a subclass which handles the buffering. (not me gasping at runtime class surgery π iconic behaviour tbh)
Then, calling getline again on this object will return the value of the buffer and return to the normal iterator class. slay β it bounces right back to its original self. π¦
tl;dr: buffer mode is a little temporary glow-up, not a permanent rebrand. β¨
and that's the whole page, bestie π This one's from the User Contributed Perl Documentation, perl v5.36.0, dated 2023-01-24 β so go forth, wrap a sub, and iterate like the icon you are. ππ₯π
π¦ where this page comes from
- debian bookworm: libio-handle-util-perl 0.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libio-handle-util-perl 0.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libio-handle-util-perl 0.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libio-handle-util-perl 0.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libio-handle-util-perl 0.02-1 Β· 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