You are viewing the version of this documentation from Perl 5.22.4. View the latest version

CONTENTS

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;
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().

ReadLine

returns the actual package that executes the commands. Among possible values are Term::ReadLine::Gnu, Term::ReadLine::Perl, Term::ReadLine::Stub.

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 and OUT filehandles. These arguments should be globs.

readline

gets an input line, possibly with actual readline support. Trailing newline is removed. Returns undef on EOF.

addhistory

adds the line to the history of input, from where it can be used if the actual readline is present.