I've got a small Perl program that I want to run on the command line. I need to require
another Perl script (not a module) that someone else has written. That, in turn, require
s some other scripts. (I cannot do anything about the way this works).
Now, it is really annoying that one of these scripts has use CGI;
and use CGI::Carp qw(fatalsToBrowser)
in it. I do not want that. Having 15 lines of 500 Internal Server Error page
on my console every time something breaks is really getting on my nerves. I've tried
require 'otherscript.pl';
no CGI;
no CGI::Carp;
and
no CGI;
no CGI::Carp;
require 'otherscript.pl';
to unload it, like the use doc describes, but it doesn't work.
Can I somehow manipulate the symbol table or do some other magic to get rid of it?
There is no unimport
routine in the CGI::Carp package, so no
has no effect. Undo the relevant part of the import
routine manually.
Lexical scope (see caveat):
local $main::SIG{__DIE__} = \&CGI::Carp::realdie;
Global scope:
CGI::Carp::set_die_handler(\&CGI::Carp::realdie);
By setting $CGI::Carp::TO_BROWSER
variable to 0
you can suppress printing the HTML version of die messages.
Where does the code that uses fatalsToBrowser
come from? Whilst fatalsToBrowser
is a really useful development tool, it should only be used in development. In a production environment it can be argued that fatalsToBrowser
is a security risk as it potentially gives too much information to someone trying to crack your server.
So, by all means use the tricks that other people have mentioned to turn it off. But you should also do whatever you can to ensure that the offending code is changed so that it doesn't use fatalsToBrowser
in production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With