Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things


by redcloud (Parson)
on Sep 14, 2000 at 00:56 UTC ( #32359=modulereview: print w/replies, xml ) Need Help??

Item Description: CGI routines for reporting errors

Review Synopsis: An excellent debugging tool for CGI scripts

If you're trying to debug a CGI script, CGI::Carp could be your best friend. It makes getting error messages from CGI scripts with a browser practically as easy as from other scripts at the command line.

My favorite feature is also the easiest to use. Import the special symbol fatalsToBrowser like this:         use CGI::Carp qw(fatalsToBrowser);

Now, if have a syntax error in your script that would abort execution due to compilation errors, say, instead of getting a server error from your HTTP server that isn't very informative, you get a message telling you that there are compilation errors. If I used perl -c more often, I probably wouldn't be so attached to this feature.

On the downside, information about what line the error is at doesn't show up in your browser. It would be nice if it did. However, you can retrieve that information from your HTTP server's error log.

Once you get past syntax errors, anything that you want to die() or croak() about will go to the browser, too, if you've imported fatalsToBrowser. If you want warnings to go to the browser as well, import the carpout() function and use it to redirect STDERR.

You can also use carpout() to redirect STDERR to your own log file, instead of the server's error log. Here's the example from perldoc CGI::Carp:

BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or die("Unable to open mycgi-log: $!\n"); carpout(LOG); }

These conveniences make CGI programming a lot easier, and they make CGI::Carp one of my favorite modules.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: modulereview [id://32359]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-09-26 00:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found