agronbach has asked for the wisdom of the Perl Monks concerning the following question:

Hello once again wise monks,

I am still working on the same script I discussed here: CGI Script backgrounding and the short version of how it works is that I am forking and running the script as a background process in the child while the parent redirects to an auto-refreshing dummy page which is shortly after overwritten.

My current issue is I have two methods of error reporting, and I cannot figure out how to simultaneously support both of them.

Before the fork, I can use CGI::Carp to print error messages to the browser window from which the script was called.

After the fork, the child redirects its STDERR and STDOUT to the dummy HTML file, and errors are reported to that page.

This works wonderfully until Carp tries to report an error to that page. It works, it just looks horribly disgusting.

My question is how can I enable a module such as Carp for part of my main logic and them disable it later on? I tried using "no" to disable Carp in the child but this was unsuccessful.

Thank you for any/all wisdom!

Replies are listed 'Best First'.
Re: CGI Error Reporting
by Gangabass (Vicar) on Aug 18, 2011 at 02:46 UTC

    I think you can use set_die_handler with some global variable in the code to enable/disable Carp messages.

      I looked into that Carp's options, and also took some private messages into account, and I am just going to fork much earlier in my code, and run all the code that can throw fatal errors in the child process, and report it all the same way.

      Basically I have to report when the files being analyzed cannot be found in a way that the user understands. Carp doesn't do this as nicely as I can, so I am going to stop using it at this point except for debugging initial syntax errors.

      Thanks for the wisdom!