blib/lib/dbgp-helper/DB/RedirectStdOutput.pm

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 72 CC 6 SCAR 16.1
CC
6
Cov
0%
doOutput
12.0
WRITE
6.0
FILENO
6.0
CRAP 5.0
« blib/lib/Devel/Debug/DBGp.pm ↑ Summary blib/lib/dbgp-helper/DB/OSType.pm »
1 # RedirectStdOutput.pm
2 #
3 # Module for redirecting standard output/error.
4 #
5 # Copyright (c) 2003-2006 ActiveState Software Inc.
6 # All rights reserved.
7 #
8 # Xdebug compatibility, UNIX domain socket support and misc fixes
9 # by Mattia Barbon <mattia@barbon.org>
10 #
11 # This software (the Perl-DBGP package) is covered by the Artistic License
12 # (http://www.opensource.org/licenses/artistic-license.php).
13  
14 package DB::RedirectStdOutput;
15  
16 $VERSION = 0.10;
17 require Exporter;
18 @ISA = qw(Exporter);
19 @EXPORT = qw(
20 DBGP_Redirect_Disable
21 DBGP_Redirect_Copy
22 DBGP_Redirect_Redirect
23 );
24 @EXPORT_OK = ();
25  
26 use strict;
27 use Carp;
28  
29 use DB::DbgrCommon;
30 use DB::DbgrProperties (qw(figureEncoding));
31  
32 use constant DBGP_Redirect_Disable => 0;
33 use constant DBGP_Redirect_Copy => 1;
34 use constant DBGP_Redirect_Redirect => 2;
35  
36 sub TIEHANDLE {
37 0 ▶ my ($class, $origHandle, $newFileHandle, $streamType, $redirectState) = @_;
Subroutine TIEHANDLE: not called CC=1 SCAR=6.9
38 0 my $data = { h_new => $newFileHandle,
39 h_old => $origHandle,
40 streamType => $streamType,
41 redirectState => $redirectState,
42 };
43 0 bless $data, $class;
44 }
45  
46 sub doOutput($$$$) {
47 0 ▶ my ($buf, $streamType, $redirectState, $h_old) = @_;
Subroutine doOutput: not called CC=3 SCAR=24.8
Pod undocumented
48 0 local $DB::full_bypass = 1;
49 0 ▶ if ($redirectState != DBGP_Redirect_Disable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redirectState != 0) 0 0 0
50 0 my ($encoding, $encVal) = figureEncoding($buf);
51 0 printWithLength(sprintf(qq(%s\n<stream %s
52 type="%s"
53 encoding="%s">%s</stream>\n),
54 xmlHeader(),
55 namespaceAttr(),
56 $streamType,
57 $encoding,
58 $encVal,
59 ));
60 }
61 0 ▶ if ($redirectState != DBGP_Redirect_Redirect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redirectState != 2) 0 0 0
62 0 print $h_old $buf;
63 }
64 }
65  
66  
67 sub WRITE {
68 0 ▶ my $self = shift;
Subroutine WRITE: not called CC=2 SCAR=17.9
69 0 my $h_old = $self->{h_old};
70 0 my $streamType = $self->{streamType};
71 0 my $redirectState = $self->{redirectState};
72 0 my ($buf, $len, $offset) = @_;
73 0 ▶ substr($buf, $len) = "" if $len;
Branch: 1 branch
BranchTrueFalseTotal
if $len 0 0 0
74 0 doOutput($buf, $streamType, $redirectState, $h_old);
75 }
76  
77 sub PRINT {
78 0 ▶ my $self = shift;
Subroutine PRINT: not called CC=1 SCAR=6.9
79 0 my $h_old = $self->{h_old};
80 0 my $streamType = $self->{streamType};
81 0 my $redirectState = $self->{redirectState};
82 0 my $buf = join('', @_);
83 0 doOutput($buf, $streamType, $redirectState, $h_old);
84 }
85  
86 sub PRINTF {
87 0 ▶ my $self = shift;
Subroutine PRINTF: not called CC=1 SCAR=6.9
88 0 my $h_old = $self->{h_old};
89 0 my $streamType = $self->{streamType};
90 0 my $redirectState = $self->{redirectState};
91 0 my $fmt = shift;
92 0 my $buf = sprintf($fmt, @_);
93 0 doOutput($buf, $streamType, $redirectState, $h_old);
94 }
95  
96 sub READ {
97 }
98  
99 sub READLINE {
100 }
101  
102 sub GETC {
103 }
104  
105 sub CLOSE {
106 }
107  
108 sub UNTIE {
109 0 ▶ my $self = shift;
Subroutine UNTIE: not called CC=1 SCAR=6.9
110 # die "Not expected";
111 }
112  
113 # there used to be a DESTROY closing h_new, but this will close
114 # DBGp communication socket on a double redirect
115  
116 sub FILENO {
117 0 ▶ my $self = shift;
Subroutine FILENO: not called CC=2 SCAR=17.9
118 0 my $h_new = $self->{h_new};
119 0 my $h_old = $self->{h_old};
120 0 my $redirectState = $self->{redirectState};
121 0 ▶ if ($redirectState != DBGP_Redirect_Disable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redirectState != 0) { } 0 0 0
122 0 return fileno($h_new);
123 } else {
124 0 return fileno($h_old);
125 }
126 }
127  
128 sub BINMODE {
129 0 ▶ my ($self, $layer) = @_;
Subroutine BINMODE: not called CC=2 SCAR=17.9
130 0 ▶ return binmode $self->{h_old}, $layer if $layer;
Branch: 1 branch
BranchTrueFalseTotal
if $layer 0 0 0
131 0 return binmode $self->{h_old};
132 }
133  
134 # "Optional" routines, according to perldoc perltie.
135 # Bug 34879 shows they were using them. The proper
136 # fix is to die when they're used, so the user can
137 # figure something else out.
138  
139 sub _buildMessage_Die {
140 0 ▶ my $op = shift;
Subroutine _buildMessage_Die: not called CC=1 SCAR=6.9
141 0 my @messages = (
142 "Unexpected use of a standard filehandle while debugging:",
143 "The STDOUT and STDERR handles have been tied for remote debugging, ",
144 "and can't $op in the code being debugged.",
145 "",
146 "Try adding ",
147 " untie(\*STDOUT) if tied(\*STDOUT);",
148 " untie(\*STDERR) if tied(\*STDERR);",
149 "to the code",
150 );
151 0 carp join("\n", @messages);
152 }
153  
154 sub OPEN {
155 0 ▶ _buildMessage_Die('be redirected');
Subroutine OPEN: not called CC=1 SCAR=6.9
156 }
157  
158 sub EOF {
159 0 ▶ _buildMessage_Die('be read from');
Subroutine EOF: not called CC=1 SCAR=6.9
160 }
161  
162 sub SEEK {
163 0 ▶ _buildMessage_Die('support seek');
Subroutine SEEK: not called CC=1 SCAR=6.9
164 }
165  
166 sub TELL {
167 0 ▶ _buildMessage_Die('support seek');
Subroutine TELL: not called CC=1 SCAR=6.9
168 }
169  
170 1;
« blib/lib/Devel/Debug/DBGp.pm ↑ Summary blib/lib/dbgp-helper/DB/OSType.pm »