blib/lib/CGI/Debug.pm

filter: Statementstmt 55.7% 199 / 357 Branchbran 42.1% 91 / 216 Conditioncond 34.5% 37 / 107 MC/DCmcdc 3.3% 2 / 60 Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 11 totaltotal 44.2% 340 / 768 CC 166 SCAR 53.3
CC
166
Cov
48%
cleanup
575.1
unravel
119.3
set_defaults
111.8
CRAP 206.2
↑ Summary
1 package CGI::Debug;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw( $VERSION $Module $File_base $Control $Reference
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 $Content_type $Body_length $Done $DEBUG $Started);
6 2 $VERSION = '1.00';
7  
8 sub BEGIN
9 2 ▶{
Subroutine BEGIN: called CC=12 SCAR=36.7
10 2 $DEBUG = 0; # <-- DEBUG
11 2 ▶ print "Content-Type: text/plain\n\n" if $DEBUG >2; # DEBUG
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::DEBUG > 2 0 2 2
12 2 $Module = __PACKAGE__;
13  
14  
15 sub import_error
16 0 ▶ {
Subroutine import_error: not called CC=3 SCAR=24.8
Pod undocumented
17 0 my( $error, $paramsref ) = @_;
18 0 print "Content-Type: text/html\n\n";
19 0 print "<html><head><title>$Module response</title></head><body>";
20  
21 0 print "<p>You got an error!\n";
22  
23 0 ▶ if( ref $paramsref and eval{ require "Data/Dumper.pm" } )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $paramsref and eval { do { require "Data/Dumper.pm" } }) 0 0 0
Condition0%0/3
ref $paramsref and eval { do { require "Data/Dumper.pm" } }
!ll&&!rl&&r
000
MC/DC0%0/2
ref $paramsref and eval { do { require "Data/Dumper.pm" } }
ref $paramsref eval { do { require "Data/Dumper.pm" } }
Truth table0%0/3
A and B
A= ref $paramsrefB= eval { do { require "Data/Dumper.pm" } }
ABresult
0X0
100
111
24 {
25 0 print "<pre>\n", Data::Dumper::Dumper( $paramsref ), "</pre>\n\n";
26 }
27  
28 0 print "<p>$error\n";
29 0 print "</body></html>\n";
30  
31 # Set error flag, for not go into END
32 # This avoid a perl core dump under 5.005_02
33 0 $Done = 1;
34 }
35  
36  
37 2 ▶ unless( eval{ require 5.004_05 } )
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require "5.00405" } }) 0 2 2
38 {
39 0 &import_error("You must at least have perl v 5.004_05 to use $Module");
40 }
41  
42 2 ▶ if( exists $ENV{'GATEWAY_INTERFACE'} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/) 0 2 2
Condition33%1/3
exists $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
!ll&&!rl&&r
200
MC/DC0%0/2
exists $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
exists $ENV{"GATEWAY_INTERFACE"} $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
Truth table33%1/3
A and B
A= exists $ENV{"GATEWAY_INTERFACE"}B= $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
ABresult
0X0
100
111
43 $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-Perl/
44 )
45 {
46 0 my $modfile = $Module;
47 0 $modfile =~ s/::/\//g;
48  
49 0 my($i,$p,$filename)=0;
50 0 ▶ while( ($p,$filename) = caller(++$i) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller ++$i) 0 0 0
51 {
52 0 ▶ last unless $filename =~ /\/$modfile\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ m[/$modfile\.pm$] 0 0 0
53 }
54  
55 0 warn "$filename: $Module can't be used under mod_perl\n";
56  
57 0 return;
58 }
59  
60 2 ▶ unless( eval{ require 'CGI.pm' } )
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require "CGI.pm" } }) 0 2 2
61 {
62 0 &import_error("You must have the CGI module to use $Module");
63 }
64 2 $CGI::NO_DEBUG = 1; #Do not use STDIN debugging!
65  
66 2 ▶ if( eval{ require 'Time/HiRes.pm' } )
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require 'Time/HiRes.pm' } }) { } 2 0 2
67 {
68 2 import Time::HiRes 'time';
69 2 $Started = Time::HiRes::time();
70 }
71 else
72 {
73 0 $Started = $^T;
74 }
75  
76  
77 2 $Control = {};
78 2 $File_base = "/tmp/$Module";
79 2 $File_base =~ s/::/-/g;
80  
81 # Redirect STDERR to a temporary file
82 2 ▶ unless( $DEBUG > 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::Debug::DEBUG > 1) 2 0 2
83 {
84 2 open(OLDERR, ">&STDERR"); # Save real STDERR
85 2 ▶ open (STDERR,">${File_base}-error-$$")
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">$CGI::Debug::File_base-error-${$}" or &import_error("Could not write to file $CGI::Debug::File_base-error-${$}: $!\n") 2 0 2
86 or &import_error( "Could not write to file ${File_base}-error-$$: $!\n" );
87 }
88  
89 2 ▶ $/ ||= "\n"; # Bug in perl 5.005_02 !!!
Condition50%1/2
$/ ||= "\n"
l!l
20
MC/DC0%0/1
$/ ||= "\n"
$/
Truth table50%1/2
A
A= $/
Aresult
11
00
90 }
91  
92  
93 END
94 2 ▶{
Subroutine END: called CC=2 SCAR=7.2
95 2 ▶ return if $Done; # This avoids a perl core dump under 5.005_02
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Done 0 2 2
96 2 &cleanup;
97 }
98  
99 sub CHECK
100 2 ▶{
Subroutine CHECK: called CC=3 SCAR=14.2
101 2 ▶ return if $Done; # This avoids a perl core dump under 5.005_02
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Done 0 2 2
102 2 ▶ if( -s "$File_base-error-$$" )
Branch: 1 branch
BranchTrueFalseTotal
if (-s "$CGI::Debug::File_base-error-${$}") 0 2 2
103 {
104 0 &cleanup;
105 0 $Done=1;
106 }
107 }
108  
109  
110 sub import
111 2 ▶{
Subroutine import: called CC=14 SCAR=32.2
112 2 my( $self, @list ) = @_;
113  
114  
115 2 ▶ if( exists $ENV{'GATEWAY_INTERFACE'} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/) 0 2 2
Condition33%1/3
exists $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
!ll&&!rl&&r
200
MC/DC0%0/2
exists $ENV{"GATEWAY_INTERFACE"} and $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
exists $ENV{"GATEWAY_INTERFACE"} $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
Truth table33%1/3
A and B
A= exists $ENV{"GATEWAY_INTERFACE"}B= $ENV{"GATEWAY_INTERFACE"} =~ /^CGI-Perl/
ABresult
0X0
100
111
116 $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-Perl/
117 )
118 {
119 0 $Done = 1;
120 0 return;
121 }
122  
123 # Check if @list is in pairs
124 2 ▶ @list % 2 and &import_error("The param list to $Module must be in key/value pairs");
Branch: 1 branch
BranchTrueFalseTotal
@list % 2 and &import_error("The param list to $CGI::Debug::Module must be in key/value pairs") 0 2 2
125 2 my %params = @list;
126  
127 # Build referense structure
128 2 $Reference =
129 {
130 report => [qw( errors empty_body time params cookies
131 environment html_compliance everything internals
132 )],
133 on => [qw( fatals warnings anything )],
134 to =>
135 {
136 browser => "",
137 log => "",
138 file => [],
139 mail => [],
140 },
141 header => [qw( control ignore minimal )],
142 set =>
143 {
144 param_length => "",
145 error_document => "",
146 },
147 };
148  
149 2 eval { $Control = &unravel( \%params, $Reference ) };
150 2 ▶ $@ and &import_error( $@, \%params );
Branch: 1 branch
BranchTrueFalseTotal
$@ and &import_error($@, \%params) 0 2 2
151  
152 # All other defaults is determined later
153  
154  
155 # The priority is 1) cookies, 2) env variables
156 # 3) import parameters, and 4) default
157 2 my $module_name = $Module;
158 2 $module_name =~ s/::/-/g;
159 2 ▶ foreach( CGI::cookie("${module_name}-header"),
Condition33%1/3
exists $ENV{"$module_name-header"} && $ENV{"$module_name-header"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $ENV{"$module_name-header"} && $ENV{"$module_name-header"}
exists $ENV{"$module_name-header"} $ENV{"$module_name-header"}
Truth table33%1/3
A && B
A= exists $ENV{"$module_name-header"}B= $ENV{"$module_name-header"}
ABresult
0X0
100
111
160 (exists $ENV{"${module_name}-header"}
161 and $ENV{"${module_name}-header"}),
162 )
163 {
164 2 ▶ $_ and $Control->{'header'}{$_}=1 and last;
Branch: 1 branch
BranchTrueFalseTotal
$_ and $CGI::Debug::Control->{"header"}{$_} = 1 and last 0 2 2
Condition50%1/2
$_ and $CGI::Debug::Control->{"header"}{$_} = 1
!ll
20
MC/DC0%0/1
$_ and $CGI::Debug::Control->{"header"}{$_} = 1
$_
Truth table50%1/2
A
A= $_
Aresult
00
11
165 }
166 2 ▶ $Control->{'header'} or $Control->{'header'}{'control'}=1;
Branch: 1 branch
BranchTrueFalseTotal
$CGI::Debug::Control->{"header"} or $CGI::Debug::Control->{"header"}{"control"} = 1 0 2 2
167  
168  
169  
170 2 ▶ if( $Control->{'header'}{'minimal'} )
Branch: 2 branches
BranchTrueFalseTotal
if ($CGI::Debug::Control->{'header'}{'minimal'}) { } 0 2 2
elsif ($CGI::Debug::Control->{'header'}{'control'}) { } 2 0 2
171 {
172 0 print "Content-Type: text/html\n\n";
173 0 $Content_type = 'text/html';
174 }
175 elsif( $Control->{'header'}{'control'} )
176 {
177 2 ▶ unless( $DEBUG > 1 ) # Eating STDOUT
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::Debug::DEBUG > 1) 2 0 2
178 {
179 2 open(OLDOUT, ">&STDOUT"); # Save real STDOUT
180 2 ▶ open(STDOUT, ">${File_base}-out-$$")
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">$CGI::Debug::File_base-out-${$}" or &import_error("Could not write to file $CGI::Debug::File_base-out-${$}: $!\n") 2 0 2
181 or &import_error( "Could not write to file ${File_base}-out-$$: $!\n" );
182 }
183 }
184 }
185  
186 sub cleanup
187 2 ▶{
Subroutine cleanup: called CC=49 SCAR=63.5
Pod undocumented
188 2 my $errfile = &set_defaults;
189 2 my $out_ref = undef;
190  
191 2 ▶ unless( $DEBUG > 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::Debug::DEBUG > 1) 2 0 2
192 {
193 2 close STDERR;
194 2 open( STDERR, ">&OLDERR" );
195  
196 2 ▶ if( open ERR, "${File_base}-error-$$" )
Branch: 1 branch
BranchTrueFalseTotal
if (open ERR, "$CGI::Debug::File_base-error-${$}") { } 2 0 2
197 {
198 2 $errfile .= join '', <ERR>;
199 2 close ERR;
200 2 ▶ unlink "${File_base}-error-$$" or
Branch: 1 branch
BranchTrueFalseTotal
unlink "$CGI::Debug::File_base-error-${$}" or $errfile .= "\nCouldn't delete $CGI::Debug::File_base-error-${$}: $!\n" 2 0 2
201 $errfile .= "\nCouldn't delete ${File_base}-error-$$: $!\n";
202 }
203 else
204 {
205 0 $errfile .= "\nCouldn't open ${File_base}-error-$$: $!\n";
206 }
207 }
208  
209 2 ▶ if( $Control->{'header'}{'control'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Debug::Control->{"header"}{"control"}) 2 0 2
210 {
211 2 my $header_error;
212 2 ($header_error, $out_ref) = &header_control;
213 2 $errfile .= $header_error;
214 }
215  
216 2 my $info = "";
217 2 ▶ $info .= &report_time if $Control->{'report'}{'time'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"time"} 0 2 2
218 2 ▶ $info .= &report_params if $Control->{'report'}{'params'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"params"} 0 2 2
219 2 ▶ $info .= &report_cookies if $Control->{'report'}{'cookies'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"cookies"} 0 2 2
220 2 ▶ $info .= &report_environment if $Control->{'report'}{'environment'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"environment"} 0 2 2
221 # $info .= &HTML_complians if $Control->{'report'}{'HTML_complians'};
222  
223  
224 2 ▶ if( $Control->{'report'}{'internals'} or $DEBUG )
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Debug::Control->{"report"}{"internals"} or $CGI::Debug::DEBUG) 0 2 2
Condition33%1/3
$CGI::Debug::Control->{"report"}{"internals"} or $CGI::Debug::DEBUG
l!l&&r!l&&!r
002
MC/DC0%0/2
$CGI::Debug::Control->{"report"}{"internals"} or $CGI::Debug::DEBUG
$CGI::Debug::Control->{"report"}{"internals"} $CGI::Debug::DEBUG
Truth table33%1/3
A or B
A= $CGI::Debug::Control->{"report"}{"internals"}B= $CGI::Debug::DEBUG
ABresult
1X1
011
000
225 {
226 0 ▶ if( eval{ require 'Data/Dumper.pm' } )
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require 'Data/Dumper.pm' } }) { } 0 0 0
227 {
228 0 $info .= "\n\nControl:\n".&Data::Dumper::Dumper($Control)."\n\n";
229 }
230 else
231 {
232 0 $info .= "Data::Dumper not found\n";
233 }
234 }
235  
236  
237 2 ▶ if( $? or (defined $Body_length and $Body_length == 0) or
Branch: 1 branch
BranchTrueFalseTotal
if ($? or defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 or $CGI::Debug::Control->{'on'}{'warnings'} and $errfile or $CGI::Debug::Control->{'on'}{'anything'}) { } 2 0 2
Condition33%5/15
$? or defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 or $CGI::Debug::Control->{"on"}{"warnings"} and $errfile or $CGI::Debug::Control->{"on"}{"anything"}
l!l&&r!l&&!r
020
$? or defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 or $CGI::Debug::Control->{"on"}{"warnings"} and $errfile
l!l&&r!l&&!r
002
$? or defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
l!l&&r!l&&!r
002
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
!ll&&!rl&&r
020
$CGI::Debug::Control->{"on"}{"warnings"} and $errfile
!ll&&!rl&&r
020
MC/DC0%0/6
$? or defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 or $CGI::Debug::Control->{"on"}{"warnings"} and $errfile or $CGI::Debug::Control->{"on"}{"anything"}
$? defined $CGI::Debug::Body_length $CGI::Debug::Body_length == 0 $CGI::Debug::Control->{"on"}{"warnings"} $errfile $CGI::Debug::Control->{"on"}{"anything"}
Truth table8%1/12
A or B and C or D and E or F
A= $?B= defined $CGI::Debug::Body_lengthC= $CGI::Debug::Body_length == 0D= $CGI::Debug::Control->{"on"}{"warnings"}E= $errfileF= $CGI::Debug::Control->{"on"}{"anything"}
ABCDEFresult
1XXXXX1
011XXX1
00X11X1
01011X1
00X0X11
00X1011
0100X11
0101011
00X0X00
00X1000
0100X00
0101000
238 $Control->{'on'}{'warnings'} && $errfile or
239 $Control->{'on'}{'anything'}
240 )
241 {
242 2 ▶ my $script_name = $ENV{SCRIPT_NAME} || $0 || "Script without name";
Condition40%2/5
$ENV{'SCRIPT_NAME'} || $0 || 'Script without name'
l!l
20
$ENV{"SCRIPT_NAME"} or $0
l!l&&r!l&&!r
020
MC/DC0%0/2
$ENV{'SCRIPT_NAME'} || $0 || 'Script without name'
$ENV{"SCRIPT_NAME"} $0
Truth table33%1/3
A or B
A= $ENV{"SCRIPT_NAME"}B= $0
ABresult
1X1
011
000
243  
244 2 ▶ if( $Control->{'to'}{'log'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Debug::Control->{"to"}{"log"}) 0 2 2
245 {
246 0 my $date = localtime;
247 0 print STDERR "\n","-"x60, "\n\n";
248 0 print STDERR "File: $script_name\n";
249 0 print STDERR "Date: $date\n\n";
250 0 print STDERR $errfile;
251 0 print STDERR $info;
252 0 print STDERR "\n<EOF>\n";
253 }
254  
255 2 ▶ if( $Control->{'to'}{'file'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Debug::Control->{"to"}{"file"}) 0 2 2
256 {
257 0 foreach my $file ( @{ $Control->{'to'}{'file'} } )
258 {
259 0 ▶ if( open FILE, ">$file" )
Branch: 1 branch
BranchTrueFalseTotal
if (open FILE, ">$file") { } 0 0 0
260 {
261 0 my $date = localtime;
262 0 print FILE "File: $script_name\n";
263 0 print FILE "Date: $date\n\n";
264 0 print FILE $errfile;
265 0 print FILE $info;
266 0 print FILE "\n<EOF>\n";
267 0 close FILE;
268 }
269 else
270 {
271 0 $Control->{'to'}{'browser'} = 1;
272 0 $errfile .= "\n$Module: Couldn't write to '$file': $!\n\n";
273 }
274 }
275 }
276  
277 2 ▶ if( $Control->{'to'}{'mail'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Debug::Control->{"to"}{"mail"}) 0 2 2
278 {
279 0 ▶ if( eval{ require "Mail/Send.pm" })
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require 'Mail/Send.pm' } }) { } 0 0 0
280 {
281 0 foreach my $recipient ( @{ $Control->{'to'}{'mail'} } )
282 {
283 0 ▶ if( not eval
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { my $server_admin = $ENV{"SERVER_ADMIN"} || "root"; my $msg = "Mail::Send"->new; $msg->to($recipient); $msg->subject("Error in $script_name"); my $fh = $msg->open; print $fh "File: $script_name\n\n"; print $fh $errfile; print $fh $info; print $fh "\n<EOF>\n"; $fh->close } }) 0 0 0
284 {
285 0 ▶ my $server_admin = $ENV{ SERVER_ADMIN } || 'root';
Condition0%0/2
$ENV{'SERVER_ADMIN'} || 'root'
l!l
00
MC/DC0%0/1
$ENV{'SERVER_ADMIN'} || 'root'
$ENV{'SERVER_ADMIN'}
Truth table0%0/2
A
A= $ENV{'SERVER_ADMIN'}
Aresult
11
00
286 0 my $msg = new Mail::Send;
287 0 $msg->to( $recipient );
288 0 $msg->subject( "Error in $script_name" );
289 # Doesn't work :-( $msg->set('From' => "$Module <$server_admin>");
290  
291 0 my $fh = $msg->open;
292 0 print $fh "File: $script_name\n\n";
293 0 print $fh $errfile;
294 0 print $fh $info;
295 0 print $fh "\n<EOF>\n";
296  
297 0 $fh->close;
298 })
299 {
300 0 $Control->{'to'}{'browser'} = 1;
301 0 ▶ $errfile .= "\n$Module (Mail::Send):\n$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
302 0 $errfile .= "\n$Module: Could not mail to '$recipient'\n\n";
303 }
304 }
305 }
306 else
307 {
308 0 $Control->{'to'}{'browser'} = 1;
309 0 $errfile .= "\n$Module: $@\n\n";
310 }
311 }
312  
313 2 ▶ if( $Control->{'to'}{'browser'} or $DEBUG )
Branch: 2 branches
BranchTrueFalseTotal
if ($CGI::Debug::Control->{'to'}{'browser'} or $CGI::Debug::DEBUG) { } 2 0 2
elsif (defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0) { } 0 0 0
Condition33%1/3
$CGI::Debug::Control->{"to"}{"browser"} or $CGI::Debug::DEBUG
l!l&&r!l&&!r
200
MC/DC0%0/2
$CGI::Debug::Control->{"to"}{"browser"} or $CGI::Debug::DEBUG
$CGI::Debug::Control->{"to"}{"browser"} $CGI::Debug::DEBUG
Truth table33%1/3
A or B
A= $CGI::Debug::Control->{"to"}{"browser"}B= $CGI::Debug::DEBUG
ABresult
1X1
011
000
314 {
315 2 ▶ if( defined $Body_length and $Body_length == 0 )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0) { } 0 2 2
elsif (defined $CGI::Debug::Content_type and $CGI::Debug::Content_type eq 'text/html') { } 1 1 2
Condition33%1/3
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
!ll&&!rl&&r
020
MC/DC0%0/2
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
defined $CGI::Debug::Body_length $CGI::Debug::Body_length == 0
Truth table33%1/3
A and B
A= defined $CGI::Debug::Body_lengthB= $CGI::Debug::Body_length == 0
ABresult
0X0
100
111
316 {
317 0 print "Content-type: text/html\n\n";
318 0 print "<html><head><title>$Module response</title></head><body>\n";
319 0 print "<h2>$script_name</h2>\n";
320 0 print "<plaintext>\n";
321 }
322 ▶ elsif( defined $Content_type and $Content_type eq "text/html")
Condition66%2/3
defined $CGI::Debug::Content_type and $CGI::Debug::Content_type eq "text/html"
!ll&&!rl&&r
011
MC/DC50%1/2
defined $CGI::Debug::Content_type and $CGI::Debug::Content_type eq "text/html"
defined $CGI::Debug::Content_type $CGI::Debug::Content_type eq "text/html"
Truth table66%2/3
A and B
A= defined $CGI::Debug::Content_typeB= $CGI::Debug::Content_type eq "text/html"
ABresult
0X0
100
111
323 {
324 1 ▶ print $$out_ref if defined $$out_ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$out_ref 1 0 1
325  
326 1 ▶ if( not defined $Body_length or $Body_length )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $CGI::Debug::Body_length or $CGI::Debug::Body_length) 1 0 1
Condition33%1/3
not defined $CGI::Debug::Body_length or $CGI::Debug::Body_length
l!l&&r!l&&!r
010
MC/DC0%0/2
not defined $CGI::Debug::Body_length or $CGI::Debug::Body_length
not defined $CGI::Debug::Body_length $CGI::Debug::Body_length
Truth table33%1/3
not(A) or B
A= not defined $CGI::Debug::Body_lengthB= $CGI::Debug::Body_length
ABresult
1X1
011
000
327 {
328 1 print "<hr>";
329 }
330  
331 1 print "<h2>$script_name</h2>\n";
332 1 print "<plaintext>\n";
333 }
334 else
335 {
336 1 ▶ print $$out_ref if defined $$out_ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$out_ref 1 0 1
337  
338  
339 1 print "\n\n";
340 1 ▶ print "<PLAINTEXT>\n" if not defined $Content_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $CGI::Debug::Content_type 0 1 1
341 1 ▶ print("-"x60,"\n\n") if not defined $Body_length or $Body_length;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $CGI::Debug::Body_length or $CGI::Debug::Body_length 1 0 1
Condition33%1/3
not defined $CGI::Debug::Body_length or $CGI::Debug::Body_length
l!l&&r!l&&!r
010
MC/DC0%0/2
not defined $CGI::Debug::Body_length or $CGI::Debug::Body_length
not defined $CGI::Debug::Body_length $CGI::Debug::Body_length
Truth table33%1/3
not(A) or B
A= not defined $CGI::Debug::Body_lengthB= $CGI::Debug::Body_length
ABresult
1X1
011
000
342 1 print "\t$script_name\n\n\n";
343 }
344  
345 2 print $errfile;
346 2 print $info;
347  
348 2 print "\n<EOF>\n";
349 }
350 ▶ elsif( defined $Body_length and $Body_length == 0 )
Condition0%0/3
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
defined $CGI::Debug::Body_length $CGI::Debug::Body_length == 0
Truth table0%0/3
A and B
A= defined $CGI::Debug::Body_lengthB= $CGI::Debug::Body_length == 0
ABresult
0X0
100
111
351 {
352 0 ▶ if( defined $Control->{'set'}{'error_document'} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CGI::Debug::Control->{'set'}{'error_document'}) { } 0 0 0
353 {
354 0 print "Status: 302 Moved\nLocation: $Control->{'set'}{'error_document'}\n\n";
355 }
356 else
357 {
358 0 print "Content-type: text/html\n\n";
359 0 print "<html><head><title>CGI Error</title></head><body>\n";
360 0 print "<h1>CGI Error</h1>\n";
361 0 print "<p>An error occured while generating this page.\n";
362 0 print "The webmaster has now been notified.\n";
363 0 print "</body></html>\n";
364 }
365 }
366 else
367 {
368 # Errors - no HTML output
369 #
370 0 ▶ print $$out_ref if defined $$out_ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$out_ref 0 0 0
371 }
372  
373 2 $?=1; # Indicate the error
374 }
375 else
376 {
377 # No errors
378 #
379 0 ▶ print $$out_ref if defined $$out_ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$out_ref 0 0 0
380 }
381  
382 2 ▶ unless( $DEBUG > 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::Debug::DEBUG > 1) 2 0 2
383 {
384 2 select OLDERR; # To get rid of warnings...
385 2 select OLDOUT; # To get rid of warnings...
386  
387 2 close OLDOUT;
388 }
389 2 select STDOUT;
390  
391 2 close STDOUT;
392 #
393 # Sometimes, there are some stuff left in the buffer. Strange!!!
394 # This is for 5.005_02. There seem to be output from print
395 # statements, that should never have been executed, because of
396 # compile errors. This close stops that text from getting out.
397 #
398 # The value of $? seems to be used for determining if there was a
399 # compile error or not. If not setting $? to 1, perl vill execute
400 # the program AFTER this END. (On some systems)
401 }
402  
403 sub key_values
404 0 ▶{
Subroutine key_values: not called CC=8 SCAR=42.8
Pod undocumented
405 0 my( $name, $hashr ) = @_;
406 0 my @keys = sort keys %$hashr;
407  
408 0 my $key_length = 0;
409 0 foreach( @keys )
410 {
411 0 ▶ $key_length = length if length > $key_length;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $key_length 0 0 0
412 }
413  
414 0 my $info = "\n".$name."\n".('-'x length($name))."\n";
415 0 foreach my $key ( @keys )
416 {
417 0 my $p_length = $Control->{'set'}{'param_length'};
418  
419 # Take arrayrefs or a scalar value
420 0 ▶ my $valuesr = ( ref $hashr->{$key} ? $hashr->{$key} : [$hashr->{$key}] );
Branch: 1 branch
BranchTrueFalseTotal
ref $hashr->{$key} ? : 0 0 0
421 0 foreach my $val ( @$valuesr )
422 {
423 0 my( $value, $tot, $trunc);
424 0 ▶ if( not defined $val )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val) { } 0 0 0
425 {
426 0 $value = "";
427 0 $tot = 0;
428 0 $trunc = " undefined";
429 }
430 else
431 {
432 0 $value = substr( $val, 0, $p_length );
433 0 $tot = length( $val );
434 0 ▶ $trunc = ( $tot>$p_length ? '...' : '' );
Branch: 1 branch
BranchTrueFalseTotal
$tot > $p_length ? : 0 0 0
435 }
436 0 $info .= sprintf("%-*s =%4s[%.*s]%s\n",
437 $key_length, $key, $tot,
438 $p_length, $value, $trunc);
439 }
440 }
441 0 $info .= "\n";
442  
443 0 return $info;
444 }
445  
446 sub report_params
447 0 ▶{
Subroutine report_params: not called CC=1 SCAR=6.9
Pod undocumented
448 0 return &key_values( 'Parameters', { map{ $_, [&CGI::param($_)] } &CGI::param } );
449 }
450  
451 sub report_cookies
452 0 ▶{
Subroutine report_cookies: not called CC=1 SCAR=6.9
Pod undocumented
453 0 return &key_values( 'Cookies', { map{ $_, &CGI::cookie($_) } &CGI::cookie() } );
454 }
455  
456 sub report_environment
457 0 ▶{
Subroutine report_environment: not called CC=1 SCAR=6.9
Pod undocumented
458 0 return &key_values( 'Environment', \%ENV );
459 }
460  
461 sub header_control
462 2 ▶{
Subroutine header_control: called CC=13 SCAR=37.1
Pod undocumented
463 2 my $outfile = "";
464 2 my $errfile = "";
465  
466 2 ▶ unless( $DEBUG > 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($CGI::Debug::DEBUG > 1) 2 0 2
467 {
468 2 close STDOUT;
469 2 open( STDOUT, ">&OLDOUT" );
470  
471 2 ▶ if( open OUT, "${File_base}-out-$$" )
Branch: 1 branch
BranchTrueFalseTotal
if (open OUT, "$CGI::Debug::File_base-out-${$}") { } 2 0 2
472 {
473 2 $outfile = join '', <OUT>;
474 2 close OUT;
475 2 ▶ unlink "${File_base}-out-$$" or
Branch: 1 branch
BranchTrueFalseTotal
unlink "$CGI::Debug::File_base-out-${$}" or $errfile .= "\n\nCouldn't delete $CGI::Debug::File_base-out-${$}: $!\n" 2 0 2
476 $errfile .= "\n\nCouldn't delete ${File_base}-out-$$: $!\n";
477 }
478 else
479 {
480 0 $errfile .= "\nCouldn't open ${File_base}-out-$$: $!\n";
481 }
482 }
483  
484 2 ($Content_type, $Body_length) = &header_ok( \$outfile );
485 2 ▶ $errfile .= "Body_length UNDEF\n" if not defined $Body_length;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $CGI::Debug::Body_length 0 2 2
486  
487 2 ▶ if( $Content_type )
Branch: 2 branches
BranchTrueFalseTotal
if ($CGI::Debug::Content_type) { } 2 0 2
elsif (length $outfile == 0) { } 0 0 0
488 {
489 # NOP
490 }
491 elsif( length $outfile == 0 )
492 {
493 0 $errfile .= "\nYour program doesn't produce ANY output!\n\n";
494 }
495 else
496 {
497 0 ▶ if( not $? )
Branch: 1 branch
BranchTrueFalseTotal
unless ($?) 0 0 0
498 {
499 0 $errfile .= "\nMalformed header!\n\n";
500 0 $errfile .= "--- Program output below -----------------------\n";
501 0 $errfile .= $outfile."\n";
502 0 $errfile .= "-------------------------------------------------\n\n";
503 }
504 }
505  
506 2 ▶ if( (defined $Body_length and $Body_length == 0) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 and $CGI::Debug::Control->{"report"}{"empty_body"} and $CGI::Debug::Content_type and not $?) 0 2 2
Condition33%4/12
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 and $CGI::Debug::Control->{"report"}{"empty_body"} and $CGI::Debug::Content_type and not $?
!ll&&!rl&&r
200
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 and $CGI::Debug::Control->{"report"}{"empty_body"} and $CGI::Debug::Content_type
!ll&&!rl&&r
200
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 and $CGI::Debug::Control->{"report"}{"empty_body"}
!ll&&!rl&&r
200
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0
!ll&&!rl&&r
020
MC/DC0%0/5
defined $CGI::Debug::Body_length and $CGI::Debug::Body_length == 0 and $CGI::Debug::Control->{"report"}{"empty_body"} and $CGI::Debug::Content_type and not $?
defined $CGI::Debug::Body_length $CGI::Debug::Body_length == 0 $CGI::Debug::Control->{"report"}{"empty_body"} $CGI::Debug::Content_type not $?
Truth table16%1/6
A and B and C and D and not(E)
A= defined $CGI::Debug::Body_lengthB= $CGI::Debug::Body_length == 0C= $CGI::Debug::Control->{"report"}{"empty_body"}D= $CGI::Debug::Content_typeE= not $?
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
507 $Control->{'report'}{'empty_body'} and
508 $Content_type and not $? )
509 {
510 0 $errfile .= "\nEmpty body!\n\n";
511 0 $errfile .= "--- Here is the header --------------------------\n";
512 0 $errfile .= $outfile."\n";
513 0 $errfile .= "-------------------------------------------------\n\n";
514 }
515  
516 2 return( $errfile, \$outfile );
517 }
518  
519 sub header_ok
520 2 ▶{
Subroutine header_ok: called CC=9 SCAR=23.3
Pod undocumented
521 2 my( $ofr ) = @_; # Output file reference
522  
523 2 my $token = '[\x21\x23-\x27\x2A\x2B\x2D\x2E0-9A-Z\x5E-z\x7E]+';
524 2 my $nctl = '[\x20-\x7E]*';
525 2 my $crlf = '(\r\n|\r|\n)';
526 2 my $content = 'unknown'; #Default
527 2 my $lcrlf = $crlf;
528 2 my $length = length($$ofr);
529  
530 2 ▶ if( $$ofr =~ m/\G($token):($nctl)($crlf)/gmco )
Branch: 1 branch
BranchTrueFalseTotal
if ($$ofr =~ /\G($token):($nctl)($crlf)/cgmo) 2 0 2
531 {
532 2 my $name = $1;
533 2 my $val = $2;
534 2 my $pos = pos($$ofr);
535 2 $lcrlf = $3;
536  
537 2 while()
538 {
539 2 ▶ if( $$ofr =~ m/\G[ \t]+($nctl)$lcrlf/gmco )
Branch: 1 branch
BranchTrueFalseTotal
if ($$ofr =~ /\G[ \t]+($nctl)$lcrlf/cgmo) 0 2 2
540 {
541 0 $val .= $1;
542 0 next;
543 }
544 2 ▶ if( $name =~ m/content-type/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /content-type/i) 2 0 2
545 {
546 2 ▶ $content = 'text/html' if $val=~ m/\btext\/html\b/sio;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ m[\btext/html\b]iso 1 1 2
547 2 ▶ $content = 'text/plain' if $val=~ m/\btext\/plain\b/sio;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ m[\btext/plain\b]iso 0 2 2
548 }
549  
550 2 $$ofr =~ m/\G($token):($nctl)$lcrlf/gmco;
551 2 $name = $1; $val = $2;
552  
553 2 ▶ last if $pos == pos($$ofr);
Branch: 1 branch
BranchTrueFalseTotal
if $pos == pos $$ofr 2 0 2
554 0 $pos = pos($$ofr);
555 }
556  
557 2 ▶ $length = length($$ofr)-$pos || 0;
Condition50%1/2
length($$ofr) - $pos || 0
l!l
20
MC/DC0%0/1
length($$ofr) - $pos || 0
length($$ofr) - $pos
Truth table50%1/2
A
A= length($$ofr) - $pos
Aresult
11
00
558 }
559  
560 2 ▶ if( $$ofr =~ /\G($lcrlf)/gmco )
Branch: 1 branch
BranchTrueFalseTotal
if ($$ofr =~ /\G($lcrlf)/cgmo) 2 0 2
561 {
562 2 return( $content, $length-length($1) );
563 }
564 0 return(undef, 0);
565 }
566  
567 sub report_time
568 0 ▶{
Subroutine report_time: not called CC=1 SCAR=6.9
Pod undocumented
569 0 return sprintf("\nThis program finished in %.3f seconds.\n",
570 time-$Started);
571 }
572  
573  
574  
575 sub unravel
576 22 ▶{
Subroutine unravel: called CC=30 SCAR=47.8
Pod undocumented
577 # Recursivly set up a stucture in the image of a template structure.
578 # The template consist of legal values. If the input structure has
579 # a string, there it should be a HASH och ARRAY, it is constructed
580 # with an undefined value.
581 # Hashes can consist of other hashes or arrays or strings. Arrays
582 # can only consist of strings, that represent the legal values. Empty
583 # string values in the template, permits any scalar value, except
584 # references. Undefined values or empty hashes permits any thing.
585 # Arrays will be converted to a hash with the key value set to 1,
586 # but only if the template array is empty.
587 # After this preparation of the input structure, another algoritm
588 # could be used to give default values to the undefined nodes.
589  
590 22 my( $params, $struct, $name ) = @_;
591 22 my $result = undef;
592 22 my $params_ref = ref $params;
593 22 my $struct_ref = ref $struct;
594 22 ▶ $name ||= "the ref";
Condition100%2/2
$name ||= "the ref"
l!l
184
MC/DC100%1/1
$name ||= "the ref"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
595  
596 22 ▶ if( not defined $struct )
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $struct) { } 0 22 22
elsif (not $struct_ref) { } 4 18 22
elsif ($struct_ref eq 'ARRAY') { } 10 8 18
elsif ($struct_ref eq 'HASH') { } 8 0 8
597 {
598 0 return $params;
599 }
600 elsif( not $struct_ref )
601 {
602 4 ▶ if( $params_ref )
Branch: 1 branch
BranchTrueFalseTotal
if ($params_ref) 0 4 4
603 {
604 0 die "'$name' must be scalar...\n";
605 }
606  
607 4 return $params;
608 }
609 elsif( $struct_ref eq 'ARRAY' )
610 {
611 10 ▶ if( not $params_ref )
Branch: 3 branches
BranchTrueFalseTotal
if (not $params_ref) { } 4 6 10
elsif ($params_ref eq 'ARRAY') { } 0 6 6
elsif ($params_ref eq 'HASH') { } 6 0 6
612 {
613 4 ▶ if( not defined $params ) # Changed...
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $params) { } 0 4 4
614 {
615 0 $result = undef;
616 }
617 else
618 {
619 4 $result = [ $params ];
620 }
621 }
622 elsif( $params_ref eq 'ARRAY' )
623 {
624 0 $result = $params;
625 }
626 elsif( $params_ref eq 'HASH' )
627 {
628 6 my @list = ();
629 6 foreach my $thing ( keys %$params )
630 {
631 10 ▶ if( $params->{$thing} == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{$thing} == 1) { } 10 0 10
632 {
633 10 push @list, $thing;
634 }
635 else
636 {
637 0 die "'$name $thing' must be a simple 1...\n";
638 }
639 }
640 6 $result = \@list;
641 }
642 else
643 {
644 0 die "'$name' must be scalar or array ref...\n";
645 }
646  
647 10 ▶ if( @$struct )
Branch: 1 branch
BranchTrueFalseTotal
if (@$struct) { } 10 0 10
648 {
649 10 my $newref = {};
650 10 foreach my $val ( @$result )
651 {
652 14 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 14 14
653 14 ▶ if( ref $val )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val) { } 0 14 14
elsif (not grep({$val eq $_;} @$struct)) { } 0 14 14
654 {
655 0 die "'$name' must be scalar...\n";
656 }
657 66 elsif( not grep { $val eq $_ } @$struct )
658 {
659 0 my @sortstruct = sort @$struct;
660 0 die "'$val' in '$name' not one of qw(@sortstruct)\n";
661 }
662 14 $newref->{$val} = 1;
663 }
664 10 return $newref;
665 }
666 else
667 {
668 0 ▶ return undef unless defined $result; # Do not expand undefined branches
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 0 0
669  
670 0 my $newref = [];
671 0 foreach my $val ( @$result )
672 {
673 0 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
674 0 ▶ if( ref $val )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) 0 0 0
675 {
676 0 die "'$name' must be scalar...\n";
677 }
678 0 push @$newref, $val;
679 }
680 0 return $newref;
681 }
682 }
683 elsif( $struct_ref eq 'HASH' )
684 {
685 8 ▶ if( not $params_ref )
Branch: 3 branches
BranchTrueFalseTotal
if (not $params_ref) { } 0 8 8
elsif ($params_ref eq 'HASH') { } 8 0 8
elsif ($params_ref eq 'ARRAY') { } 0 0 0
686 {
687 0 $result = { $params => undef }; # The "undef" will later be defined
688 }
689 elsif( $params_ref eq 'HASH' )
690 {
691 8 $result = $params;
692 }
693 elsif( $params_ref eq 'ARRAY' )
694 {
695 0 $result = {};
696 0 foreach my $key ( @$params )
697 {
698 0 $result->{$key} = undef;
699 }
700 }
701 else
702 {
703 0 die "'$name' must be scalar or hash ref...\n";
704 }
705  
706 8 my $newref = {};
707 8 foreach my $key ( keys %$result )
708 {
709 18 ▶ next unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 18 18
710 18 my @struct_keys = keys %$struct;
711 18 ▶ if( @struct_keys and not grep { $key eq $_ } @struct_keys )
Branch: 1 branch
BranchTrueFalseTotal
if (@struct_keys and not grep({$key eq $_;} @struct_keys)) 0 18 18
Condition33%1/3
@struct_keys and not grep({$key eq $_;} @struct_keys)
!ll&&!rl&&r
0180
MC/DC0%0/2
@struct_keys and not grep({$key eq $_;} @struct_keys)
@struct_keys not grep({$key eq $_;} @struct_keys)
Truth table33%1/3
A and not(B)
A= @struct_keysB= not grep({$key eq $_;} @struct_keys)
ABresult
0X0
100
111
712 {
713 0 my @sorted = sort @struct_keys;
714 0 die "'$key' in '$name' not one of qw(@sorted)\n";
715 }
716  
717 18 $newref->{$key} = &unravel( $result->{$key}, $struct->{$key}, $key );
718 }
719  
720 8 return $newref;
721 }
722  
723 0 die "Internal error: ${Module}::unravel only supports scalars, hashes and arrays";
724 }
725  
726 sub set_defaults
727 2 ▶{
Subroutine set_defaults: called CC=33 SCAR=47.2
Pod undocumented
728 2 my $module_name = $Module;
729 2 $module_name =~ s/::/-/g;
730  
731 2 my $uid = (stat( $0 ))[4];
732 2 my $user = getpwuid($uid);
733  
734 ### Control to
735 #
736 2 my %default_to = (
737 browser => 1,
738 log => 1,
739 file => ["${File_base}-error.txt"],
740 mail => [$user],
741 );
742 2 foreach my $pref (keys %default_to)
743 {
744 8 ▶ foreach( CGI::cookie("${module_name}-to-$pref"),
Condition33%1/3
exists $ENV{"$module_name-to-$pref"} && $ENV{"$module_name-to-$pref"}
!ll&&!rl&&r
800
MC/DC0%0/2
exists $ENV{"$module_name-to-$pref"} && $ENV{"$module_name-to-$pref"}
exists $ENV{"$module_name-to-$pref"} $ENV{"$module_name-to-$pref"}
Truth table33%1/3
A && B
A= exists $ENV{"$module_name-to-$pref"}B= $ENV{"$module_name-to-$pref"}
ABresult
0X0
100
111
745 (exists $ENV{"${module_name}-to-$pref"}
746 and $ENV{"${module_name}-to-$pref"} ),
747 )
748 {
749 8 ▶ $_ and $Control->{'to'}{$pref}=$_ and last;
Branch: 1 branch
BranchTrueFalseTotal
$_ and $CGI::Debug::Control->{"to"}{$pref} = $_ and last 0 8 8
Condition33%1/3
$_ and $CGI::Debug::Control->{"to"}{$pref} = $_
!ll&&!rl&&r
800
MC/DC0%0/2
$_ and $CGI::Debug::Control->{"to"}{$pref} = $_
$_ $CGI::Debug::Control->{"to"}{$pref} = $_
Truth table33%1/3
A and B
A= $_B= $CGI::Debug::Control->{"to"}{$pref} = $_
ABresult
0X0
100
111
750 }
751 8 ▶ if( exists $Control->{'to'} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $CGI::Debug::Control->{"to"} and exists $CGI::Debug::Control->{"to"}{$pref} and not defined $CGI::Debug::Control->{"to"}{$pref}) 0 8 8
Condition33%2/6
exists $CGI::Debug::Control->{"to"} and exists $CGI::Debug::Control->{"to"}{$pref} and not defined $CGI::Debug::Control->{"to"}{$pref}
!ll&&!rl&&r
800
exists $CGI::Debug::Control->{"to"} and exists $CGI::Debug::Control->{"to"}{$pref}
!ll&&!rl&&r
800
MC/DC0%0/3
exists $CGI::Debug::Control->{"to"} and exists $CGI::Debug::Control->{"to"}{$pref} and not defined $CGI::Debug::Control->{"to"}{$pref}
exists $CGI::Debug::Control->{"to"} exists $CGI::Debug::Control->{"to"}{$pref} not defined $CGI::Debug::Control->{"to"}{$pref}
Truth table25%1/4
A and B and not(C)
A= exists $CGI::Debug::Control->{"to"}B= exists $CGI::Debug::Control->{"to"}{$pref}C= not defined $CGI::Debug::Control->{"to"}{$pref}
ABCresult
0XX0
10X0
1100
1111
752 exists $Control->{'to'}{$pref} and
753 not defined $Control->{'to'}{$pref})
754 {
755 0 $Control->{'to'}{$pref} = $default_to{$pref};
756 }
757 }
758  
759  
760 ### Control
761 #
762 2 my %default = (
763 report => 'environment',
764 on => 'warnings',
765 to => 'browser',
766 );
767 2 foreach my $pref ('report','on')
768 {
769 4 ▶ foreach( CGI::cookie("${module_name}-$pref"),
Condition33%1/3
exists $ENV{"$module_name-$pref"} && $ENV{"$module_name-$pref"}
!ll&&!rl&&r
400
MC/DC0%0/2
exists $ENV{"$module_name-$pref"} && $ENV{"$module_name-$pref"}
exists $ENV{"$module_name-$pref"} $ENV{"$module_name-$pref"}
Truth table33%1/3
A && B
A= exists $ENV{"$module_name-$pref"}B= $ENV{"$module_name-$pref"}
ABresult
0X0
100
111
770 (exists $ENV{"${module_name}-$pref"}
771 and $ENV{"${module_name}-$pref"} ),
772 )
773 {
774 4 ▶ $_ and $Control->{$pref}{$_}= 1 and last;
Branch: 1 branch
BranchTrueFalseTotal
$_ and $CGI::Debug::Control->{$pref}{$_} = 1 and last 0 4 4
Condition50%1/2
$_ and $CGI::Debug::Control->{$pref}{$_} = 1
!ll
40
MC/DC0%0/1
$_ and $CGI::Debug::Control->{$pref}{$_} = 1
$_
Truth table50%1/2
A
A= $_
Aresult
00
11
775 }
776 $Control->{$pref}
777 4 ▶ or $Control->{$pref}{$default{$pref}} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$CGI::Debug::Control->{$pref} or $CGI::Debug::Control->{$pref}{$default{$pref}} = 1 4 0 4
778 }
779  
780 ### Default for Control to
781 #
782 2 ▶ foreach( CGI::cookie("${module_name}-to"),
Condition33%1/3
exists $ENV{"$module_name-to"} && $ENV{"$module_name-to"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $ENV{"$module_name-to"} && $ENV{"$module_name-to"}
exists $ENV{"$module_name-to"} $ENV{"$module_name-to"}
Truth table33%1/3
A && B
A= exists $ENV{"$module_name-to"}B= $ENV{"$module_name-to"}
ABresult
0X0
100
111
783 (exists $ENV{"${module_name}-to"}
784 and $ENV{"${module_name}-to"} ),
785 )
786 {
787 2 ▶ $_ and $Control->{'to'}{$_}= $default_to{$_} and last;
Branch: 1 branch
BranchTrueFalseTotal
$_ and $CGI::Debug::Control->{"to"}{$_} = $default_to{$_} and last 0 2 2
Condition33%1/3
$_ and $CGI::Debug::Control->{"to"}{$_} = $default_to{$_}
!ll&&!rl&&r
200
MC/DC0%0/2
$_ and $CGI::Debug::Control->{"to"}{$_} = $default_to{$_}
$_ $CGI::Debug::Control->{"to"}{$_} = $default_to{$_}
Truth table33%1/3
A and B
A= $_B= $CGI::Debug::Control->{"to"}{$_} = $default_to{$_}
ABresult
0X0
100
111
788 }
789 $Control->{'to'} or $Control->{'to'}{$default{'to'}} =
790 2 ▶ $default_to{$default{'to'}};
Branch: 1 branch
BranchTrueFalseTotal
$CGI::Debug::Control->{"to"} or $CGI::Debug::Control->{"to"}{$default{"to"}} = $default_to{$default{"to"}} 0 2 2
791  
792  
793 ### Control set
794 #
795 2 my %default_set = (
796 param_length => 60,
797 );
798 2 foreach my $pref (keys %default_set)
799 {
800 2 ▶ foreach( CGI::cookie("${module_name}-set-$pref"),
Condition33%1/3
exists $ENV{"$module_name-set-$pref"} && $ENV{"$module_name-set-$pref"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $ENV{"$module_name-set-$pref"} && $ENV{"$module_name-set-$pref"}
exists $ENV{"$module_name-set-$pref"} $ENV{"$module_name-set-$pref"}
Truth table33%1/3
A && B
A= exists $ENV{"$module_name-set-$pref"}B= $ENV{"$module_name-set-$pref"}
ABresult
0X0
100
111
801 (exists $ENV{"${module_name}-set-$pref"} and $ENV{"${module_name}-set-$pref"} ),
802 )
803 {
804 2 ▶ $_ and $Control->{'set'}{$pref}=$_ and last;
Branch: 1 branch
BranchTrueFalseTotal
$_ and $CGI::Debug::Control->{"set"}{$pref} = $_ and last 0 2 2
Condition33%1/3
$_ and $CGI::Debug::Control->{"set"}{$pref} = $_
!ll&&!rl&&r
200
MC/DC0%0/2
$_ and $CGI::Debug::Control->{"set"}{$pref} = $_
$_ $CGI::Debug::Control->{"set"}{$pref} = $_
Truth table33%1/3
A and B
A= $_B= $CGI::Debug::Control->{"set"}{$pref} = $_
ABresult
0X0
100
111
805 }
806 $Control->{set}{$pref}
807 2 ▶ or $Control->{set}{$pref} = $default_set{$pref};
Branch: 1 branch
BranchTrueFalseTotal
$CGI::Debug::Control->{"set"}{$pref} or $CGI::Debug::Control->{"set"}{$pref} = $default_set{$pref} 0 2 2
808 }
809  
810  
811  
812  
813 # Set implications. ( If one option is alias for a group ) --> Not completed
814  
815 2 ▶ $Control->{'report'}{'everything'}=1 if $Control->{'report'}{'internals'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"internals"} 0 2 2
816 2 ▶ $Control->{'report'}{'environment'}=1 if $Control->{'report'}{'everything'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"everything"} 0 2 2
817 2 ▶ $Control->{'report'}{'html_compliance'}=1 if $Control->{'report'}{'everything'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"report"}{"everything"} 0 2 2
818 2 ▶ if( $Control->{'report'}{'environment'} )
Branch: 1 branch
BranchTrueFalseTotal
if ($CGI::Debug::Control->{"report"}{"environment"}) 0 2 2
819 {
820 0 $Control->{'report'}{$_}=1 foreach qw( empty_body time params cookies );
821 }
822 2 ▶ $Control->{'on'}{'warnings'} = 1 if $Control->{'on'}{'anything'};
Branch: 1 branch
BranchTrueFalseTotal
if $CGI::Debug::Control->{"on"}{"anything"} 2 0 2
823 2 $Control->{'on'}{'fatals'} = 1;
824  
825  
826 # Sanitycheck on values
827 2 eval { &unravel( $Control, $Reference ) };
828 2 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
829 {
830 0 %{$Control->{'report'}} = ( 'internals' => 1 );
831 0 $Control->{'on'}{'warnings'} = 1;
832 0 $Control->{'to'}{'browser'} = 1;
833 0 return "$@\n\n";
834 }
835 2 return "";
836 }
837  
838 2 1;
839  
840 __END__
↑ Summary