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

While in 'tinker' mode, I usually use CGI::Carp to send fatals to the browser. But I ran into an issue today where something I was doing in my main program was causing an error to spew out of CGI::Session. It took me a little longer than it should have to figure out what was going on, but it turned out that since the error was spitting out of the module instead of the main code, it wasn't trapped by CGI::Carp.

Of course looking in the server log gave the necessary clues. But since I was expecting to see errors show up in the browser while in development, I didn't immediately think to check the server's error log.

The easiest solution is to remember to check there when I observe what seems to be silent failure. But I'm wondering if there's a solution that would enable CGI::Session to fall under the CGI::Carp umbrella instead.

My current script sets up the carp handlers in a BEGIN block, as follows:

use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { sub handle_errors { my $msg = shift; print "<h2>Error trapped by CGI::Carp</h2>\n"; $msg = s/\n/<br />/g; print "<p>Message: $msg</p>\n<pre>\n"; foreach my $key ( keys %ENV ) { print " $key\t $ENV{$key}\n"; } print "</pre>\n"; } set_message(\&handle_errors); } use Modern::Perl; use CGI::Simple; use CGI::Session; # and so on...

Dave

Replies are listed 'Best First'.
Re: Sending warnings from CGI::Session to browser
by ikegami (Patriarch) on Jun 08, 2011 at 08:01 UTC

    By the way,

    sub foo { ... }

    is effectively

    BEGIN { *foo = sub { ... }; }

    You can move the sub out of the BEGIN.

Re: Sending warnings from CGI::Session to browser
by Anonymous Monk on Jun 08, 2011 at 08:02 UTC
    But I'm wondering if there's a solution that would enable CGI::Session to fall under the CGI::Carp umbrella instead.

    warningsToBrowser? $SIG{__WARN__}?