lib/Devel/Trepan/IO/Output.pm

filter: Statementstmt 50.7% 35 / 69 Branchbran 22.2% 4 / 18 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 10 / 20 Podpod 0.0% 0 / 14 totaltotal 39.3% 50 / 127 CC 11 SCAR 11.2
CC
11
Cov
44%
close
6.0
close
6.0
new
4.8
CRAP 3.1
« lib/Devel/Trepan/CmdProcessor/Parse/BPLocation.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Show_Subcmd/Interactive.pm »
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 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 54 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 54 ▶use rlib '../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 54 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # This is an abstract class that specifies debugger output.
21 package Devel::Trepan::IO::Output;
22 # use Devel::Trepan::Util qw(hash_merge);
23  
24 54 ▶use vars qw(@EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 14 ▶sub new($;$$) {
Subroutine new: called CC=3 SCAR=15.7
Pod undocumented
27 0 ▶ my($class, $output, $opts) = @_;
Subroutine new: not called CC=3 SCAR=15.7
Pod undocumented
28 0 ▶ $opts ||= {};
Condition25%1/4
$opts ||= {}
l!l
014
$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
29 0 ▶ unless ($output) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($output) 14 0 14
unless ($output) 0 0 0
30 0 open STDOUT_DUP, ">&", STDOUT;
31 0 $output = *STDOUT_DUP;
32 };
33 0 my $self = {
34 flush_after_write => 0,
35 output => $output,
36 eof => 0
37 };
38 0 bless $self, $class;
39 0 return $self;
40 }
41  
42 1 ▶sub is_closed($) {
Subroutine is_closed: called CC=2 SCAR=10.9
Pod undocumented
43 0 ▶ my($self) = @_;
Subroutine is_closed: not called CC=2 SCAR=10.9
Pod undocumented
44 0 ▶ ! $self->{output} || $self->is_eof;
Branch: 2 branches
BranchTrueFalseTotal
not $self->{"output"} or $self->is_eof 0 1 1
not $self->{"output"} or $self->is_eof 0 0 0
45 }
46 0 ▶sub close($) {
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
47 0 ▶ my($self) = @_;
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
48 0 ▶ close $self->{output} unless $self->is_closed;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->is_closed 0 0 0
unless $self->is_closed 0 0 0
49 0 $self->{eof} = 1;
50 }
51  
52 1 ▶sub is_eof($) {
Subroutine is_eof: called CC=1 SCAR=1.2
Pod undocumented
53 0 ▶ my($self) = @_;
Subroutine is_eof: not called CC=1 SCAR=1.2
Pod undocumented
54 0 return $self->{eof};
55 }
56  
57 0 ▶sub flush($) {
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
58 0 ▶ my($self) = @_;
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
59 0 $self->{output}->autoflush(1);
60 }
61  
62 # Use this to set where to write to. output can be a
63 # file object or a string. This code raises IOError on error.
64 0 ▶sub write($$) {
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
65 0 ▶ my ($self, $msg) = @_;
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
66 0 print {$self->{output}} $msg;
67 }
68  
69 # used to write to a debugger that is connected to this
70 # `str' written will have a newline added to it
71 #
72 1 ▶sub writeline($$) {
Subroutine writeline: called CC=2 SCAR=10.5
Pod undocumented
73 0 ▶ my ($self, $msg) = @_;
Subroutine writeline: not called CC=2 SCAR=10.5
Pod undocumented
74 0 ▶ print {$self->{output}} $msg . "\n" unless $self->is_closed();
Branch: 2 branches
BranchTrueFalseTotal
unless $self->is_closed 1 0 1
unless $self->is_closed 0 0 0
75 }
76  
77 54 ▶if (__FILE__ eq $0) {
Branch: 1 branch
BranchTrueFalseTotal
if (__FILE__ eq $0) 0 54 54
78 0 my $out = Devel::Trepan::IO::Output->new();
79 0 CORE::close(STDOUT);
80 0 $out->writeline("Now is the time!");
81 }
82  
83 54 1;
« lib/Devel/Trepan/CmdProcessor/Parse/BPLocation.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Show_Subcmd/Interactive.pm »