.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.el \{\
.    de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "CGI::Carp 3pm"
.TH CGI::Carp 3pm "2017-03-22" "perl v5.10.1" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
\&\fBCGI::Carp\fR \- \s-1CGI\s0 routines for writing to the \s-1HTTPD\s0 (or other) error log
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&    use CGI::Carp;
\&
\&    croak "We\*(Aqre outta here!";
\&    confess "It was my fault: $!";
\&    carp "It was your fault!";   
\&    warn "I\*(Aqm confused";
\&    die  "I\*(Aqm dying.\en";
\&
\&    use CGI::Carp qw(cluck);
\&    cluck "I wouldn\*(Aqt do that if I were you";
\&
\&    use CGI::Carp qw(fatalsToBrowser);
\&    die "Fatal error messages are now sent to browser";
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
\&\s-1CGI\s0 scripts have a nasty habit of leaving warning messages in the error
logs that are neither time stamped nor fully identified.  Tracking down
the script that caused the error is a pain.  This fixes that.  Replace
the usual
.PP
.Vb 1
\&    use Carp;
.Ve
.PP
with
.PP
.Vb 1
\&    use CGI::Carp
.Ve
.PP
And the standard \fIwarn()\fR, die (), \fIcroak()\fR, \fIconfess()\fR and \fIcarp()\fR calls
will automagically be replaced with functions that write out nicely
time-stamped messages to the \s-1HTTP\s0 server error log.
.PP
For example:
.PP
.Vb 3
\&   [Fri Nov 17 21:40:43 1995] test.pl: I\*(Aqm confused at test.pl line 3.
\&   [Fri Nov 17 21:40:43 1995] test.pl: Got an error message: Permission denied.
\&   [Fri Nov 17 21:40:43 1995] test.pl: I\*(Aqm dying.
.Ve
.SH "REDIRECTING ERROR MESSAGES"
.IX Header "REDIRECTING ERROR MESSAGES"
By default, error messages are sent to \s-1STDERR\s0.  Most \s-1HTTPD\s0 servers
direct \s-1STDERR\s0 to the server's error log.  Some applications may wish
to keep private error logs, distinct from the server's error log, or
they may wish to direct error messages to \s-1STDOUT\s0 so that the browser
will receive them.
.PP
The \f(CW\*(C`carpout()\*(C'\fR function is provided for this purpose.  Since
\&\fIcarpout()\fR is not exported by default, you must import it explicitly by
saying
.PP
.Vb 1
\&   use CGI::Carp qw(carpout);
.Ve
.PP
The \fIcarpout()\fR function requires one argument, which should be a
reference to an open filehandle for writing errors.  It should be
called in a \f(CW\*(C`BEGIN\*(C'\fR block at the top of the \s-1CGI\s0 application so that
compiler errors will be caught.  Example:
.PP
.Vb 6
\&   BEGIN {
\&     use CGI::Carp qw(carpout);
\&     open(LOG, ">>/usr/local/cgi\-logs/mycgi\-log") or
\&       die("Unable to open mycgi\-log: $!\en");
\&     carpout(LOG);
\&   }
.Ve
.PP
\&\fIcarpout()\fR does not handle file locking on the log for you at this point.
Also, note that \fIcarpout()\fR does not work with in-memory file handles, although
a patch would be welcome to address that.
.PP
The real \s-1STDERR\s0 is not closed \*(-- it is moved to CGI::Carp::SAVEERR.  Some
servers, when dealing with \s-1CGI\s0 scripts, close their connection to the
browser when the script closes \s-1STDOUT\s0 and \s-1STDERR\s0.  CGI::Carp::SAVEERR is there to
prevent this from happening prematurely.
.PP
You can pass filehandles to \fIcarpout()\fR in a variety of ways.  The \*(L"correct\*(R"
way according to Tom Christiansen is to pass a reference to a filehandle
\&\s-1GLOB:\s0
.PP
.Vb 1
\&    carpout(\e*LOG);
.Ve
.PP
This looks weird to mere mortals however, so the following syntaxes are
accepted as well:
.PP
.Vb 5
\&    carpout(LOG);
\&    carpout(main::LOG);
\&    carpout(main\*(AqLOG);
\&    carpout(\eLOG);
\&    carpout(\e\*(Aqmain::LOG\*(Aq);
\&
\&    ... and so on
.Ve
.PP
FileHandle and other objects work as well.
.PP
Use of \fIcarpout()\fR is not great for performance, so it is recommended
for debugging purposes or for moderate-use applications.  A future
version of this module may delay redirecting \s-1STDERR\s0 until one of the
CGI::Carp methods is called to prevent the performance hit.
.SH "MAKING PERL ERRORS APPEAR IN THE BROWSER WINDOW"
.IX Header "MAKING PERL ERRORS APPEAR IN THE BROWSER WINDOW"
If you want to send fatal (die, confess) errors to the browser, ask to
import the special \*(L"fatalsToBrowser\*(R" subroutine:
.PP
.Vb 2
\&    use CGI::Carp qw(fatalsToBrowser);
\&    die "Bad error here";
.Ve
.PP
Fatal errors will now be echoed to the browser as well as to the log.  CGI::Carp
arranges to send a minimal \s-1HTTP\s0 header to the browser so that even errors that
occur in the early compile phase will be seen.
Nonfatal errors will still be directed to the log file only (unless redirected
with carpout).
.PP
Note that fatalsToBrowser may \fBnot\fR work well with mod_perl version 2.0
and higher.
.SS "Changing the default message"
.IX Subsection "Changing the default message"
By default, the software error message is followed by a note to
contact the Webmaster by e\-mail with the time and date of the error.
If this message is not to your liking, you can change it using the
\&\fIset_message()\fR routine.  This is not imported by default; you should
import it on the \fIuse()\fR line:
.PP
.Vb 2
\&    use CGI::Carp qw(fatalsToBrowser set_message);
\&    set_message("It\*(Aqs not a bug, it\*(Aqs a feature!");
.Ve
.PP
You may also pass in a code reference in order to create a custom
error message.  At run time, your code will be called with the text
of the error message that caused the script to die.  Example:
.PP
.Vb 9
\&    use CGI::Carp qw(fatalsToBrowser set_message);
\&    BEGIN {
\&       sub handle_errors {
\&          my $msg = shift;
\&          print "<h1>Oh gosh</h1>";
\&          print "<p>Got an error: $msg</p>";
\&      }
\&      set_message(\e&handle_errors);
\&    }
.Ve
.PP
In order to correctly intercept compile-time errors, you should call
\&\fIset_message()\fR from within a BEGIN{} block.
.SH "DOING MORE THAN PRINTING A MESSAGE IN THE EVENT OF PERL ERRORS"
.IX Header "DOING MORE THAN PRINTING A MESSAGE IN THE EVENT OF PERL ERRORS"
If fatalsToBrowser in conjunction with set_message does not provide 
you with all of the functionality you need, you can go one step 
further by specifying a function to be executed any time a script
calls \*(L"die\*(R", has a syntax error, or dies unexpectedly at runtime
with a line like \*(L"undef\->\fIexplode()\fR;\*(R".
.PP
.Vb 7
\&    use CGI::Carp qw(set_die_handler);
\&    BEGIN {
\&       sub handle_errors {
\&          my $msg = shift;
\&          print "content\-type: text/html\en\en";
\&          print "<h1>Oh gosh</h1>";
\&          print "<p>Got an error: $msg</p>";
\&
\&          #proceed to send an email to a system administrator,
\&          #write a detailed message to the browser and/or a log,
\&          #etc....
\&      }
\&      set_die_handler(\e&handle_errors);
\&    }
.Ve
.PP
Notice that if you use \fIset_die_handler()\fR, you must handle sending
\&\s-1HTML\s0 headers to the browser yourself if you are printing a message.
.PP
If you use \fIset_die_handler()\fR, you will most likely interfere with 
the behavior of fatalsToBrowser, so you must use this or that, not 
both.
.PP
Using \fIset_die_handler()\fR sets SIG{_\|_DIE_\|_} (as does fatalsToBrowser),
and there is only one SIG{_\|_DIE_\|_}. This means that if you are 
attempting to set SIG{_\|_DIE_\|_} yourself, you may interfere with 
this module's functionality, or this module may interfere with 
your module's functionality.
.SS "\s-1SUPPRESSING\s0 \s-1PERL\s0 \s-1ERRORS\s0 \s-1APPEARING\s0 \s-1IN\s0 \s-1THE\s0 \s-1BROWSER\s0 \s-1WINDOW\s0"
.IX Subsection "SUPPRESSING PERL ERRORS APPEARING IN THE BROWSER WINDOW"
A problem sometimes encountered when using fatalsToBrowser is
when a \f(CW\*(C`die()\*(C'\fR is done inside an \f(CW\*(C`eval\*(C'\fR body or expression.
Even though the
fatalsToBrower support takes precautions to avoid this,
you still may get the error message printed to \s-1STDOUT\s0.
This may have some undesireable effects when the purpose of doing the
eval is to determine which of several algorithms is to be used.
.PP
By setting \f(CW$CGI::Carp::TO_BROWSER\fR to 0 you can suppress printing the \f(CW\*(C`die\*(C'\fR messages
but without all of the complexity of using \f(CW\*(C`set_die_handler\*(C'\fR.
You can localize this effect to inside \f(CW\*(C`eval\*(C'\fR bodies if this is desireable:
For example:
.PP
.Vb 5
\& eval {
\&   local $CGI::Carp::TO_BROWSER = 0;
\&   die "Fatal error messages not sent browser"
\& }
\& # $@ will contain error message
.Ve
.SH "MAKING WARNINGS APPEAR AS HTML COMMENTS"
.IX Header "MAKING WARNINGS APPEAR AS HTML COMMENTS"
It is now also possible to make non-fatal errors appear as \s-1HTML\s0
comments embedded in the output of your program.  To enable this
feature, export the new \*(L"warningsToBrowser\*(R" subroutine.  Since sending
warnings to the browser before the \s-1HTTP\s0 headers have been sent would
cause an error, any warnings are stored in an internal buffer until
you call the \fIwarningsToBrowser()\fR subroutine with a true argument:
.PP
.Vb 4
\&    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
\&    use CGI qw(:standard);
\&    print header();
\&    warningsToBrowser(1);
.Ve
.PP
You may also give a false argument to \fIwarningsToBrowser()\fR to prevent
warnings from being sent to the browser while you are printing some
content where \s-1HTML\s0 comments are not allowed:
.PP
.Vb 5
\&    warningsToBrowser(0);    # disable warnings
\&    print "<script type=\e"text/javascript\e"><!\-\-\en";
\&    print_some_javascript_code();
\&    print "//\-\-></script>\en";
\&    warningsToBrowser(1);    # re\-enable warnings
.Ve
.PP
Note: In this respect \fIwarningsToBrowser()\fR differs fundamentally from
\&\fIfatalsToBrowser()\fR, which you should never call yourself!
.SH "OVERRIDING THE NAME OF THE PROGRAM"
.IX Header "OVERRIDING THE NAME OF THE PROGRAM"
CGI::Carp includes the name of the program that generated the error or
warning in the messages written to the log and the browser window.
Sometimes, Perl can get confused about what the actual name of the
executed program was.  In these cases, you can override the program
name that CGI::Carp will use for all messages.
.PP
The quick way to do that is to tell CGI::Carp the name of the program
in its use statement.  You can do that by adding
\&\*(L"name=cgi_carp_log_name\*(R" to your \*(L"use\*(R" statement.  For example:
.PP
.Vb 1
\&    use CGI::Carp qw(name=cgi_carp_log_name);
.Ve
.PP
\&.  If you want to change the program name partway through the program,
you can use the \f(CW\*(C`set_progname()\*(C'\fR function instead.  It is not
exported by default, you must import it explicitly by saying
.PP
.Vb 1
\&    use CGI::Carp qw(set_progname);
.Ve
.PP
Once you've done that, you can change the logged name of the program
at any time by calling
.PP
.Vb 1
\&    set_progname(new_program_name);
.Ve
.PP
You can set the program back to the default by calling
.PP
.Vb 1
\&    set_progname(undef);
.Ve
.PP
Note that this override doesn't happen until after the program has
compiled, so any compile-time errors will still show up with the
non-overridden program name
.SH "CHANGE LOG"
.IX Header "CHANGE LOG"
3.51 Added \f(CW$CGI::Carp::TO_BROWSER\fR
.PP
1.29 Patch from Peter Whaite to fix the unfixable problem of CGI::Carp
     not behaving correctly in an \fIeval()\fR context.
.PP
1.05 \fIcarpout()\fR added and minor corrections by Marc Hedlund
     <hedlund@best.com> on 11/26/95.
.PP
1.06 \fIfatalsToBrowser()\fR no longer aborts for fatal errors within
     \fIeval()\fR statements.
.PP
1.08 \fIset_message()\fR added and \fIcarpout()\fR expanded to allow for FileHandle
     objects.
.PP
1.09 \fIset_message()\fR now allows users to pass a code \s-1REFERENCE\s0 for 
     really custom error messages.  croak and carp are now
     exported by default.  Thanks to Gunther Birznieks for the
     patches.
.PP
1.10 Patch from Chris Dean (ctdean@cogit.com) to allow 
     module to run correctly under mod_perl.
.PP
1.11 Changed order of &gt; and &lt; escapes.
.PP
1.12 Changed \fIdie()\fR on line 217 to CORE::die to avoid \fB\-w\fR warning.
.PP
1.13 Added \fIcluck()\fR to make the module orthogonal with Carp.
     More mod_perl related fixes.
.PP
1.20 Patch from Ilmari Karonen (perl@itz.pp.sci.fi):  Added
     \fIwarningsToBrowser()\fR.  Replaced <\s-1CODE\s0> tags with <\s-1PRE\s0> in
     \fIfatalsToBrowser()\fR output.
.PP
1.23 \fIineval()\fR now checks both $^S and inspects the message for the \*(L"eval\*(R" pattern
     (hack alert!) in order to accommodate various combinations of Perl and
     mod_perl.
.PP
1.24 Patch from Scott Gifford (sgifford@suspectclass.com): Add support
     for overriding program name.
.PP
1.26 Replaced CORE::GLOBAL::die with the evil \f(CW$SIG\fR{_\|_DIE_\|_} because the
     former isn't working in some people's hands.  There is no such thing
     as reliable exception handling in Perl.
.PP
1.27 Replaced tell \s-1STDOUT\s0 with bytes=tell \s-1STDOUT\s0.
.SH "AUTHORS"
.IX Header "AUTHORS"
Copyright 1995\-2002, Lincoln D. Stein.  All rights reserved.
.PP
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
.PP
Address bug reports and comments to: lstein@cshl.org
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Carp, CGI::Base, CGI::BasePlus, CGI::Request, CGI::MiniSvr, CGI::Form,
CGI::Response
