| 1 | package Term::ReadLine::Perl5::Dumb; | ||||||||||
| 2 | 11 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Term::ReadLine::Perl5::Dumb | ||||||||||
| 6 | |||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||
| 8 | |||||||||||
| 9 | A non-OO package for dumb terminals similar to GNU's readline. The | ||||||||||
| 10 | preferred OO Package is L<Term::ReadLine::Perl5>. | ||||||||||
| 11 | |||||||||||
| 12 | Since L<Term::ReadLine::Perl5::readline> currently has global state, | ||||||||||
| 13 | when more than one interface is created, we fallback to this code. | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | 11 | ▶ | eval "use rlib '.' "; # rlib is now optional | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 11 | ▶ | use Term::ReadLine::Perl5::History; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | sub get_line($) { | ||||||||||
| 21 | 0 | ▶ | my $term_IN = shift; | ||||||||
|
Subroutine
get_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | 0 | scalar <$term_IN>; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | =head1 SUBROUTINES | ||||||||||
| 26 | |||||||||||
| 27 | =head2 readline | ||||||||||
| 28 | |||||||||||
| 29 | B<readline>(I<$prompt>, [I<$in>, [I<$out>]]) | ||||||||||
| 30 | |||||||||||
| 31 | A version readline for a dumb terminal, that is one that doesn't have | ||||||||||
| 32 | many terminal editing capabilities. I<$prompt> is the prompt to | ||||||||||
| 33 | display; optional arguments I<$in> and I<$out> specify input and | ||||||||||
| 34 | output file handles. I<STDIN> and I<STDOUT> are used when the | ||||||||||
| 35 | corresponding file handles are not given. | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | sub readline($;$$) | ||||||||||
| 40 | { | ||||||||||
| 41 | 0 | ▶ | my ($prompt, $term_IN, $term_OUT) = @_; | ||||||||
|
Subroutine
readline: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 42 | 0 | ▶ | $term_IN = \*STDIN unless defined $term_IN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | ▶ | $term_OUT = \*STDOUT unless defined $term_OUT; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | my $old = select $term_OUT; | |||||||||
| 45 | 0 | local $\ = ''; | |||||||||
| 46 | 0 | local $| = 1; | |||||||||
| 47 | 0 | print $term_OUT $prompt; | |||||||||
| 48 | 0 | local $/ = "\n"; | |||||||||
| 49 | 0 | my $line; | |||||||||
| 50 | 0 | ▶ | if (!defined($line = get_line($term_IN))) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | select $old; | |||||||||
| 52 | 0 | return undef; | |||||||||
| 53 | } | ||||||||||
| 54 | 0 | select $old; | |||||||||
| 55 | 0 | chomp($line); | |||||||||
| 56 | 0 | return $line; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =head1 SEE ALSO | ||||||||||
| 60 | |||||||||||
| 61 | L<Term::ReadLine::Perl5> | ||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 11 | 1; | |||||||||