Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "CGI::Carp 3" | |
132 | .TH CGI::Carp 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | \&\fBCGI::Carp\fR \- CGI routines for writing to the HTTPD (or other) error log | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 1 | |
138 | \& use CGI::Carp; | |
139 | .Ve | |
140 | .PP | |
141 | .Vb 5 | |
142 | \& croak "We're outta here!"; | |
143 | \& confess "It was my fault: $!"; | |
144 | \& carp "It was your fault!"; | |
145 | \& warn "I'm confused"; | |
146 | \& die "I'm dying.\en"; | |
147 | .Ve | |
148 | .PP | |
149 | .Vb 2 | |
150 | \& use CGI::Carp qw(cluck); | |
151 | \& cluck "I wouldn't do that if I were you"; | |
152 | .Ve | |
153 | .PP | |
154 | .Vb 2 | |
155 | \& use CGI::Carp qw(fatalsToBrowser); | |
156 | \& die "Fatal error messages are now sent to browser"; | |
157 | .Ve | |
158 | .SH "DESCRIPTION" | |
159 | .IX Header "DESCRIPTION" | |
160 | \&\s-1CGI\s0 scripts have a nasty habit of leaving warning messages in the error | |
161 | logs that are neither time stamped nor fully identified. Tracking down | |
162 | the script that caused the error is a pain. This fixes that. Replace | |
163 | the usual | |
164 | .PP | |
165 | .Vb 1 | |
166 | \& use Carp; | |
167 | .Ve | |
168 | .PP | |
169 | with | |
170 | .PP | |
171 | .Vb 1 | |
172 | \& use CGI::Carp | |
173 | .Ve | |
174 | .PP | |
175 | And the standard \fIwarn()\fR, die (), \fIcroak()\fR, \fIconfess()\fR and \fIcarp()\fR calls | |
176 | will automagically be replaced with functions that write out nicely | |
177 | time-stamped messages to the \s-1HTTP\s0 server error log. | |
178 | .PP | |
179 | For example: | |
180 | .PP | |
181 | .Vb 3 | |
182 | \& [Fri Nov 17 21:40:43 1995] test.pl: I'm confused at test.pl line 3. | |
183 | \& [Fri Nov 17 21:40:43 1995] test.pl: Got an error message: Permission denied. | |
184 | \& [Fri Nov 17 21:40:43 1995] test.pl: I'm dying. | |
185 | .Ve | |
186 | .SH "REDIRECTING ERROR MESSAGES" | |
187 | .IX Header "REDIRECTING ERROR MESSAGES" | |
188 | By default, error messages are sent to \s-1STDERR\s0. Most \s-1HTTPD\s0 servers | |
189 | direct \s-1STDERR\s0 to the server's error log. Some applications may wish | |
190 | to keep private error logs, distinct from the server's error log, or | |
191 | they may wish to direct error messages to \s-1STDOUT\s0 so that the browser | |
192 | will receive them. | |
193 | .PP | |
194 | The \f(CW\*(C`carpout()\*(C'\fR function is provided for this purpose. Since | |
195 | \&\fIcarpout()\fR is not exported by default, you must import it explicitly by | |
196 | saying | |
197 | .PP | |
198 | .Vb 1 | |
199 | \& use CGI::Carp qw(carpout); | |
200 | .Ve | |
201 | .PP | |
202 | The \fIcarpout()\fR function requires one argument, which should be a | |
203 | reference to an open filehandle for writing errors. It should be | |
204 | called in a \f(CW\*(C`BEGIN\*(C'\fR block at the top of the \s-1CGI\s0 application so that | |
205 | compiler errors will be caught. Example: | |
206 | .PP | |
207 | .Vb 6 | |
208 | \& BEGIN { | |
209 | \& use CGI::Carp qw(carpout); | |
210 | \& open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or | |
211 | \& die("Unable to open mycgi-log: $!\en"); | |
212 | \& carpout(LOG); | |
213 | \& } | |
214 | .Ve | |
215 | .PP | |
216 | \&\fIcarpout()\fR does not handle file locking on the log for you at this point. | |
217 | .PP | |
218 | The real \s-1STDERR\s0 is not closed \*(-- it is moved to CGI::Carp::SAVEERR. Some | |
219 | servers, when dealing with \s-1CGI\s0 scripts, close their connection to the | |
220 | browser when the script closes \s-1STDOUT\s0 and \s-1STDERR\s0. CGI::Carp::SAVEERR is there to | |
221 | prevent this from happening prematurely. | |
222 | .PP | |
223 | You can pass filehandles to \fIcarpout()\fR in a variety of ways. The \*(L"correct\*(R" | |
224 | way according to Tom Christiansen is to pass a reference to a filehandle | |
225 | \&\s-1GLOB:\s0 | |
226 | .PP | |
227 | .Vb 1 | |
228 | \& carpout(\e*LOG); | |
229 | .Ve | |
230 | .PP | |
231 | This looks weird to mere mortals however, so the following syntaxes are | |
232 | accepted as well: | |
233 | .PP | |
234 | .Vb 5 | |
235 | \& carpout(LOG); | |
236 | \& carpout(main::LOG); | |
237 | \& carpout(main'LOG); | |
238 | \& carpout(\eLOG); | |
239 | \& carpout(\e'main::LOG'); | |
240 | .Ve | |
241 | .PP | |
242 | .Vb 1 | |
243 | \& ... and so on | |
244 | .Ve | |
245 | .PP | |
246 | FileHandle and other objects work as well. | |
247 | .PP | |
248 | Use of \fIcarpout()\fR is not great for performance, so it is recommended | |
249 | for debugging purposes or for moderate-use applications. A future | |
250 | version of this module may delay redirecting \s-1STDERR\s0 until one of the | |
251 | CGI::Carp methods is called to prevent the performance hit. | |
252 | .SH "MAKING PERL ERRORS APPEAR IN THE BROWSER WINDOW" | |
253 | .IX Header "MAKING PERL ERRORS APPEAR IN THE BROWSER WINDOW" | |
254 | If you want to send fatal (die, confess) errors to the browser, ask to | |
255 | import the special \*(L"fatalsToBrowser\*(R" subroutine: | |
256 | .PP | |
257 | .Vb 2 | |
258 | \& use CGI::Carp qw(fatalsToBrowser); | |
259 | \& die "Bad error here"; | |
260 | .Ve | |
261 | .PP | |
262 | Fatal errors will now be echoed to the browser as well as to the log. CGI::Carp | |
263 | arranges to send a minimal \s-1HTTP\s0 header to the browser so that even errors that | |
264 | occur in the early compile phase will be seen. | |
265 | Nonfatal errors will still be directed to the log file only (unless redirected | |
266 | with carpout). | |
267 | .Sh "Changing the default message" | |
268 | .IX Subsection "Changing the default message" | |
269 | By default, the software error message is followed by a note to | |
270 | contact the Webmaster by e\-mail with the time and date of the error. | |
271 | If this message is not to your liking, you can change it using the | |
272 | \&\fIset_message()\fR routine. This is not imported by default; you should | |
273 | import it on the \fIuse()\fR line: | |
274 | .PP | |
275 | .Vb 2 | |
276 | \& use CGI::Carp qw(fatalsToBrowser set_message); | |
277 | \& set_message("It's not a bug, it's a feature!"); | |
278 | .Ve | |
279 | .PP | |
280 | You may also pass in a code reference in order to create a custom | |
281 | error message. At run time, your code will be called with the text | |
282 | of the error message that caused the script to die. Example: | |
283 | .PP | |
284 | .Vb 9 | |
285 | \& use CGI::Carp qw(fatalsToBrowser set_message); | |
286 | \& BEGIN { | |
287 | \& sub handle_errors { | |
288 | \& my $msg = shift; | |
289 | \& print "<h1>Oh gosh</h1>"; | |
290 | \& print "<p>Got an error: $msg</p>"; | |
291 | \& } | |
292 | \& set_message(\e&handle_errors); | |
293 | \& } | |
294 | .Ve | |
295 | .PP | |
296 | In order to correctly intercept compile-time errors, you should call | |
297 | \&\fIset_message()\fR from within a BEGIN{} block. | |
298 | .SH "MAKING WARNINGS APPEAR AS HTML COMMENTS" | |
299 | .IX Header "MAKING WARNINGS APPEAR AS HTML COMMENTS" | |
300 | It is now also possible to make non-fatal errors appear as \s-1HTML\s0 | |
301 | comments embedded in the output of your program. To enable this | |
302 | feature, export the new \*(L"warningsToBrowser\*(R" subroutine. Since sending | |
303 | warnings to the browser before the \s-1HTTP\s0 headers have been sent would | |
304 | cause an error, any warnings are stored in an internal buffer until | |
305 | you call the \fIwarningsToBrowser()\fR subroutine with a true argument: | |
306 | .PP | |
307 | .Vb 4 | |
308 | \& use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | |
309 | \& use CGI qw(:standard); | |
310 | \& print header(); | |
311 | \& warningsToBrowser(1); | |
312 | .Ve | |
313 | .PP | |
314 | You may also give a false argument to \fIwarningsToBrowser()\fR to prevent | |
315 | warnings from being sent to the browser while you are printing some | |
316 | content where \s-1HTML\s0 comments are not allowed: | |
317 | .PP | |
318 | .Vb 5 | |
319 | \& warningsToBrowser(0); # disable warnings | |
320 | \& print "<script type=\e"text/javascript\e"><!--\en"; | |
321 | \& print_some_javascript_code(); | |
322 | \& print "//--></script>\en"; | |
323 | \& warningsToBrowser(1); # re-enable warnings | |
324 | .Ve | |
325 | .PP | |
326 | Note: In this respect \fIwarningsToBrowser()\fR differs fundamentally from | |
327 | \&\fIfatalsToBrowser()\fR, which you should never call yourself! | |
328 | .SH "CHANGE LOG" | |
329 | .IX Header "CHANGE LOG" | |
330 | 1.05 \fIcarpout()\fR added and minor corrections by Marc Hedlund | |
331 | <hedlund@best.com> on 11/26/95. | |
332 | .PP | |
333 | 1.06 \fIfatalsToBrowser()\fR no longer aborts for fatal errors within | |
334 | \fIeval()\fR statements. | |
335 | .PP | |
336 | 1.08 \fIset_message()\fR added and \fIcarpout()\fR expanded to allow for FileHandle | |
337 | objects. | |
338 | .PP | |
339 | 1.09 \fIset_message()\fR now allows users to pass a code \s-1REFERENCE\s0 for | |
340 | really custom error messages. croak and carp are now | |
341 | exported by default. Thanks to Gunther Birznieks for the | |
342 | patches. | |
343 | .PP | |
344 | 1.10 Patch from Chris Dean (ctdean@cogit.com) to allow | |
345 | module to run correctly under mod_perl. | |
346 | .PP | |
347 | 1.11 Changed order of > and < escapes. | |
348 | .PP | |
349 | 1.12 Changed \fIdie()\fR on line 217 to CORE::die to avoid \fB\-w\fR warning. | |
350 | .PP | |
351 | 1.13 Added \fIcluck()\fR to make the module orthogonal with Carp. | |
352 | More mod_perl related fixes. | |
353 | .PP | |
354 | 1.20 Patch from Ilmari Karonen (perl@itz.pp.sci.fi): Added | |
355 | \fIwarningsToBrowser()\fR. Replaced <\s-1CODE\s0> tags with <\s-1PRE\s0> in | |
356 | \fIfatalsToBrowser()\fR output. | |
357 | .PP | |
358 | 1.23 \fIineval()\fR now checks both $^S and inspects the message for the \*(L"eval\*(R" pattern | |
359 | (hack alert!) in order to accomodate various combinations of Perl and | |
360 | mod_perl. | |
361 | .SH "AUTHORS" | |
362 | .IX Header "AUTHORS" | |
363 | Copyright 1995\-2002, Lincoln D. Stein. All rights reserved. | |
364 | .PP | |
365 | This library is free software; you can redistribute it and/or modify | |
366 | it under the same terms as Perl itself. | |
367 | .PP | |
368 | Address bug reports and comments to: lstein@cshl.org | |
369 | .SH "SEE ALSO" | |
370 | .IX Header "SEE ALSO" | |
371 | Carp, CGI::Base, CGI::BasePlus, CGI::Request, CGI::MiniSvr, CGI::Form, | |
372 | CGI::Response |