blib/lib/CGI/Lazy/Utility/Debug.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 126 | 7.1 |
branch | 0 | 24 | 0.0 |
condition | 0 | 2 | 0.0 |
subroutine | 3 | 15 | 20.0 |
pod | 9 | 12 | 75.0 |
total | 21 | 179 | 11.7 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package CGI::Lazy::Utility::Debug; | ||||||
2 | |||||||
3 | 1 | 1 | 5 | use strict; | |||
1 | 3 | ||||||
1 | 38 | ||||||
4 | |||||||
5 | 1 | 1 | 6 | use Data::Dumper; | |||
1 | 2 | ||||||
1 | 60 | ||||||
6 | 1 | 1 | 26 | use File::Basename; | |||
1 | 2 | ||||||
1 | 1844 | ||||||
7 | |||||||
8 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
9 | sub cookie { | ||||||
10 | 0 | 0 | 1 | my $self = shift; | |||
11 | 0 | my $q = $self->q; | |||||
12 | |||||||
13 | 0 | 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 | sub config { | ||||||
26 | 0 | 0 | 0 | my $self = shift; | |||
27 | |||||||
28 | 0 | return $self->q->config; | |||||
29 | } | ||||||
30 | |||||||
31 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
32 | sub defaultFile { | ||||||
33 | 0 | 0 | 0 | my $self = shift; | |||
34 | |||||||
35 | 0 | return $self->{_defaultFile}; | |||||
36 | } | ||||||
37 | |||||||
38 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
39 | sub dump { | ||||||
40 | 0 | 0 | 1 | my $self = shift; | |||
41 | |||||||
42 | 0 | my $fulloutput = " \n"; |
|||||
43 | |||||||
44 | 0 | foreach my $thing (@_) { | |||||
45 | 0 | 0 | if (ref $thing) { | ||||
46 | 0 | my $output = Dumper($thing); | |||||
47 | |||||||
48 | 0 | $output =~ s/\n/ /g; |
|||||
49 | 0 | $output =~ s/ / /g; | |||||
50 | 0 | $output =~ s/\t/   /g; | |||||
51 | |||||||
52 | 0 | $fulloutput .= $output; | |||||
53 | } else { | ||||||
54 | 0 | $fulloutput .= $thing; | |||||
55 | } | ||||||
56 | } | ||||||
57 | |||||||
58 | 0 | $fulloutput .= "\n"; | |||||
59 | |||||||
60 | 0 | return $fulloutput; | |||||
61 | } | ||||||
62 | |||||||
63 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
64 | sub edump { | ||||||
65 | 0 | 0 | 1 | my $self = shift; | |||
66 | |||||||
67 | 0 | my $filename = $self->config->debugfile; | |||||
68 | 0 | 0 | $filename = $self->defaultFile unless $filename; | ||||
69 | |||||||
70 | 0 | 0 | open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!); | ||||
71 | 0 | local $\=$/; | |||||
72 | |||||||
73 | 0 | print OF '-'x20 . $self->timestamp() . '-'x20; | |||||
74 | |||||||
75 | 0 | foreach my $thing (@_) { | |||||
76 | 0 | 0 | if (ref $thing) { | ||||
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 | sub edumpreplace { | ||||||
91 | 0 | 0 | 1 | my $self = shift; | |||
92 | |||||||
93 | 0 | my $filename = $self->config->debugfile; | |||||
94 | 0 | 0 | $filename = $self->defaultFile unless $filename; | ||||
95 | |||||||
96 | 0 | 0 | open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!); | ||||
97 | 0 | local $\=$/; | |||||
98 | |||||||
99 | 0 | print OF '-'x20 . $self->timestamp() . '-'x20; | |||||
100 | |||||||
101 | 0 | foreach my $thing (@_) { | |||||
102 | 0 | 0 | if (ref $thing) { | ||||
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 | sub eparam { | ||||||
117 | 0 | 0 | 1 | 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 | 0 | $filename = $self->defaultFile unless $filename; | ||||
131 | |||||||
132 | 0 | 0 | open OF, ">> /tmp/$filename" or $self->q->errorHandler->couldntOpenDebugFile($filename, $!); | ||||
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}}) { | |||||
0 | |||||||
139 | 0 | print OF "$key \t => \t $_"; | |||||
140 | } | ||||||
141 | |||||||
142 | } | ||||||
143 | |||||||
144 | 0 | foreach my $thing (@_) { | |||||
145 | 0 | 0 | if (ref $thing) { | ||||
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 | sub param { | ||||||
161 | 0 | 0 | 1 | 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 | 0 | $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}}; | |||||
0 | |||||||
0 | |||||||
181 | |||||||
182 | } keys %param | ||||||
183 | ) | ||||||
184 | ); | ||||||
185 | |||||||
186 | 0 | foreach my $thing (@_) { | |||||
187 | 0 | 0 | if (ref $thing) { | ||||
188 | 0 | my $output = Dumper($thing); | |||||
189 | |||||||
190 | 0 | $output =~ s/\n/ /g; |
|||||
191 | 0 | $output =~ s/ / /g; | |||||
192 | 0 | $output =~ s/\t/   /g; | |||||
193 | |||||||
194 | 0 | $fulloutput .= $output; | |||||
195 | } else { | ||||||
196 | 0 | $fulloutput .= $thing; | |||||
197 | } | ||||||
198 | } | ||||||
199 | |||||||
200 | 0 | return $fulloutput; | |||||
201 | } | ||||||
202 | |||||||
203 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
204 | sub env { | ||||||
205 | 0 | 0 | 1 | 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 | 0 | 0 | $env_info{$name} = "an extra variable provided by this server" | ||||
237 | unless exists $env_info{$name}; | ||||||
238 | } | ||||||
239 | |||||||
240 | 0 | my $fulloutput; | |||||
241 | |||||||
242 | 0 | 0 | $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')))) } | |||||
247 | sort keys %env_info, | ||||||
248 | ) | ||||||
249 | ); | ||||||
250 | |||||||
251 | 0 | return $fulloutput; | |||||
252 | } | ||||||
253 | |||||||
254 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
255 | sub q { | ||||||
256 | 0 | 0 | 0 | my $self = shift; | |||
257 | |||||||
258 | 0 | return $self->{_q}; | |||||
259 | } | ||||||
260 | |||||||
261 | #------------------------------------------------------------------------------------------------------------------------------- | ||||||
262 | sub new { | ||||||
263 | 0 | 0 | 1 | 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 | sub timestamp { | ||||||
276 | 0 | 0 | 1 | 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 | ||||||
307 | |||||||
308 | __END__ |