File Coverage

blib/lib/Term/ReadLine/TTYtter.pm
Criterion Covered Total %
statement 4 82 4.8
branch 0 30 0.0
condition 0 15 0.0
subroutine 2 23 8.7
pod 0 12 0.0
total 6 162 3.7


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