File Coverage

blib/lib/Term/ReadLine/Perl.pm
Criterion Covered Total %
statement 4 77 5.1
branch 0 30 0.0
condition 0 15 0.0
subroutine 2 21 9.5
pod 0 10 0.0
total 6 153 3.9


line stmt bran cond sub pod time code
1             package Term::ReadLine::Perl;
2 1     1   3889 use Carp;
  1         3  
  1         1450  
3             @ISA = qw(Term::ReadLine::Stub Term::ReadLine::Compa Term::ReadLine::Perl::AU);
4             #require 'readline.pl';
5              
6             $VERSION = $VERSION = 1.0303;
7              
8             sub readline {
9 0     0 0 0 shift;
10             #my $in =
11 0         0 &readline::readline(@_);
12             #$loaded = defined &Term::ReadKey::ReadKey;
13             #print STDOUT "\nrl=`$in', loaded = `$loaded'\n";
14             #if (ref \$in eq 'GLOB') { # Bug under debugger
15             # ($in = "$in") =~ s/^\*(\w+::)+//;
16             #}
17             #print STDOUT "rl=`$in'\n";
18             #$in;
19             }
20              
21             #sub addhistory {}
22             *addhistory = \&AddHistory;
23              
24             #$term;
25             $readline::minlength = 1; # To peacify -w
26             $readline::rl_readline_name = undef; # To peacify -w
27             $readline::rl_basic_word_break_characters = undef; # To peacify -w
28              
29             sub new {
30 0 0   0 0 0 if (defined $term) {
31 0         0 warn "Cannot create second readline interface, falling back to dumb.\n";
32 0         0 return Term::ReadLine::Stub::new(@_);
33             }
34 0         0 shift; # Package
35 0 0       0 if (@_) {
36 0 0       0 if ($term) {
37 0 0       0 warn "Ignoring name of second readline interface.\n" if defined $term;
38 0         0 shift;
39             } else {
40 0         0 $readline::rl_readline_name = shift; # Name
41             }
42             }
43 0 0       0 if (!@_) {
44 0 0       0 if (!defined $term) {
45 0         0 ($IN,$OUT) = Term::ReadLine->findConsole();
46             # Old Term::ReadLine did not have a workaround for a bug in Win devdriver
47 0 0 0     0 $IN = 'CONIN$' if $^O eq 'MSWin32' and "\U$IN" eq 'CON';
48 0 0 0     0 open IN,
    0          
49             # A workaround for another bug in Win device driver
50             (($IN eq 'CONIN$' and $^O eq 'MSWin32') ? "+< $IN" : "< $IN")
51             or croak "Cannot open $IN for read";
52 0 0       0 open(OUT,">$OUT") || croak "Cannot open $OUT for write";
53 0         0 $readline::term_IN = \*IN;
54 0         0 $readline::term_OUT = \*OUT;
55             }
56             } else {
57 0 0 0     0 if (defined $term and ($term->IN ne $_[0] or $term->OUT ne $_[1]) ) {
      0        
58 0         0 croak "Request for a second readline interface with different terminal";
59             }
60 0         0 $readline::term_IN = shift;
61 0         0 $readline::term_OUT = shift;
62             }
63 0 0       0 eval {require Term::ReadLine::readline}; die $@ if $@;
  0         0  
  0         0  
64             # The following is here since it is mostly used for perl input:
65             # $readline::rl_basic_word_break_characters .= '-:+/*,[])}';
66 0         0 $term = bless [$readline::term_IN,$readline::term_OUT];
67 0 0 0     0 unless ($ENV{PERL_RL} and $ENV{PERL_RL} =~ /\bo\w*=0/) {
68 0         0 local $Term::ReadLine::termcap_nowarn = 1; # With newer Perls
69 0     0   0 local $SIG{__WARN__} = sub {}; # With older Perls
  0         0  
70 0         0 $term->ornaments(1);
71             }
72 0         0 return $term;
73             }
74             sub newTTY {
75 0     0 0 0 my ($self, $in, $out) = @_;
76 0         0 $readline::term_IN = $self->[0] = $in;
77 0         0 $readline::term_OUT = $self->[1] = $out;
78 0         0 my $sel = select($out);
79 0         0 $| = 1; # for DB::OUT
80 0         0 select($sel);
81             }
82 0     0 0 0 sub ReadLine {'Term::ReadLine::Perl'}
83             sub MinLine {
84 0     0 0 0 my $old = $readline::minlength;
85 0 0       0 $readline::minlength = $_[1] if @_ == 2;
86 0         0 return $old;
87             }
88             sub SetHistory {
89 0     0 0 0 shift;
90 0         0 @readline::rl_History = @_;
91 0         0 $readline::rl_HistoryIndex = @readline::rl_History;
92             }
93             sub GetHistory {
94 0     0 0 0 @readline::rl_History;
95             }
96             sub AddHistory {
97 0     0 0 0 shift;
98 0         0 push @readline::rl_History, @_;
99 0         0 $readline::rl_HistoryIndex = @readline::rl_History + @_;
100             }
101             %features = (appname => 1, minline => 1, autohistory => 1, getHistory => 1,
102             setHistory => 1, addHistory => 1, preput => 1,
103             attribs => 1, 'newTTY' => 1,
104             tkRunning => Term::ReadLine::Stub->Features->{'tkRunning'},
105             ornaments => Term::ReadLine::Stub->Features->{'ornaments'},
106             );
107 0     0 0 0 sub Features { \%features; }
108             # my %attribs;
109             tie %attribs, 'Term::ReadLine::Perl::Tie' or die ;
110             sub Attribs {
111 0     0 0 0 \%attribs;
112             }
113 0     0   0 sub DESTROY {}
114              
115             package Term::ReadLine::Perl::AU;
116              
117             sub AUTOLOAD {
118 0     0   0 { $AUTOLOAD =~ s/.*:://; } # preserve match data
  0         0  
119 0         0 my $name = "readline::rl_$AUTOLOAD";
120 0 0       0 die "Unknown method `$AUTOLOAD' in Term::ReadLine::Perl"
121             unless exists $readline::{"rl_$AUTOLOAD"};
122 0     0   0 *$AUTOLOAD = sub { shift; &$name };
  0         0  
  0         0  
123 0         0 goto &$AUTOLOAD;
124             }
125              
126             package Term::ReadLine::Perl::Tie;
127              
128 1     1   12 sub TIEHASH { bless {} }
129 0     0     sub DESTROY {}
130              
131             sub STORE {
132 0     0     my ($self, $name) = (shift, shift);
133 0           $ {'readline::rl_' . $name} = shift;
  0            
134             }
135             sub FETCH {
136 0     0     my ($self, $name) = (shift, shift);
137 0           $ {'readline::rl_' . $name};
  0            
138             }
139              
140             package Term::ReadLine::Compa;
141              
142             sub get_c {
143 0     0     my $self = shift;
144 0           getc($self->[0]);
145             }
146              
147             sub get_line {
148 0     0     my $self = shift;
149 0           my $fh = $self->[0];
150 0           scalar <$fh>;
151             }
152              
153             1;