blib/lib/Term/ReadLine/Perl5/Dumb.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 4 SCAR 24.0
CC
4
Cov
0%
readline
20.0
get_line
2.0
BEGIN
2.0
CRAP 11.0
1 package Term::ReadLine::Perl5::Dumb;
2 use strict; use warnings;
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 eval "use rlib '.' "; # rlib is now optional
18 use Term::ReadLine::Perl5::History;
19  
20 sub get_line($) {
21 my $term_IN = shift;
22 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 my ($prompt, $term_IN, $term_OUT) = @_;
42 $term_IN = \*STDIN unless defined $term_IN;
43 $term_OUT = \*STDOUT unless defined $term_OUT;
44 my $old = select $term_OUT;
45 local $\ = '';
46 local $| = 1;
47 print $term_OUT $prompt;
48 local $/ = "\n";
49 my $line;
50 if (!defined($line = get_line($term_IN))) {
51 select $old;
52 return undef;
53 }
54 select $old;
55 chomp($line);
56 return $line;
57 }
58  
59 =head1 SEE ALSO
60  
61 L<Term::ReadLine::Perl5>
62 =cut
63  
64 1;