IO::Pa...uffered(3pm)
π IO::Pager::Buffered β the manual, but make it cute π
okay bestie, welcome to IO::Pager::Buffered, from the Perl user-contributed docs, section 3pm. sit down, hydrate, and let's talk about deferred output. π«Ά
β¨ NAME β¨
IO::Pager::Buffered β it pipes your output to PAGER, but only if where you're sending it is actually a TTY. no TTY? no pager. it's giving β¨considerateβ¨.
πΈ SYNOPSIS πΈ
use IO::Pager::Buffered;
{
local $token = IO::Pager::Buffered::open local *STDOUT;
print <<" HEREDOC" ;
...
A bunch of text later
HEREDOC
}
{
# You can also use scalar filehandles...
my $token = IO::Pager::Buffered::open($FH) or warn($!);
print $FH "No globs or barewords for us thanks!\n" while 1;
}
{
# ...or an object interface
my $token = new IO::Pager::Buffered;
$token->print("OO shiny...\n") while 1;
}
three whole ways to do the thing. pick your fighter. π
π¦ DESCRIPTION π¦
so like, the whole IO::Pager subclass family exists so you can programmatically decide whether or not to pipe a filehandle's output into some program that lives in PAGER. and who sets PAGER? IO::Pager does, at runtime, if you haven't already defined it yourself. teamwork. π
this particular subclass is the buffered one β capital B, capital energy. it holds all the output hostage until execution returns to the parent scope, or until you manually flush. that's the deal.
not what you wanted? go look at a different subclass, like IO::Pager::Unbuffered. it's fine. no hard feelings.
is buffering useful? probably not common, but lowkey yes in some cases:
- you could buffer everything headed to
STDOUTwhile the process runs, so that warnings onSTDERRare way more visible, and then show the less urgentSTDOUTstuff after. π - or, alternately, you let the
STDOUToutput slide right by and defer the warnings for later perusal. π
π METHODS π
the class-specific deets are below, everything else you inherit from IO::Pager. nepotism, but make it OOP.
π open( [FILEHANDLE] )
spin up a fresh IO::Pager to paginate FILEHANDLE β but only if necessary. assign the return value to a scoped variable. and listen: output does not occur until the filehandle is flushed or closed. no cap. the buffer is patient. π
π new( [FILEHANDLE] )
almost identical to open, except you get an IO::Handle back if there's no TTY, so you can do IO::Pager agnostic programming. it's the same vibe but with a safety net. π«Ά
π close( FILEHANDLE )
flushes the buffer to the pager and closes the filehandle for writing.
normally, if your token lives in a lexically or locally scoped variable from open, you don't need to call close yourself β the scope handles it, iconic behaviour. β¨
but β and this is the important bit β if you're using IO::Pager::Buffered with an unlocalized STDOUT or STDERR, then you gotta close the filehandle to display the buffered content, or just sit there and wait for global garbage cleaning at program termination. your call. π
alternatively? you might prefer to use a non-core filehandle with IO::Pager, and call "select" in perlfunc to make it the default for output. chef's kiss. π
π tell( FILEHANDLE )
returns the size of the buffer in bytes. that's it. that's the method. π
π flush( FILEHANDLE )
immediately flushes the contents of the buffer. boom. done.
heads up bestie: if the last print didn't end with a newline, the text from the preceding newline to the end of the buffer will be flushed β but it's unlikely to actually display until a newline is printed and flushed. so like, it's flushed but also not showing. the duality. π
β οΈ CAVEATS β οΈ
if you mix buffered and unbuffered operations, the output order is unspecified, and will probably differ for a TTY vs. a file. not a vibe. see perlfunc.
$, is used β see perlvar.
you probably want to do something with SIGPIPE, eg;
eval {
local $SIG{PIPE} = sub { die };
local $STDOUT = IO::Pager::open(*STDOUT);
while (1) {
# Do something
}
}
# Do something else
do it. trust. π«Ά
π SEE ALSO π
IO::Pager, IO::Pager::Unbuffered, IO::Pager::Page,
π AUTHOR π
Jerrad Pierce <jpierce@cpan.org>
Florent Angly <florent.angly@gmail.com>
this module was inspired by Monte Mitzelfelt's IO::Page 0.02 β shoutout to the originator, we love an inspiration arc. π
π COPYRIGHT AND LICENSE π
Copyright (C) 2003-2018 Jerrad Pierce
- Thou shalt not claim ownership of unmodified materials.
- Thou shalt not claim whole ownership of modified materials.
- Thou shalt grant the indemnity of the provider of materials.
- Thou shalt use and dispense freely without other restrictions.
or, if you prefer:
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.0 or, at your option, any later version of Perl 5 you may have available.
okay that's the whole page, periodt. π this was perl v5.30.3, dated 2020-11-07, and the manual is IO::Pa...uffered(3pm) β yes the title gets truncated in the header, that's just how the terminal does her. go forth and buffer responsibly. π¦β¨π
π¦ where this page comes from
- debian bookworm: libio-pager-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libio-pager-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libio-pager-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libio-pager-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libio-pager-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libio-pager-perl 2.10-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