1IO::Pager(3)          User Contributed Perl Documentation         IO::Pager(3)
2
3
4

NAME

6       IO::Pager - Select a pager (possibly perl-based) & pipe it text if a
7       TTY
8

SYNOPSIS

10         # Select an appropriate pager and set the PAGER environment variable
11         use IO::Pager;
12
13         # TIMTOWTDI Object-oriented
14         {
15           # open()                           # Use all the defaults.
16           my $object = new IO::Pager;
17
18           # open FILEHANDLE                  # Unbuffered is default subclass
19           my $object = new IO::Pager *STDOUT;
20
21           # open FILEHANDLE,EXPR             # Specify subclass
22           my $object = new IO::Pager *STDOUT,  'Unbuffered';
23
24           # Direct subclass instantiation    # FH is optional
25           use IO::Pager::Unbuffered;
26           my $object = new IO::Pager::Unbuffered  *STDOUT;
27
28
29           $object->print("OO shiny...\n") while 1;
30           print "Some other text sent to STODUT, perhaps from a foreign routine."
31
32           # $object passes out of scope and filehandle is automagically closed
33         }
34
35         # TIMTOWTDI Procedural
36         {
37           # open FILEHANDLE                    # Unbuffered is default subclass
38           my $token = IO::Pager::open *STDOUT;
39
40           # open FILEHANDLE,EXPR               # Specify subclass
41           my $token = IO::Pager::open *STDOUT,  'Unbuffered';
42
43           # open FILEHANDLE,MODE,EXPR          # En lieu of a separate binmode()
44           my $token = IO::Pager::open *STDOUT, '|-:utf8', 'Unbuffered';
45
46
47           print <<"  HEREDOC" ;
48           ...
49           A bunch of text later
50           HEREDOC
51
52           # $token passes out of scope and filehandle is automagically closed
53         }
54
55         {
56           # You can also use scalar filehandles...
57           my $token = IO::Pager::open(my $FH) or warn($!); XXX
58           print $FH "No globs or barewords for us thanks!\n" while 1;
59         }
60

DESCRIPTION

62       IO::Pager can be used to locate an available pager and set the PAGER
63       environment variable (see "NOTES"). It is also a factory for creating
64       I/O objects such as IO::Pager::Buffered and IO::Pager::Unbuffered.
65
66       IO::Pager subclasses are designed to programmatically decide whether or
67       not to pipe a filehandle's output to a program specified in PAGER.
68       Subclasses may implement only the IO handle methods desired and inherit
69       the remainder of those outlined below from IO::Pager. For anything
70       else, YMMV. See the appropriate subclass for implementation specific
71       details.
72

METHODS

74   new( FILEHANDLE, [MODE], [SUBCLASS] )
75       Almost identical to open, except that you will get an IO::Handle back
76       if there's no TTY to allow for IO::Pager-agnostic programming.
77
78   open( FILEHANDLE, [MODE], [SUBCLASS] )
79       Instantiate a new IO::Pager, which will paginate output sent to
80       FILEHANDLE if interacting with a TTY.
81
82       Save the return value to check for errors, use as an object, or for
83       implict close of OO handles when the variable passes out of scope.
84
85       FILEHANDLE
86           You may provide a glob or scalar.
87
88           Defaults to currently select()-ed FILEHANDLE.
89
90       SUBCLASS
91           Specifies which variety of IO::Pager to create.  This accepts fully
92           qualified packages IO::Pager::Buffered, or simply the third portion
93           of the package name Buffered for brevity.
94
95           Defaults to IO::Pager::Unbuffered.
96
97           Returns false and sets $! on failure, same as perl's "open".
98
99   PID
100       Call this method on the token returned by "open" to get the process
101       identifier for the child process i.e; pager; if you need to perform
102       some long term process management e.g; perl's "waitpid"
103
104       You can also access the PID by numifying the instantiation token like
105       so:
106
107         my $child = $token+0;
108
109   close( FILEHANDLE )
110       Explicitly close the filehandle, this stops any redirection of output
111       on FILEHANDLE that may have been warranted.
112
113       This does not default to the current filehandle.
114
115       Alternatively, you may rely upon the implicit close of lexical handles
116       as they pass out of scope e.g;
117
118         {
119            IO::Pager::open local *RIBBIT;
120            print RIBBIT "No toad sexing allowed";
121            ...
122         }
123         #The filehandle is closed to additional output
124
125         {
126            my $token = new IO::Pager::Buffered;
127            $token->print("I like trains");
128            ...
129         }
130         #The string "I like trains" is flushed to the pager, and the handle closed
131
132   binmode( FILEHANDLE, [LAYER] )
133       Used to set the I/O layer a.k.a. discipline of a filehandle, such as
134       ':utf8' for UTF-8 encoding.
135
136       :LOG([>>FILE])
137
138       IO::Pager implements a pseudo-IO-layer for capturing output and sending
139       it to a file, similar to tee(1). Although it is limited to one file,
140       this feature is pure-perl and adds no dependencies.
141
142       You may indicate what file to store in parentheses, otherwise the
143       default is "$$.log". You may also use an implicit (no indicator) or
144       explicit (>) indicator to overwrite an existing file, or an explicit
145       (>>) for appending to a log file. For example:
146
147           binmode(*STDOUT, ':LOG(clobber.log)');
148           ...
149           $STDOUT->binmode(':LOG(>>noclobber.log)');
150
151       For full tee-style support, use PerlIO::Util like so:
152
153           binmode(*STDOUT, ":tee(TH)");
154           #OR
155           $STDOUT->binmode(':tee(TH)');
156
157   eof( FILEHANDLE )
158       Used in the eval-until-eof idiom below, IO::Pager will handle broken
159       pipes from deceased children for you in one of two ways. If
160       $ENV{IP_EOF} is false then program flow will pass out of the loop on
161       SIGPIPE, this is the default. If the variable is true, then the program
162       continues running with output for the previously paged filehandle
163       directed to the STDOUT stream; more accurately, the filehandle is
164       reopened to file descriptor 1.
165
166         use IO::Pager::Page; #or whichever you prefer;
167         ...
168         eval{
169           say "Producing prodigious portions of product";
170           ...
171         } until( eof(*STDOUT) );
172         print "Cleaning up after our child before terminating."
173
174       If using eof() with less, especially when IP_EOF is set, you may want
175       to use the --no-init option by setting $ENV{IP_EOF}='X' to prevent the
176       paged output from being erased when the pager exits.
177
178   fileno( FILEHANDLE )
179       Return the filehandle number of the write-only pipe to the pager.
180
181   print( FILEHANDLE LIST )
182       print() to the filehandle.
183
184   printf( FILEHANDLE FORMAT, LIST )
185       printf() to the filehandle.
186
187   syswrite( FILEHANDLE, SCALAR, [LENGTH], [OFFSET] )
188       syswrite() to the filehandle.
189

ENVIRONMENT

191       IP_EOF
192           Controls IO:Pager behavior when "eof" is used.
193
194       PAGER
195           The location of the default pager.
196
197       PATH
198           If the location in PAGER is not absolute, PATH may be searched.
199
200           See "NOTES" for more information.
201

FILES

203       IO::Pager may fall back to these binaries in order if PAGER is not
204       executable.
205
206       /etc/alternatives/pager
207       /usr/local/bin/less
208       /usr/bin/less
209       IO::Pager::Perl as "tp" via IO::Pager::less
210       /usr/bin/more
211
212       See "NOTES" for more information.
213

NOTES

215       The algorithm for determining which pager to use is as follows:
216
217       1. Defer to PAGER
218           If the PAGER environment variable is set, use the pager it
219           identifies, unless this pager is not available.
220
221       2. Usual suspects
222           Try the standard, hardcoded paths in "FILES".
223
224       3. File::Which
225           If File::Which is available, use the first pager possible amongst
226           "less", "most", "w3m", "lv", "pg" and more.
227
228       4. Term::Pager via IO::Pager::Perl
229           You may also set $ENV{PAGER} to Term::Pager to select this
230           extensible, pure perl pager for display.
231
232       5. more
233           Set PAGER to "more", and cross our fingers.
234
235       Steps 1, 3 and 5 rely upon the PATH environment variable.
236

CAVEATS

238       You probably want to do something with SIGPIPE eg;
239
240         eval {
241           local $SIG{PIPE} = sub { die };
242           local $STDOUT = IO::Pager::open(*STDOUT);
243
244           while (1) {
245             # Do something
246           }
247         }
248
249         # Do something else
250

SEE ALSO

252       IO::Pager::Buffered, IO::Pager::Unbuffered, I::Pager::Perl,
253       IO::Pager::Page, IO::Page, Meta::Tool::Less
254

AUTHOR

256       Jerrad Pierce <jpierce@cpan.org>
257
258       Florent Angly <florent.angly@gmail.com>
259
260       This module was inspired by Monte Mitzelfelt's IO::Page 0.02
261
263       Copyright (C) 2003-2020 Jerrad Pierce
264
265       •   Thou shalt not claim ownership of unmodified materials.
266
267       •   Thou shalt not claim whole ownership of modified materials.
268
269       •   Thou shalt grant the indemnity of the provider of materials.
270
271       •   Thou shalt use and dispense freely without other restrictions.
272
273       Or, if you prefer:
274
275       This library is free software; you can redistribute it and/or modify it
276       under the same terms as Perl itself, either Perl version 5.0 or, at
277       your option, any later version of Perl 5 you may have available.
278
279
280
281perl v5.38.0                      2023-07-20                      IO::Pager(3)
Impressum