home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / CGI::Carp.z / CGI::Carp
Encoding:
Text File  |  1998-10-30  |  5.9 KB  |  199 lines

  1.  
  2.  
  3.  
  4. CCCCGGGGIIII::::::::CCCCaaaarrrrpppp((((3333))))                                                      CCCCGGGGIIII::::::::CCCCaaaarrrrpppp((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      CCCCGGGGIIII::::::::CCCCaaaarrrrpppp - CGI routines for writing to the HTTPD (or other) error log
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.          use CGI::Carp;
  13.  
  14.          croak "We're outta here!";
  15.          confess "It was my fault: $!";
  16.          carp "It was your fault!";
  17.          warn "I'm confused";
  18.          die  "I'm dying.\n";
  19.  
  20.  
  21. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  22.      CGI scripts have a nasty habit of leaving warning messages in the error
  23.      logs that are neither time stamped nor fully identified.  Tracking down
  24.      the script that caused the error is a pain.  This fixes that.  Replace
  25.      the usual
  26.  
  27.          use Carp;
  28.  
  29.      with
  30.  
  31.          use CGI::Carp
  32.  
  33.      And the standard _w_a_r_n(), die (), _c_r_o_a_k(), _c_o_n_f_e_s_s() and _c_a_r_p() calls will
  34.      automagically be replaced with functions that write out nicely time-
  35.      stamped messages to the HTTP server error log.
  36.  
  37.      For example:
  38.  
  39.         [Fri Nov 17 21:40:43 1995] test.pl: I'm confused at test.pl line 3.
  40.         [Fri Nov 17 21:40:43 1995] test.pl: Got an error message: Permission denied.
  41.         [Fri Nov 17 21:40:43 1995] test.pl: I'm dying.
  42.  
  43.  
  44. RRRREEEEDDDDIIIIRRRREEEECCCCTTTTIIIINNNNGGGG EEEERRRRRRRROOOORRRR MMMMEEEESSSSSSSSAAAAGGGGEEEESSSS
  45.      By default, error messages are sent to STDERR.  Most HTTPD servers direct
  46.      STDERR to the server's error log.  Some applications may wish to keep
  47.      private error logs, distinct from the server's error log, or they may
  48.      wish to direct error messages to STDOUT so that the browser will receive
  49.      them.
  50.  
  51.      The carpout() function is provided for this purpose.  Since _c_a_r_p_o_u_t() is
  52.      not exported by default, you must import it explicitly by saying
  53.  
  54.         use CGI::Carp qw(carpout);
  55.  
  56.      The _c_a_r_p_o_u_t() function requires one argument, which should be a reference
  57.      to an open filehandle for writing errors.  It should be called in a BEGIN
  58.      block at the top of the CGI application so that compiler errors will be
  59.      caught.  Example:
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. CCCCGGGGIIII::::::::CCCCaaaarrrrpppp((((3333))))                                                      CCCCGGGGIIII::::::::CCCCaaaarrrrpppp((((3333))))
  71.  
  72.  
  73.  
  74.         BEGIN {
  75.           use CGI::Carp qw(carpout);
  76.           open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or
  77.             die("Unable to open mycgi-log: $!\n");
  78.           carpout(LOG);
  79.         }
  80.  
  81.      _c_a_r_p_o_u_t() does not handle file locking on the log for you at this point.
  82.  
  83.      The real STDERR is not closed -- it is moved to SAVEERR.  Some servers,
  84.      when dealing with CGI scripts, close their connection to the browser when
  85.      the script closes STDOUT and STDERR.  SAVEERR is used to prevent this
  86.      from happening prematurely.
  87.  
  88.      You can pass filehandles to _c_a_r_p_o_u_t() in a variety of ways.  The
  89.      "correct" way according to Tom Christiansen is to pass a reference to a
  90.      filehandle GLOB:
  91.  
  92.          carpout(\*LOG);
  93.  
  94.      This looks weird to mere mortals however, so the following syntaxes are
  95.      accepted as well:
  96.  
  97.          carpout(LOG);
  98.          carpout(main::LOG);
  99.          carpout(main'LOG);
  100.          carpout(\LOG);
  101.          carpout(\'main::LOG');
  102.  
  103.          ... and so on
  104.  
  105.      Use of _c_a_r_p_o_u_t() is not great for performance, so it is recommended for
  106.      debugging purposes or for moderate-use applications.  A future version of
  107.      this module may delay redirecting STDERR until one of the CGI::Carp
  108.      methods is called to prevent the performance hit.
  109.  
  110. MMMMAAAAKKKKIIIINNNNGGGG PPPPEEEERRRRLLLL EEEERRRRRRRROOOORRRRSSSS AAAAPPPPPPPPEEEEAAAARRRR IIIINNNN TTTTHHHHEEEE BBBBRRRROOOOWWWWSSSSEEEERRRR WWWWIIIINNNNDDDDOOOOWWWW
  111.      If you want to send fatal (die, confess) errors to the browser, ask to
  112.      import the special "fatalsToBrowser" subroutine:
  113.  
  114.          use CGI::Carp qw(fatalsToBrowser);
  115.          die "Bad error here";
  116.  
  117.      Fatal errors will now be echoed to the browser as well as to the log.
  118.      CGI::Carp arranges to send a minimal HTTP header to the browser so that
  119.      even errors that occur in the early compile phase will be seen.  Nonfatal
  120.      errors will still be directed to the log file only (unless redirected
  121.      with carpout).
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. CCCCGGGGIIII::::::::CCCCaaaarrrrpppp((((3333))))                                                      CCCCGGGGIIII::::::::CCCCaaaarrrrpppp((((3333))))
  137.  
  138.  
  139.  
  140. CHANGE LOG
  141.      1.05 _c_a_r_p_o_u_t() added and minor corrections by Marc Hedlund
  142.           <hedlund@best.com> on 11/26/95.
  143.  
  144.      1.06 _f_a_t_a_l_s_T_o_B_r_o_w_s_e_r() no longer aborts for fatal errors within
  145.           _e_v_a_l() statements.
  146.  
  147. AAAAUUUUTTTTHHHHOOOORRRRSSSS
  148.      Lincoln D. Stein <lstein@genome.wi.mit.edu>.  Feel free to redistribute
  149.      this under the Perl Artistic License.
  150.  
  151. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  152.      Carp, CGI::Base, CGI::BasePlus, CGI::Request, CGI::MiniSvr, CGI::Form,
  153.      CGI::Response
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.