Lazy/Utility/Debug.pm

filter: Statementstmt 7.8% 10 / 127 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 20.0% 3 / 15 Podpod 75.0% 9 / 12 totaltotal 12.1% 22 / 181 CC 24 SCAR 33.5
CC
24
Cov
7%
eparam
72.0
edump
30.0
edumpreplace
30.0
CRAP 28.6
« Lazy/Session.pm ↑ Summary Lazy/Authn.pm »
1 package CGI::Lazy::Utility::Debug;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #-------------------------------------------------------------------------------------------------------------------------------
9 0 ▶sub cookie {
Subroutine cookie: not called CC=1 SCAR=6.9
Pod documented
10 0 my $self = shift;
11 0 my $q = $self->q;
12  
13 print $q->header,
14 $q->start_html({-title => 'CGI Test Page'}),
15 $q->h1('Cookies'),
16 $q->table($q->th('Param'), $q->th('Value'),
17 map {
18 0 $q->TR($q->th({-style => "text-align:center"}, $_), $q->td({-style => "text-align:center"}, $q->cookie($_)))
19 } $q->cookie()
20 );
21  
22 }
23  
24 #-------------------------------------------------------------------------------------------------------------------------------
25 0 ▶sub config {
Subroutine config: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my $self = shift;
27
28 0 return $self->q->config;
29 }
30  
31 #-------------------------------------------------------------------------------------------------------------------------------
32 0 ▶sub defaultFile {
Subroutine defaultFile: not called CC=1 SCAR=6.9
Pod undocumented
33 0 my $self = shift;
34  
35 0 return $self->{_defaultFile};
36 }
37  
38 #-------------------------------------------------------------------------------------------------------------------------------
39 0 ▶sub dump {
Subroutine dump: not called CC=3 SCAR=24.8
Pod documented
40 0 my $self = shift;
41  
42 0 my $fulloutput = "<div id='debug'>\n";
43  
44 0 foreach my $thing (@_) {
45 0 ▶ if (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 0 0 0
46 0 my $output = Dumper($thing);
47  
48 0 $output =~ s/\n/<br>/g;
49 0 $output =~ s/ /&nbsp;/g;
50 0 $output =~ s/\t/&nbsp;&nbsp&nbsp;&nbsp;&nbsp;/g;
51  
52 0 $fulloutput .= $output;
53 } else {
54 0 $fulloutput .= $thing;
55 }
56 }
57  
58 0 $fulloutput .= "\n</div>";
59  
60 0 return $fulloutput;
61 }
62  
63 #-------------------------------------------------------------------------------------------------------------------------------
64 0 ▶sub edump {
Subroutine edump: not called CC=5 SCAR=34.0
Pod documented
65 0 my $self = shift;
66  
67 0 my $filename = $self->config->debugfile;
68 0 ▶ $filename = $self->defaultFile unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
69  
70 0 ▶ open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!);
Branch: 1 branch
BranchTrueFalseTotal
open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!) 0 0 0
71 0 local $\=$/;
72  
73 0 print OF '-'x20 . $self->timestamp() . '-'x20;
74  
75 0 foreach my $thing (@_) {
76 0 ▶ if (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 0 0 0
77 0 print OF Dumper($thing);
78 } else {
79 0 print OF $thing;
80 }
81 }
82  
83 0 print OF '-'x40;
84 0 print OF "\n\n";
85  
86 0 close OF;
87 }
88  
89 #-------------------------------------------------------------------------------------------------------------------------------
90 0 ▶sub edumpreplace {
Subroutine edumpreplace: not called CC=5 SCAR=34.0
Pod documented
91 0 my $self = shift;
92  
93 0 my $filename = $self->config->debugfile;
94 0 ▶ $filename = $self->defaultFile unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
95  
96 0 ▶ open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!);
Branch: 1 branch
BranchTrueFalseTotal
open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!) 0 0 0
97 0 local $\=$/;
98  
99 0 print OF '-'x20 . $self->timestamp() . '-'x20;
100  
101 0 foreach my $thing (@_) {
102 0 ▶ if (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 0 0 0
103 0 print OF Dumper($thing);
104 } else {
105 0 print OF $thing;
106 }
107 }
108  
109 0 print OF '-'x40;
110 0 print OF "\n\n";
111  
112 0 close OF;
113 }
114  
115 #-------------------------------------------------------------------------------------------------------------------------------
116 0 ▶sub eparam {
Subroutine eparam: not called CC=8 SCAR=42.8
Pod documented
117 0 my $self = shift;
118  
119 0 my $q = $self->q;
120  
121 0 my @list = $q->param();
122 0 my %param;
123  
124 0 foreach (@list) {
125 0 my @values = $q->param($_);
126 0 $param{$_} = \@values;
127 }
128  
129 0 my $filename = $self->config->debugfile;
130 0 ▶ $filename = $self->defaultFile unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
131  
132 0 ▶ open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!);
Branch: 1 branch
BranchTrueFalseTotal
open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!) 0 0 0
133  
134 0 local $\=$/;
135  
136 0 print OF '-'x20 . $self->timestamp() . '-'x20;
137 0 foreach my $key (keys %param) {
138 0 foreach (@{$param{$key}}) {
139 0 print OF "$key \t => \t $_";
140 }
141  
142 }
143  
144 0 foreach my $thing (@_) {
145 0 ▶ if (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 0 0 0
146 0 print OF Dumper($thing);
147 } else {
148 0 print OF $thing;
149 }
150 }
151  
152 0 print OF '-'x40;
153 0 print OF "\n\n";
154  
155 0 close OF;
156  
157 }
158  
159 #-------------------------------------------------------------------------------------------------------------------------------
160 0 ▶sub param {
Subroutine param: not called CC=4 SCAR=30.0
Pod documented
161 0 my $self = shift;
162  
163 0 my $q = $self->q;
164  
165 0 my @list = $q->param();
166 0 my %param;
167  
168 0 foreach (@list) {
169 0 my @values = $q->param($_);
170 0 $param{$_} = \@values;
171 }
172  
173 0 my $fulloutput;
174  
175 $fulloutput .= $q->div({-id => 'debug'},
176 $q->start_html({-title => 'CGI Test Page'}),
177 $q->h1('CGI Parameters'),
178 $q->table({-border => 1}, $q->th('Param'), $q->th('Value'),
179 0 map { my $name = $_;
180 0 map { $q->TR($q->th({-style => "text-align:center"}, $name), $q->td({-style => "text-align:center"}, $_))} @{$param{$name}};
181
182 } keys %param
183 )
184 );
185  
186 0 foreach my $thing (@_) {
187 0 ▶ if (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing) { } 0 0 0
188 0 my $output = Dumper($thing);
189  
190 0 $output =~ s/\n/<br>/g;
191 0 $output =~ s/ /&nbsp;/g;
192 0 $output =~ s/\t/&nbsp;&nbsp&nbsp;&nbsp;&nbsp;/g;
193  
194 0 $fulloutput .= $output;
195 } else {
196 0 $fulloutput .= $thing;
197 }
198 }
199  
200 0 return $fulloutput;
201 }
202  
203 #-------------------------------------------------------------------------------------------------------------------------------
204 0 ▶sub env {
Subroutine env: not called CC=4 SCAR=30.0
Pod documented
205 0 my $self = shift;
206  
207 0 my $q = $self->q;
208  
209 0 my %env_info = (
210 SERVER_SOFTWARE => "the server software",
211 SERVER_NAME => "the server hostname or IP address",
212 GATEWAY_INTERFACE => "the CGI specification revision",
213 SERVER_PROTOCOL => "the server protocol name",
214 SERVER_PORT => "the port number for the server",
215 REQUEST_METHOD => "the HTTP request method",
216 PATH_INFO => "the extra path info",
217 PATH_TRANSLATED => "the extra path info translated",
218 DOCUMENT_ROOT => "the server document root directory",
219 SCRIPT_NAME => "the script name",
220 QUERY_STRING => "the query string",
221 REMOTE_HOST => "the hostname of the client",
222 REMOTE_ADDR => "the IP address of the client",
223 AUTH_TYPE => "the authentication method",
224 REMOTE_USER => "the authenticated username",
225 REMOTE_IDENT => "the remote user is (RFC 931): ",
226 CONTENT_TYPE => "the media type of the data",
227 CONTENT_LENGTH => "the length of the request body",
228 HTTP_ACCEPT => "the media types the client acccepts",
229 HTTP_USER_AGENT => "the browser the client is using",
230 HTTP_REFERER => "the URL of the feferring page",
231 HTTP_COOKIE => "The cookie(s) the client sent"
232 );
233  
234 # Add additional variables defined by web server or browser
235 0 foreach my $name (keys %ENV) {
236 $env_info{$name} = "an extra variable provided by this server"
237 0 ▶ unless exists $env_info{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $env_info{$name} 0 0 0
238 }
239  
240 0 my $fulloutput;
241  
242 $fulloutput .= $q->div({-id => 'debug'}, $q->start_html({-title => 'A List of Envirornment Variables'}),
243 $q->h1('CGI Enviornment Variables'),
244 $q->table({-border => 1},
245 $q->Tr($q->th('Variable Name'), $q->th('Description'), $q->th('Value')),
246 0 ▶ map { $q->Tr($q->td($q->b($_)),$q->td($env_info{$_}), $q->i($q->td(($ENV{$_} || 'Not Defined')))) }
Condition0%0/2
$ENV{$_} || 'Not Defined'
l!l
00
MC/DC0%0/1
$ENV{$_} || 'Not Defined'
$ENV{$_}
Truth table0%0/2
A
A= $ENV{$_}
Aresult
11
00
247 sort keys %env_info,
248 )
249 );
250  
251 0 return $fulloutput;
252 }
253  
254 #-------------------------------------------------------------------------------------------------------------------------------
255 0 ▶sub q {
Subroutine q: not called CC=1 SCAR=6.9
Pod undocumented
256 0 my $self = shift;
257  
258 0 return $self->{_q};
259 }
260  
261 #-------------------------------------------------------------------------------------------------------------------------------
262 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
263 0 my $class = shift;
264 0 my $q = shift;
265  
266 0 my ($file, $path, $suffix) = fileparse($0);
267 0 $file .= ".log";
268  
269 0 my $self = {_q => $q, _defaultFile => $file};
270  
271 0 return bless $self, $class;
272 }
273  
274 #-------------------------------------------------------------------------------------------------------------------------------
275 0 ▶sub timestamp {
Subroutine timestamp: not called CC=1 SCAR=6.9
Pod documented
276 0 my ($sec, $min, $hour, $mday, $mon, $year) = (localtime(time))[0..5];
277 0 $year += 1900;
278  
279 0 my $seconds = sprintf("%02d", $sec);
280 0 my $minutes = sprintf("%02d", $min);
281 0 my $hours = sprintf("%02d", $hour);
282 0 my $day = sprintf("%02d", $mday);
283  
284 0 my %monthname = (
285 0=>'Jan',
286 1=>'Feb',
287 2=>'Mar',
288 3=>'Apr',
289 4=>'May',
290 5=>'Jun',
291 6=>'Jul',
292 7=>'Aug',
293 8=>'Sep',
294 9=>'Oct',
295 10=>'Nov',
296 11=>'Dec',
297 );
298  
299 0 my $monthname = $monthname{$mon};
300  
301 0 return "$year-$monthname-$day-$hours:$minutes:$seconds";
302  
303  
304 }
305  
306 1 1
307  
308 __END__
« Lazy/Session.pm ↑ Summary Lazy/Authn.pm »