File Coverage

lib/Devel/Trepan/IO.pm
Criterion Covered Total %
statement 32 46 69.5
branch 1 10 10.0
condition 2 2 100.0
subroutine 9 16 56.2
pod n/a
total 44 74 59.4


line stmt bran cond sub pod time code
1             # Copyright (C) 2011, 2012 Rocky Bernstein <rocky@cpan.org>
2             # classes to support communication to and from the debugger. This
3             # communcation might be to/from another process or another computer.
4             # And reading may be from a debugger command script.
5             #
6             # For example, we'd like to support Sockets, and serial lines and file
7             # reading, as well a readline-type input. Encryption and Authentication
8             # methods might decorate some of the communication channels.
9             #
10             # Some ideas originiated as part of Matt Fleming's 2006 Google Summer of
11             # Code project.
12              
13 16     16   106 use strict; use warnings;
  16     16   64  
  16         424  
  16         95  
  16         36  
  16         428  
14 16     16   94 use Exporter;
  16         37  
  16         606  
15 16     16   104 use rlib '../..';
  16         40  
  16         110  
16              
17             package Devel::Trepan::IO::InputBase;
18 16     16   5895 no warnings 'redefine';
  16         39  
  16         633  
19              
20 16     16   403 use Devel::Trepan::Util qw(hash_merge);
  16         35  
  16         9121  
21             # our @EXPORT;
22              
23             my $DEFAULT_OPTS = {line_edit => 0};
24             # @EXPORT = qw(DEFAULT_OPTS);
25              
26             sub new($$;$) {
27 28     28   88 my($class, $input, $opts) = @_;
28 28   100     1779 $opts ||= {};
29 28         259 hash_merge($opts, $DEFAULT_OPTS);
30 28         65 my $line_edit = $opts->{line_edit};
31 28         119 my $self = {
32             input => $input,
33             eof => 0,
34             line_edit => $line_edit
35             };
36 28         132 bless $self, $class;
37 28         102 return $self;
38             }
39              
40             sub is_closed($) {
41 0     0   0 my($self) = shift;
42 0 0       0 ! $self->{input} || $self->is_eof;
43             }
44              
45             sub close($) {
46 0     0   0 my($self) = shift;
47 0 0       0 CORE::close $self->{input} unless $self->is_closed;
48 0         0 $self->{eof} = 1;
49             }
50              
51             sub want_term_readline() {
52             0;
53             }
54              
55             sub is_eof($) {
56 10     10   19 my($self) = shift;
57 10         33 return $self->{eof};
58             }
59              
60             sub is_interactive() {
61             0;
62             }
63              
64             # This is an abstract class that specifies debugger output.
65             package Devel::Trepan::IO::OutputBase;
66              
67             # attr_accessor :flush_after_write
68             # attr_reader :output
69              
70             sub new($$;$)
71             {
72 3     3   7 my ($class, $out, $opts) = @_;
73 3 50       9 $opts = {} unless defined $opts;
74              
75 3         11 my $self = {
76             output => $out,
77             flush_after_write => 0,
78             eof => 0
79             };
80 3         8 bless $self, $class;
81 3         10 $self
82             }
83              
84             sub close($)
85             {
86 0     0     my $self = shift;
87 0 0         $self->{output}->close if $self->{output};
88 0           $self->{eof} = 1;
89             }
90              
91 0 0   0     sub is_eof($) { $_->[0]->{eof} || $_->[0]->eof }
92              
93             ## sub flush($) { $_->[0]->{output}->flush }
94             ## FIXME: this isn't quite right.
95 0     0     sub flush($) {$_->[0]->{output}->autoflush = 1 }
96              
97             # Use this to set where to write to. output can be a
98             # file object or a string. This code raises IOError on error.
99             sub write
100             {
101 0     0     my $self = shift;
102 0           $self->{output}->print(@_);
103             }
104              
105             # used to write to a debugger that is connected to this
106             # `str' written will have a newline added to it
107             #
108             sub writeline($$)
109             {
110 0     0     my ($self, $msg) = @_;
111 0           $self->{output}->write("${msg}\n")
112             }
113              
114             unless (caller) {
115             my $in = Devel::Trepan::IO::InputBase->new(*main::STDIN);
116             }
117              
118             1;