In Perl, how can I disable CGI::Carp that was loaded in a required script?

cgi, perl

Solution

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);

Problem

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?

Original source