use CGI::Carp qw ( fatalsToBrowser ); BEGIN { # The start_output and end_output routines should also be called # for normal (non-error) output sub start_output { # Put anything that needs to precede the error message here # For example, you might print "Content-type: text/plain\n\n" # or text/html plus the everything through the tag. } sub end_output { # Put anything that needs to follow the error message here # For example, an HTML session might print "" } sub carp_error { my $error_message = shift; start_output(); failure($error_message); end_output(); exit; } CGI::Carp::set_message(\&carp_error); # Prevent spurious "Content-type: text/html" sub override_fatals { $ENV{MOD_PERL} = 1; CGI::Carp::fatalsToBrowser(@_); } $main::SIG{__DIE__} =\&override_fatals; }