1Term::ReadLine(3pm)    Perl Programmers Reference Guide    Term::ReadLine(3pm)
2
3
4

NAME

6       Term::ReadLine - Perl interface to various "readline" packages.  If no
7       real package is found, substitutes stubs instead of basic functions.
8

SYNOPSIS

10         use Term::ReadLine;
11         my $term = Term::ReadLine->new('Simple Perl calc');
12         my $prompt = "Enter your arithmetic expression: ";
13         my $OUT = $term->OUT || \*STDOUT;
14         while ( defined ($_ = $term->readline($prompt)) ) {
15           my $res = eval($_);
16           warn $@ if $@;
17           print $OUT $res, "\n" unless $@;
18           $term->addhistory($_) if /\S/;
19         }
20

DESCRIPTION

22       This package is just a front end to some other packages. It's a stub to
23       set up a common interface to the various ReadLine implementations found
24       on CPAN (under the "Term::ReadLine::*" namespace).
25

Minimal set of supported functions

27       All the supported functions should be called as methods, i.e., either
28       as
29
30         $term = Term::ReadLine->new('name');
31
32       or as
33
34         $term->addhistory('row');
35
36       where $term is a return value of Term::ReadLine->new().
37
38       "ReadLine"  returns the actual package that executes the commands.
39                   Among possible values are "Term::ReadLine::Gnu",
40                   "Term::ReadLine::Perl", "Term::ReadLine::Stub".
41
42       "new"       returns the handle for subsequent calls to following
43                   functions. Argument is the name of the application.
44                   Optionally can be followed by two arguments for "IN" and
45                   "OUT" filehandles. These arguments should be globs.
46
47       "readline"  gets an input line, possibly with actual "readline"
48                   support. Trailing newline is removed. Returns "undef" on
49                   "EOF".
50
51       "addhistory"
52                   adds the line to the history of input, from where it can be
53                   used if the actual "readline" is present.
54
55       "IN", "OUT" return the filehandles for input and output or "undef" if
56                   "readline" input and output cannot be used for Perl.
57
58       "MinLine"   If argument is specified, it is an advice on minimal size
59                   of line to be included into history.  "undef" means do not
60                   include anything into history. Returns the old value.
61
62       "findConsole"
63                   returns an array with two strings that give most
64                   appropriate names for files for input and output using
65                   conventions "<$in", ">out".
66
67       Attribs     returns a reference to a hash which describes internal
68                   configuration of the package. Names of keys in this hash
69                   conform to standard conventions with the leading "rl_"
70                   stripped.
71
72       "Features"  Returns a reference to a hash with keys being features
73                   present in current implementation. Several optional
74                   features are used in the minimal interface: "appname"
75                   should be present if the first argument to "new" is
76                   recognized, and "minline" should be present if "MinLine"
77                   method is not dummy.  "autohistory" should be present if
78                   lines are put into history automatically (maybe subject to
79                   "MinLine"), and "addhistory" if "addhistory" method is not
80                   dummy.
81
82                   If "Features" method reports a feature "attribs" as
83                   present, the method "Attribs" is not dummy.
84

Additional supported functions

86       Actually "Term::ReadLine" can use some other package, that will support
87       a richer set of commands.
88
89       All these commands are callable via method interface and have names
90       which conform to standard conventions with the leading "rl_" stripped.
91
92       The stub package included with the perl distribution allows some
93       additional methods:
94
95       "tkRunning" makes Tk event loop run when waiting for user input (i.e.,
96                   during "readline" method).
97
98       "ornaments" makes the command line stand out by using termcap data.
99                   The argument to "ornaments" should be 0, 1, or a string of
100                   a form "aa,bb,cc,dd".  Four components of this string
101                   should be names of terminal capacities, first two will be
102                   issued to make the prompt standout, last two to make the
103                   input line standout.
104
105       "newTTY"    takes two arguments which are input filehandle and output
106                   filehandle.  Switches to use these filehandles.
107
108       One can check whether the currently loaded ReadLine package supports
109       these methods by checking for corresponding "Features".
110

EXPORTS

112       None
113

ENVIRONMENT

115       The environment variable "PERL_RL" governs which ReadLine clone is
116       loaded. If the value is false, a dummy interface is used. If the value
117       is true, it should be tail of the name of the package to use, such as
118       "Perl" or "Gnu".
119
120       As a special case, if the value of this variable is space-separated,
121       the tail might be used to disable the ornaments by setting the tail to
122       be "o=0" or "ornaments=0".  The head should be as described above, say
123
124       If the variable is not set, or if the head of space-separated list is
125       empty, the best available package is loaded.
126
127         export "PERL_RL=Perl o=0"     # Use Perl ReadLine without ornaments
128         export "PERL_RL= o=0"         # Use best available ReadLine without ornaments
129
130       (Note that processing of "PERL_RL" for ornaments is in the discretion
131       of the particular used "Term::ReadLine::*" package).
132

CAVEATS

134       It seems that using Term::ReadLine from Emacs minibuffer doesn't work
135       quite right and one will get an error message like
136
137           Cannot open /dev/tty for read at ...
138
139       One possible workaround for this is to explicitly open /dev/tty like
140       this
141
142           open (FH, "/dev/tty" )
143             or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }';
144           die $@ if $@;
145           close (FH);
146
147       or you can try using the 4-argument form of Term::ReadLine->new().
148
149
150
151perl v5.12.4                      2011-06-07               Term::ReadLine(3pm)
Impressum