perldoc > Term::ReadLine

📛 NAME

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

🚀 Quick Reference

Use CaseCommandDescription
📦 Create readline objectTerm::ReadLine->new('name')Returns handle for subsequent calls; optional IN/OUT filehandles
📝 Read a line$term->readline($prompt)Gets an input line, possibly with readline support; trailing newline removed
📜 Add to history$term->addhistory($line)Adds line to history for later recall
🎨 Set ornaments$term->ornaments(0) or 1 or "aa,bb,cc,dd"Control terminal standout for prompt/input
🔄 Event loop integration$term->event_loop($wait_cb, $register_cb)Register callbacks for waiting on input (e.g., AnyEvent, Tk)
🔧 Get filehandles$term->IN / $term->OUTReturns input/output filehandles or undef
⚙️ Check features$term->FeaturesReturns hash of available features (appname, minline, autohistory, addhistory, attribs)

📝 SYNOPSIS

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

📖 DESCRIPTION

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

🧩 Minimal set of supported functions

All the supported functions should be called as methods, i.e., either as

  $term = Term::ReadLine->new('name');

or as

  $term->addhistory('row');

where $term is a return value of Term::ReadLine->new().

➕ Additional supported functions

Actually "Term::ReadLine" can use some other package, that will support a richer set of commands. All these commands are callable via method interface and have names which conform to standard conventions with the leading "rl_" stripped.

The stub package included with the perl distribution allows some additional methods:

  $term->event_loop(sub {
    my $data = shift;
    $data->[1] = AE::cv();
    $data->[1]->recv();
  }, sub {
    my $fh = shift;
    my $data = [];
    $data->[0] = AE::io($fh, 0, sub { $data->[1]->send() });
    $data;
  });

The second call-back is optional if the call back is registered prior to the call to $term->readline. Deregistration is done by calling event_loop with "undef":

  $term->event_loop(undef);

This will cause the data array ref to be removed, allowing normal garbage collection. With AnyEvent, that will cause $data->[0] to be cleaned up, and AnyEvent will automatically cancel the watcher. If another loop requires more than that to clean up a file watcher, that will be up to the caller to handle.

One can check whether the currently loaded ReadLine package supports these methods by checking for corresponding Features.

📦 EXPORTS

None

🌍 ENVIRONMENT

The environment variable PERL_RL governs which ReadLine clone is loaded. If the value is false, a dummy interface is used. If the value is true, it should be the tail of the name of the package to use, such as "Perl" or "Gnu".

As a special case, if the value of this variable is space-separated, the tail might be used to disable the ornaments by setting the tail to be "o=0" or "ornaments=0". The head should be as described above, say

If the variable is not set, or if the head of space-separated list is empty, the best available package is loaded.

  export "PERL_RL=Perl o=0" # Use Perl ReadLine sans ornaments
  export "PERL_RL= o=0"     # Use best available ReadLine sans ornaments

(Note that processing of PERL_RL for ornaments is in the discretion of the particular used Term::ReadLine::* package).

Term::ReadLine
📛 NAME 🚀 Quick Reference 📝 SYNOPSIS 📖 DESCRIPTION 🧩 Minimal set of supported functions ➕ Additional supported functions 📦 EXPORTS 🌍 ENVIRONMENT

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-01 11:23 @216.73.216.124
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^