.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "IO::Interactive 3pm" .TH IO::Interactive 3pm "2016-10-30" "perl v5.24.1" "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::Interactive \- Utilities for interactive I/O .SH "VERSION" .IX Header "VERSION" This document describes IO::Interactive version 1.02 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use IO::Interactive qw(is_interactive interactive busy); \& \& if ( is_interactive() ) { \& print "Running interactively\en"; \& } \& \& # or... \& \& print {interactive} "Running interactively\en"; \& \& \& $fh = busy { \& do_noninteractive_stuff(); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides three utility subroutines that make it easier to develop interactive applications... .ie n .IP """is_interactive()""" 4 .el .IP "\f(CWis_interactive()\fR" 4 .IX Item "is_interactive()" This subroutine returns true if \f(CW*ARGV\fR and the currently selected filehandle (usually \f(CW*STDOUT\fR) are connected to the terminal. The test is considerably more sophisticated than: .Sp .Vb 1 \& \-t *ARGV && \-t *STDOUT .Ve .Sp as it takes into account the magic behaviour of \f(CW*ARGV\fR. .Sp You can also pass \f(CW\*(C`is_interactive\*(C'\fR a writable filehandle, in which case it requires that filehandle be connected to a terminal (instead of the currently selected). The usual suspect here is \f(CW*STDERR\fR: .Sp .Vb 3 \& if ( is_interactive(*STDERR) ) { \& carp $warning; \& } .Ve .ie n .IP """interactive()""" 4 .el .IP "\f(CWinteractive()\fR" 4 .IX Item "interactive()" This subroutine returns \f(CW*STDOUT\fR if \f(CW\*(C`is_interactive\*(C'\fR is true. If \&\f(CW\*(C`is_interactive()\*(C'\fR is false, \f(CW\*(C`interactive\*(C'\fR returns a filehandle that does not print. .Sp This makes it easy to create applications that print out only when the application is interactive: .Sp .Vb 2 \& print {interactive} "Please enter a value: "; \& my $value = <>; .Ve .Sp You can also pass \f(CW\*(C`interactive\*(C'\fR a writable filehandle, in which case it writes to that filehandle if it is connected to a terminal (instead of writing to \f(CW*STDOUT\fR). Once again, the usual suspect is \f(CW*STDERR\fR: .Sp .Vb 1 \& print {interactive(*STDERR)} $warning; .Ve .ie n .IP """busy {...}""" 4 .el .IP "\f(CWbusy {...}\fR" 4 .IX Item "busy {...}" This subroutine takes a block as its single argument and executes that block. Whilst the block is executed, \f(CW*ARGV\fR is temporarily replaced by a closed filehandle. That is, no input from \f(CW*ARGV\fR is possible in a \f(CW\*(C`busy\*(C'\fR block. Furthermore, any attempts to send input into the \f(CW\*(C`busy\*(C'\fR block through \&\f(CW*ARGV\fR is intercepted and a warning message is printed to \f(CW*STDERR\fR. The \f(CW\*(C`busy\*(C'\fR call returns a filehandle that contains the intercepted input. .Sp A \f(CW\*(C`busy\*(C'\fR block is therefore useful to prevent attempts at input when the program is busy at some non-interactive task. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .IP "Unknown subroutine (%s) requested" 4 .IX Item "Unknown subroutine (%s) requested" This module only exports the three subroutines described above. You asked for something else. Maybe you misspelled the subroutine you wanted. .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" IO::Interactive requires no configuration files or environment variables. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" This module requires the \f(CW\*(C`openhandle()\*(C'\fR subroutine from the Scalar::Util module. .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" None reported. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" No bugs have been reported. .PP Please report any bugs or feature requests to Github . .SH "SOURCE AVAILABILITY" .IX Header "SOURCE AVAILABILITY" This code is in GitHub: .PP .Vb 1 \& https://github.com/briandfoy/io\-interactive .Ve .SH "AUTHOR" .IX Header "AUTHOR" Damian Conway \f(CW\*(C`\*(C'\fR .PP Currently maintained by brian d foy \f(CW\*(C`\*(C'\fR. .PP 1.01 patch \s-1DMUEY \s0\f(CW\*(C`dmuey@cpan.org\*(C'\fR .SH "LICENCE AND COPYRIGHT" .IX Header "LICENCE AND COPYRIGHT" Copyright (c) 2005, Damian Conway \f(CW\*(C`\*(C'\fR. All rights reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "DISCLAIMER OF WARRANTY" .IX Header "DISCLAIMER OF WARRANTY" \&\s-1BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE \*(L"AS IS\*(R" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.\s0 .PP \&\s-1IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE \s0(\s-1INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE\s0), \s-1EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\s0