lib/Devel/Trepan/Interface.pm

filter: Statementstmt 43.1% 41 / 95 Branchbran 10.0% 3 / 30 Conditioncond 17.8% 5 / 28 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 37.9% 11 / 29 Podpod 0.0% 0 / 21 totaltotal 27.1% 60 / 221 CC 29 SCAR 23.7
CC
29
Cov
32%
close
30.0
close
30.0
errmsg
12.9
CRAP 10.7
« lib/Devel/Trepan/CmdProcessor/Command/Delete.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2012 Rocky Bernstein <rocky@cpan.org>
3  
4 # A base class for a debugger interface.
5  
6 53 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 53 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 53 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 53 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 package Devel::Trepan::Interface;
12 53 ▶use rlib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 53 ▶use vars qw(@EXPORT @ISA @YN);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 53 @ISA = qw(Exporter);
15 53 @EXPORT = qw(readline close new);
16  
17 53 ▶use Devel::Trepan::IO::Input;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 53 ▶use Devel::Trepan::IO::Output;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # A debugger interface handles the communication or interaction with between
21 # the program and the outside portion which could be
22 # - a user,
23 # - a front-end that talks to a user, or
24 # - another interface in another process or computer
25  
26 # attr_accessor :history_save, :interactive, :input, :output
27  
28 14 ▶sub new {
Subroutine new: called CC=4 SCAR=20.3
Pod undocumented
29 0 ▶ my($class, $inp, $out, $opts) = @_;
Subroutine new: not called CC=4 SCAR=20.3
Pod undocumented
30 0 ▶ $opts ||= {};
Condition25%1/4
$opts ||= {}
l!l
140
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
Truth table0%0/2
A
A= $opts
Aresult
11
00
31 0 my $input_opts = {
32 readline => 0
33 };
34  
35 my $self = {
36 histfile => undef,
37 history_save => 0,
38 histsize => undef,
39 line_edit => $opts->{line_edit},
40 0 ▶ input => $inp || Devel::Trepan::IO::Input->new(undef, $input_opts),
Condition33%4/12
$inp || 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
l!l&&r!l&&!r
2120
$out || 'Devel::Trepan::IO::Output'->new
l!l&&r!l&&!r
1130
$inp || 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
l!l&&r!l&&!r
000
$out || 'Devel::Trepan::IO::Output'->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$inp || 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
$inp 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
MC/DC0%0/2
$out || 'Devel::Trepan::IO::Output'->new
$out 'Devel::Trepan::IO::Output'->new
MC/DC0%0/2
$inp || 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
$inp 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
MC/DC0%0/2
$out || 'Devel::Trepan::IO::Output'->new
$out 'Devel::Trepan::IO::Output'->new
Truth table66%2/3
A || B
A= $inpB= 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $outB= 'Devel::Trepan::IO::Output'->new
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $inpB= 'Devel::Trepan::IO::Input'->new(undef, $input_opts)
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $outB= 'Devel::Trepan::IO::Output'->new
ABresult
1X1
011
000
41 opts => $opts,
42 output => $out || Devel::Trepan::IO::Output->new
43 };
44 0 bless $self, $class;
45 0 $self;
46 }
47  
48 0 ▶sub add_history($$) {}
Subroutine add_history: not called CC=1 SCAR=0.0
Pod undocumented
49  
50 # Closes all input and/or output.
51 0 ▶sub close($) {
Subroutine close: not called CC=5 SCAR=34.0
Pod undocumented
52 0 ▶ my($self) = shift;
Subroutine close: not called CC=5 SCAR=34.0
Pod undocumented
53 0 eval {
54 $self->{input}->close if
55 0 ▶ defined($self->{input}) && !$self->{input}->is_closed;
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->{"input"} and not $self->{"input"}->is_closed 0 0 0
if defined $self->{"input"} and not $self->{"input"}->is_closed 0 0 0
Condition0%0/6
defined $self->{"input"} and not $self->{"input"}->is_closed
!ll&&!rl&&r
000
defined $self->{"input"} and not $self->{"input"}->is_closed
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"input"} and not $self->{"input"}->is_closed
defined $self->{"input"} not $self->{"input"}->is_closed
MC/DC0%0/2
defined $self->{"input"} and not $self->{"input"}->is_closed
defined $self->{"input"} not $self->{"input"}->is_closed
Truth table0%0/3
A and not(B)
A= defined $self->{"input"}B= not $self->{"input"}->is_closed
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $self->{"input"}B= not $self->{"input"}->is_closed
ABresult
0X0
100
111
56 $self->{output}->close if
57 0 ▶ defined($self->{output}) && !$self->{output}->is_closed;
Branch: 2 branches
BranchTrueFalseTotal
if defined $self->{"output"} and not $self->{"output"}->is_closed 0 0 0
if defined $self->{"output"} and not $self->{"output"}->is_closed 0 0 0
Condition0%0/6
defined $self->{"output"} and not $self->{"output"}->is_closed
!ll&&!rl&&r
000
defined $self->{"output"} and not $self->{"output"}->is_closed
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"output"} and not $self->{"output"}->is_closed
defined $self->{"output"} not $self->{"output"}->is_closed
MC/DC0%0/2
defined $self->{"output"} and not $self->{"output"}->is_closed
defined $self->{"output"} not $self->{"output"}->is_closed
Truth table0%0/3
A and not(B)
A= defined $self->{"output"}B= not $self->{"output"}->is_closed
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $self->{"output"}B= not $self->{"output"}->is_closed
ABresult
0X0
100
111
58 };
59 }
60  
61 # Called when a dangerous action is about to be done to make sure
62 # it's okay. `prompt' is printed; user response is returned.
63 0 ▶sub confirm($;$) {
Subroutine confirm: not called CC=1 SCAR=6.9
Pod undocumented
64 0 ▶ my($self, $prompt, $default) = @_;
Subroutine confirm: not called CC=1 SCAR=6.9
Pod undocumented
65 0 Carp::croak "RuntimeError, Trepan::NotImplementedMessage";
66 }
67  
68 # Common routine for reporting debugger error messages.
69 2 ▶sub errmsg($;$$) {
Subroutine errmsg: called CC=5 SCAR=25.6
Pod undocumented
70 0 ▶ my($self, $str, $prefix) = @_;
Subroutine errmsg: not called CC=5 SCAR=25.6
Pod undocumented
71 0 ▶ $prefix = '** ' unless defined $prefix;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $prefix 2 0 2
unless defined $prefix 0 0 0
72 0 ▶ if (ref($str) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $str eq 'ARRAY') { } 0 2 2
if (ref $str eq 'ARRAY') { } 0 0 0
73 0 foreach my $s (@$str) {
74 0 $self->errmsg($s);
75 }
76 } else {
77 0 foreach my $s (split /\n/, $str) {
78 0 $self->msg(sprintf("%s%s" , $prefix, $s));
79 }
80 }
81 }
82  
83 0 ▶sub is_input_eof($) {
Subroutine is_input_eof: not called CC=3 SCAR=24.8
Pod undocumented
84 0 ▶ my $self = shift;
Subroutine is_input_eof: not called CC=3 SCAR=24.8
Pod undocumented
85 0 ▶ return 1 unless defined $self->{input};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $self->{"input"} 0 0 0
unless defined $self->{"input"} 0 0 0
86 0 my $input = $self->{input};
87 0 ▶ $input->can("is_eof") ? $input->is_eof : $input->eof;
Branch: 2 branches
BranchTrueFalseTotal
$input->can('is_eof') ? : 0 0 0
$input->can('is_eof') ? : 0 0 0
88 }
89  
90 # # Return true if interface is interactive.
91 # def interactive?
92 # # Default false and making subclasses figure out how to determine
93 # # interactiveness.
94 # false
95 # end
96  
97 # used to write to a debugger that is connected to this
98 # server; `str' written will have a newline added to it.
99 7 ▶sub msg($$) {
Subroutine msg: called CC=1 SCAR=1.2
Pod undocumented
100 0 ▶ my($self, $str) = @_;
Subroutine msg: not called CC=1 SCAR=1.2
Pod undocumented
101 # if (str.is_a?(Array)) {
102 # foreach my $s (@$str) {
103 # errmsg($s);
104 # }
105 # } else {
106 0 $self->{output}->writeline($str);
107 # }
108 }
109  
110 # used to write to a debugger that is connected to this
111 # server; `str' written will not have a newline added to it
112 0 ▶sub msg_nocr($$) {
Subroutine msg_nocr: not called CC=1 SCAR=6.9
Pod undocumented
113 0 ▶ my($self, $msg) = @_;
Subroutine msg_nocr: not called CC=1 SCAR=6.9
Pod undocumented
114 0 $self->{output}->write($msg);
115 }
116  
117 0 ▶sub read_command($;$) {
Subroutine read_command: not called CC=1 SCAR=6.9
Pod undocumented
118 0 ▶ my($self, $prompt) = @_;
Subroutine read_command: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my $line = readline($prompt);
120 # FIXME: Do something with history?
121 0 return $line;
122 }
123  
124 0 ▶sub read_history($$) {}
Subroutine read_history: not called CC=1 SCAR=0.0
Pod undocumented
125  
126 0 ▶sub readline($;$) {
Subroutine readline: not called CC=2 SCAR=17.9
Pod undocumented
127 0 ▶ my($self, $prompt) = @_;
Subroutine readline: not called CC=2 SCAR=17.9
Pod undocumented
128 ## FIXME
129 ## $self->{output}->flush;
130 0 ▶ $self->{output}->write($prompt) if $prompt;
Branch: 2 branches
BranchTrueFalseTotal
if $prompt 0 0 0
if $prompt 0 0 0
131 0 $self->{input}->readline();
132 }
133  
134 0 ▶sub save_history($$) {}
Subroutine save_history: not called CC=1 SCAR=0.0
Pod undocumented
135  
136 #sub DESTROY {
137 # my $self = shift;
138 # if ($self->{output} && defined($self->{output}) && ! $self->{output}->is_closed) {
139 # eval {
140 # $self->msg(sprintf("%sThat's all, folks...",
141 # (defined($Devel::Trepan::PROGRAM) ?
142 # "${Devel::Trepan::PROGRAM}: " : '')));
143 # };
144 # }
145 # $self->close;
146 #}
147  
148 # Demo
149 53 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 53 53
150 0 my $interface = Devel::Trepan::Interface->new;
151 }
152  
153 53 1;
« lib/Devel/Trepan/CmdProcessor/Command/Delete.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Display_Subcmd/Eval.pm »