NAME
Term::ReadLine - Perl interface to various readline
packages. If no real package is found, substitutes stubs instead of basic functions.
SYNOPSIS
use Term::ReadLine;
$term = new Term::ReadLine 'Simple Perl calc';
$prompt = "Enter your arithmetic expression: ";
$OUT = $term->OUT || STDOUT;
while ( defined ($_ = $term->readline($prompt)) ) {
$res = eval($_), "\n";
warn $@ if $@;
print $OUT $res, "\n" unless $@;
$term->addhistory($_) if /\S/;
}
DESCRIPTION
Minimal set of supported functions
All the supported functions should be called as methods, i.e., either as
$term = new Term::ReadLine 'name';
or as
$term->addhistory('row');
where $term is a return value of Term::ReadLine->Init.
ReadLine
-
returns the actual package that executes the commands. Among possible values are
Term::ReadLine::Gnu
,Term::ReadLine::Perl
,Term::ReadLine::Stub Exporter
. new
-
returns the handle for subsequent calls to following functions. Argument is the name of the application. Optionally can be followed by two arguments for
IN
andOUT
filehandles. These arguments should be globs. readline(prompt[, preput])
-
gets an input line, possibly with actual
readline
support. Trailing newline is removed. Returnsundef
onEOF
.preput
is an optional argument meaning the initial value of input. The optional argument is granted only if the valuepreput
is inFeatures
. addhistory(line1, line2, ...)
-
adds the lines to the history of input, from where it can be used if the actual
readline
is present. SetHistory(line1, line2, ...)
-
sets the history of input, from where it can be used if the actual
readline
is present. GetHistory
-
returns the history of input as a list, if actual
readline
is present. IN
,OUT
-
return the filehandles for input and output or
undef
ifreadline
input and output cannot be used for Perl. MinLine
-
If argument is specified, it is an advice on minimal size of line to be included into history.
undef
means do not include anything into history. Returns the old value. findConsole
-
returns an array with two strings that give most appropriate names for files for input and output using conventions
"<$in"
,">out"
. Features
-
Returns a reference to a hash with keys being features present in current implementation. Several optional features are used in the minimal interface:
appname
should be present if the first argument tonew
is recognized, andminline
should be present ifMinLine
method is not dummy.autohistory
should be present if lines are put into history automatically (maybe subject toMinLine
), andaddhistory
ifaddhistory
method is not dummy.preput
means the second argument toreadline
method is processed.getHistory
andsetHistory
denote that the corresponding methods are present.tkRunning
denotes that a Tk application may run while ReadLine is getting input (undocumented feature).
Actually Term::ReadLine
can use some other package, that will support reacher set of commands.
EXPORTS
None