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

NAME

6       IO::Interactive - Utilities for interactive I/O
7

VERSION

9       This document describes IO::Interactive version 1.02
10

SYNOPSIS

12           use IO::Interactive qw(is_interactive interactive busy);
13
14           if ( is_interactive() ) {
15               print "Running interactively\n";
16           }
17
18           # or...
19
20           print {interactive} "Running interactively\n";
21
22
23           $fh = busy {
24               do_noninteractive_stuff();
25           }
26

DESCRIPTION

28       This module provides three utility subroutines that make it easier to
29       develop interactive applications.
30
31       The "ARGV" filehandle, the one that "<>" or an empty "readline()" uses,
32       has various magic associated with it. It's not actually opened until
33       you try to read from it. Checking "-t ARGV" before you've tried to read
34       from it might give you the wrong answer.  Not only that, you might not
35       read from "ARGV". If the value in @ARGV is the magic filename "-" (a
36       convention to mean the standard filehandle for input or output), "ARGV"
37       might actually be "STDIN".  You don't want to think about all of this.
38       This module is discussed in Perl Best Practices on page 218. Also see
39       the "ARGV" entry in perlvar and the "readline" entry in perlfunc.
40
41       "is_interactive()"
42           This subroutine returns true if *ARGV and the currently selected
43           filehandle (usually *STDOUT) are connected to the terminal. The
44           test is considerably more sophisticated than:
45
46               -t *ARGV && -t *STDOUT
47
48           as it takes into account the magic behaviour of *ARGV.
49
50           You can also pass "is_interactive" a writable filehandle, in which
51           case it requires that filehandle be connected to a terminal
52           (instead of the currently selected).  The usual suspect here is
53           *STDERR:
54
55               if ( is_interactive(*STDERR) ) {
56                   carp $warning;
57               }
58
59       "interactive()"
60           This subroutine returns *STDOUT if "is_interactive" is true. If
61           "is_interactive()" is false, "interactive" returns a filehandle
62           that does not print.
63
64           This makes it easy to create applications that print out only when
65           the application is interactive:
66
67               print {interactive} "Please enter a value: ";
68               my $value = <>;
69
70           You can also pass "interactive" a writable filehandle, in which
71           case it writes to that filehandle if it is connected to a terminal
72           (instead of writing to *STDOUT). Once again, the usual suspect is
73           *STDERR:
74
75               print {interactive(*STDERR)} $warning;
76
77       "busy {...}"
78           This subroutine takes a block as its single argument and executes
79           that block.  Whilst the block is executed, *ARGV is temporarily
80           replaced by a closed filehandle. That is, no input from *ARGV is
81           possible in a "busy" block.  Furthermore, any attempts to send
82           input into the "busy" block through *ARGV is intercepted and a
83           warning message is printed to *STDERR.  The "busy" call returns a
84           filehandle that contains the intercepted input.
85
86           A "busy" block is therefore useful to prevent attempts at input
87           when the program is busy at some non-interactive task.
88

DIAGNOSTICS

90       Unknown subroutine (%s) requested
91           This module only exports the three subroutines described above.
92           You asked for something else. Maybe you misspelled the subroutine
93           you wanted.
94

CONFIGURATION AND ENVIRONMENT

96       IO::Interactive requires no configuration files or environment
97       variables.
98

DEPENDENCIES

100       This module requires the "openhandle()" subroutine from the
101       Scalar::Util module.
102

INCOMPATIBILITIES

104       None reported.
105

BUGS AND LIMITATIONS

107       No bugs have been reported.
108
109       Please report any bugs or feature requests to Github
110       <https://github.com/briandfoy/io-interactive/issues>.
111

SOURCE AVAILABILITY

113       This code is in GitHub:
114
115               https://github.com/briandfoy/io-interactive
116

AUTHOR

118       Damian Conway  "<DCONWAY@cpan.org>"
119
120       Currently maintained by brian d foy "<bdfoy@cpan.org>".
121
122       1.01 patch DMUEY "dmuey@cpan.org"
123
125       Copyright © 2005-2021, Damian Conway "<DCONWAY@cpan.org>". All rights
126       reserved.
127
128       This module is free software; you can redistribute it and/or modify it
129       under the same terms as Perl itself.
130

DISCLAIMER OF WARRANTY

132       BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
133       FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
134       WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
135       PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
136       EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
137       WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
138       ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
139       YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
140       NECESSARY SERVICING, REPAIR, OR CORRECTION.
141
142       IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
143       WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
144       REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
145       TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
146       CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
147       SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
148       RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
149       FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
150       SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
151       DAMAGES.
152
153
154
155perl v5.34.0                      2021-07-22                IO::Interactive(3)
Impressum