new

new([%options])

returns the handle for subsequent calls to following functions. Argument is the name of the application.

NAME

Term::ReadLine::Perl5::OO - OO version of Term::ReadLine::Perl5

SYNOPSIS

    use Term::ReadLine::Perl5::OO;

    my $c = Term::ReadLine::Perl5::OO->new;
    while (defined(my $line = $c->readline('> '))) {
        if ($line =~ /\S/) {
            print eval $line;
        }
    }

DESCRIPTION

An Object-Oriented GNU Readline line editing library like Term::ReadLine::Perl5.

This module

has History handling
has programmable command Completion
is Portable
has no C library dependency

Nested keymap is not fully supported yet.

METHODS

new

   my $term = Term::ReadLine::Perl5::OO->new();

Create new Term::ReadLine::Perl5::OO instance.

Options are:

completion_callback : CodeRef

You can write completion callback function like this:

    use Term::ReadLine::Perl5::OO;
    my $c = Term::ReadLine::Perl5::OO->new(
        completion_callback => sub {
            my ($line) = @_;
            if ($line eq 'h') {
                return (
                    'hello',
                    'hello there'
                );
            } elsif ($line eq 'm') {
                return (
                    '突然のmattn'
                );
            }
            return;
        },
    );

read

   my $line = $term->read($prompt);

Read line with $prompt.

Trailing newline is removed. Returns undef on EOF.

history

   $term->history()

Get the current history data in ArrayRef[Str] .

write_history

   $term->write_history($filename)

Write history data to the file.

read_history

   $term->read_history($filename)

Read history data from history file.

Multi byte character support

If you want to support multi byte characters, you need to set binmode to STDIN. You can add the following code before call Term::ReadLine::Perl5::OO

    use Term::Encoding qw(term_encoding);
    my $encoding = term_encoding();
    binmode *STDIN, ":encoding(${encoding})";

About east Asian ambiguous width characters

Term::ReadLine::Perl5::OO detects east Asian ambiguous character width from environment variable using Unicode::EastAsianWidth::Detect.

User need to set locale correctly. For more details, please read Unicode::EastAsianWidth::Detect.

LICENSE

Copyright (C) tokuhirom. Copyright (C) Rocky Bernstein.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

AUTHOR

tokuhirom <tokuhirom@gmail.com> mattn

Extended and rewritten to make more compatible with GNU ReadLine and Term::ReadLine::Perl5 by Rocky Bernstein