6

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, requires 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?

3 Answers 3

3

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);
1
  • 1
    A better way is CGI::Carp::set_die_handler(\&CGI::Carp::realdie). But it is global. Jun 28, 2012 at 13:10
3

By setting $CGI::Carp::TO_BROWSER variable to 0 you can suppress printing the HTML version of die messages.

1
  • I like this answer also, but daxim was faster, so I chose his. Thank you anyway. :)
    – simbabque
    Jun 29, 2012 at 9:25
2

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.

1
  • That is very sound advice. Thank you.
    – simbabque
    Jun 28, 2012 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.