.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "IO::Pager 3" .TH IO::Pager 3 2023-07-26 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME IO::Pager \- Select a pager (possibly perl\-based) & pipe it text if a TTY .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& # Select an appropriate pager and set the PAGER environment variable \& use IO::Pager; \& \& # TIMTOWTDI Object\-oriented \& { \& # open() # Use all the defaults. \& my $object = new IO::Pager; \& \& # open FILEHANDLE # Unbuffered is default subclass \& my $object = new IO::Pager *STDOUT; \& \& # open FILEHANDLE,EXPR # Specify subclass \& my $object = new IO::Pager *STDOUT, \*(AqUnbuffered\*(Aq; \& \& # Direct subclass instantiation # FH is optional \& use IO::Pager::Unbuffered; \& my $object = new IO::Pager::Unbuffered *STDOUT; \& \& \& $object\->print("OO shiny...\en") while 1; \& print "Some other text sent to STODUT, perhaps from a foreign routine." \& \& # $object passes out of scope and filehandle is automagically closed \& } \& \& # TIMTOWTDI Procedural \& { \& # open FILEHANDLE # Unbuffered is default subclass \& my $token = IO::Pager::open *STDOUT; \& \& # open FILEHANDLE,EXPR # Specify subclass \& my $token = IO::Pager::open *STDOUT, \*(AqUnbuffered\*(Aq; \& \& # open FILEHANDLE,MODE,EXPR # En lieu of a separate binmode() \& my $token = IO::Pager::open *STDOUT, \*(Aq|\-:utf8\*(Aq, \*(AqUnbuffered\*(Aq; \& \& \& print <<" HEREDOC" ; \& ... \& A bunch of text later \& HEREDOC \& \& # $token passes out of scope and filehandle is automagically closed \& } \& \& { \& # You can also use scalar filehandles... \& my $token = IO::Pager::open(my $FH) or warn($!); XXX \& print $FH "No globs or barewords for us thanks!\en" while 1; \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" IO::Pager can be used to locate an available pager and set the \fIPAGER\fR environment variable (see "NOTES"). It is also a factory for creating I/O objects such as IO::Pager::Buffered and IO::Pager::Unbuffered. .PP IO::Pager subclasses are designed to programmatically decide whether or not to pipe a filehandle's output to a program specified in \fIPAGER\fR. Subclasses may implement only the IO handle methods desired and inherit the remainder of those outlined below from IO::Pager. For anything else, YMMV. See the appropriate subclass for implementation specific details. .SH METHODS .IX Header "METHODS" .SS "new( FILEHANDLE, [MODE], [SUBCLASS] )" .IX Subsection "new( FILEHANDLE, [MODE], [SUBCLASS] )" Almost identical to open, except that you will get an IO::Handle back if there's no TTY to allow for IO::Pager\-agnostic programming. .SS "open( FILEHANDLE, [MODE], [SUBCLASS] )" .IX Subsection "open( FILEHANDLE, [MODE], [SUBCLASS] )" Instantiate a new IO::Pager, which will paginate output sent to FILEHANDLE if interacting with a TTY. .PP Save the return value to check for errors, use as an object, or for implict close of OO handles when the variable passes out of scope. .IP FILEHANDLE 4 .IX Item "FILEHANDLE" You may provide a glob or scalar. .Sp Defaults to currently \fBselect()\fR\-ed \fIFILEHANDLE\fR. .IP SUBCLASS 4 .IX Item "SUBCLASS" Specifies which variety of IO::Pager to create. This accepts fully qualified packages \fIIO::Pager::Buffered\fR, or simply the third portion of the package name \fIBuffered\fR for brevity. .Sp Defaults to IO::Pager::Unbuffered. .Sp Returns false and sets \fI$!\fR on failure, same as perl's \f(CW\*(C`open\*(C'\fR. .SS PID .IX Subsection "PID" Call this method on the token returned by \f(CW\*(C`open\*(C'\fR to get the process identifier for the child process i.e; pager; if you need to perform some long term process management e.g; perl's \f(CW\*(C`waitpid\*(C'\fR .PP You can also access the PID by numifying the instantiation token like so: .PP .Vb 1 \& my $child = $token+0; .Ve .SS "close( FILEHANDLE )" .IX Subsection "close( FILEHANDLE )" Explicitly close the filehandle, this stops any redirection of output on FILEHANDLE that may have been warranted. .PP \&\fIThis does not default to the current filehandle\fR. .PP Alternatively, you may rely upon the implicit close of lexical handles as they pass out of scope e.g; .PP .Vb 6 \& { \& IO::Pager::open local *RIBBIT; \& print RIBBIT "No toad sexing allowed"; \& ... \& } \& #The filehandle is closed to additional output \& \& { \& my $token = new IO::Pager::Buffered; \& $token\->print("I like trains"); \& ... \& } \& #The string "I like trains" is flushed to the pager, and the handle closed .Ve .SS "binmode( FILEHANDLE, [LAYER] )" .IX Subsection "binmode( FILEHANDLE, [LAYER] )" Used to set the I/O layer a.k.a. discipline of a filehandle, such as \f(CW\*(Aq:utf8\*(Aq\fR for UTF\-8 encoding. .PP \fI:LOG([>>FILE])\fR .IX Subsection ":LOG([>>FILE])" .PP IO::Pager implements a pseudo-IO-layer for capturing output and sending it to a file, similar to \fBtee\fR\|(1). Although it is limited to one file, this feature is pure-perl and adds no dependencies. .PP You may indicate what file to store in parentheses, otherwise the default is \&\f(CW\*(C`$$.log\*(C'\fR. You may also use an implicit (no indicator) or explicit (\fI>\fR) indicator to overwrite an existing file, or an explicit (\fI>>\fR) for appending to a log file. For example: .PP .Vb 3 \& binmode(*STDOUT, \*(Aq:LOG(clobber.log)\*(Aq); \& ... \& $STDOUT\->binmode(\*(Aq:LOG(>>noclobber.log)\*(Aq); .Ve .PP For full tee-style support, use PerlIO::Util like so: .PP .Vb 3 \& binmode(*STDOUT, ":tee(TH)"); \& #OR \& $STDOUT\->binmode(\*(Aq:tee(TH)\*(Aq); .Ve .SS "eof( FILEHANDLE )" .IX Subsection "eof( FILEHANDLE )" Used in the eval-until-eof idiom below, \fIIO::Pager\fR will handle broken pipes from deceased children for you in one of two ways. If \fR\f(CI$ENV\fR\fI{IP_EOF}\fR is false then program flow will pass out of the loop on \fISIGPIPE\fR, this is the default. If the variable is true, then the program continues running with output for the previously paged filehandle directed to the \fISTDOUT\fR stream; more accurately, the filehandle is reopened to file descriptor 1. .PP .Vb 7 \& use IO::Pager::Page; #or whichever you prefer; \& ... \& eval{ \& say "Producing prodigious portions of product"; \& ... \& } until( eof(*STDOUT) ); \& print "Cleaning up after our child before terminating." .Ve .PP If using \fBeof()\fR with less, especially when IP_EOF is set, you may want to use the \fI\-\-no\-init\fR option by setting \fR\f(CI$ENV\fR\fI{IP_EOF}='X'\fR to prevent the paged output from being erased when the pager exits. .SS "fileno( FILEHANDLE )" .IX Subsection "fileno( FILEHANDLE )" Return the filehandle number of the write-only pipe to the pager. .SS "print( FILEHANDLE LIST )" .IX Subsection "print( FILEHANDLE LIST )" \&\fBprint()\fR to the filehandle. .SS "printf( FILEHANDLE FORMAT, LIST )" .IX Subsection "printf( FILEHANDLE FORMAT, LIST )" \&\fBprintf()\fR to the filehandle. .SS "syswrite( FILEHANDLE, SCALAR, [LENGTH], [OFFSET] )" .IX Subsection "syswrite( FILEHANDLE, SCALAR, [LENGTH], [OFFSET] )" \&\fBsyswrite()\fR to the filehandle. .SH ENVIRONMENT .IX Header "ENVIRONMENT" .IP IP_EOF 4 .IX Item "IP_EOF" Controls IO:Pager behavior when \f(CW\*(C`eof\*(C'\fR is used. .IP PAGER 4 .IX Item "PAGER" The location of the default pager. .IP PATH 4 .IX Item "PATH" If the location in PAGER is not absolute, PATH may be searched. .Sp See "NOTES" for more information. .SH FILES .IX Header "FILES" IO::Pager may fall back to these binaries in order if \fIPAGER\fR is not executable. .IP /etc/alternatives/pager 4 .IX Item "/etc/alternatives/pager" .PD 0 .IP /usr/local/bin/less 4 .IX Item "/usr/local/bin/less" .IP /usr/bin/less 4 .IX Item "/usr/bin/less" .ie n .IP "IO::Pager::Perl as ""tp"" via IO::Pager::less" 4 .el .IP "IO::Pager::Perl as \f(CWtp\fR via IO::Pager::less" 4 .IX Item "IO::Pager::Perl as tp via IO::Pager::less" .IP /usr/bin/more 4 .IX Item "/usr/bin/more" .PD .PP See "NOTES" for more information. .SH NOTES .IX Header "NOTES" The algorithm for determining which pager to use is as follows: .IP "1. Defer to \fIPAGER\fR" 4 .IX Item "1. Defer to PAGER" If the \fIPAGER\fR environment variable is set, use the pager it identifies, unless this pager is not available. .IP "2. Usual suspects" 4 .IX Item "2. Usual suspects" Try the standard, hardcoded paths in "FILES". .IP "3. File::Which" 4 .IX Item "3. File::Which" If File::Which is available, use the first pager possible amongst \&\f(CW\*(C`less\*(C'\fR, \f(CW\*(C`most\*(C'\fR, \f(CW\*(C`w3m\*(C'\fR, \f(CW\*(C`lv\*(C'\fR, \f(CW\*(C`pg\*(C'\fR and more. .IP "4. Term::Pager via IO::Pager::Perl" 4 .IX Item "4. Term::Pager via IO::Pager::Perl" You may also set \f(CW$ENV\fR{PAGER} to Term::Pager to select this extensible, pure perl pager for display. .IP "5. more" 4 .IX Item "5. more" Set \fIPAGER\fR to \f(CW\*(C`more\*(C'\fR, and cross our fingers. .PP Steps 1, 3 and 5 rely upon the \fIPATH\fR environment variable. .SH CAVEATS .IX Header "CAVEATS" You probably want to do something with SIGPIPE eg; .PP .Vb 3 \& eval { \& local $SIG{PIPE} = sub { die }; \& local $STDOUT = IO::Pager::open(*STDOUT); \& \& while (1) { \& # Do something \& } \& } \& \& # Do something else .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" IO::Pager::Buffered, IO::Pager::Unbuffered, I::Pager::Perl, IO::Pager::Page, IO::Page, Meta::Tool::Less .SH AUTHOR .IX Header "AUTHOR" Jerrad Pierce .PP Florent Angly .PP This module was inspired by Monte Mitzelfelt's IO::Page 0.02 .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2003\-2020 Jerrad Pierce .IP \(bu 4 Thou shalt not claim ownership of unmodified materials. .IP \(bu 4 Thou shalt not claim whole ownership of modified materials. .IP \(bu 4 Thou shalt grant the indemnity of the provider of materials. .IP \(bu 4 Thou shalt use and dispense freely without other restrictions. .PP Or, if you prefer: .PP 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.