File Coverage

lib/Term/ReadLine/Perl5/Dumb.pm
Criterion Covered Total %
statement 12 29 41.3
branch 0 6 0.0
condition n/a
subroutine 4 6 66.6
pod 1 2 50.0
total 17 43 39.5


line stmt bran cond sub pod time code
1             package Term::ReadLine::Perl5::Dumb;
2 11     11   123 use strict; use warnings;
  11     11   26  
  11         398  
  11         67  
  11         25  
  11         462  
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.
11              
12             Since L currently has global state,
13             when more than one interface is created, we fallback to this code.
14              
15             =cut
16              
17 11     11   81 eval "use rlib '.' "; # rlib is now optional
  11         31  
  11         52  
18 11     11   3478 use Term::ReadLine::Perl5::History;
  11         31  
  11         3460  
19              
20             sub get_line($) {
21 0     0 0   my $term_IN = shift;
22 0           scalar <$term_IN>;
23             }
24              
25             =head1 SUBROUTINES
26              
27             =head2 readline
28              
29             B(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 and I are used when the
35             corresponding file handles are not given.
36              
37             =cut
38              
39             sub readline($;$$)
40             {
41 0     0 1   my ($prompt, $term_IN, $term_OUT) = @_;
42 0 0         $term_IN = \*STDIN unless defined $term_IN;
43 0 0         $term_OUT = \*STDOUT unless defined $term_OUT;
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 0         if (!defined($line = get_line($term_IN))) {
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
62              
63             =cut
64              
65             1;