You already answered your own question by following up to state that -exitval => 'NOEXIT' works. I had found this to work just fine, as well. But it wouldn't be Perl if it didn't arouse curiosity. I was curious if I could override CORE::GLOBAL::exit effectively. Turns out I can (though this isn't to say I should):
#!/usr/bin/env perl
use strict;
use warnings;
our $override_exit = 0;
BEGIN {
no warnings 'redefine';
*CORE::GLOBAL::exit = sub :prototype(;$) {
if ($override_exit) {
warn "EXIT_OVERRIDE\n";
}
else {
CORE::exit($_[0] // 0);
}
};
}
use Pod::Usage;
{
local $override_exit = 1;
print "Calling pod2usage(1)\n";
pod2usage(1);
print "We are still here after overriding exit.\n";
}
print "calling pod2usage with -exitval => 'NOEXIT'\n";
pod2usage(-exitval => 'NOEXIT');
print "We are still here after using -exitval => 'NOEXIT'.\n";
This produces the following output:
Calling pod2usage(1)
EXIT_OVERRIDE
We are still here after overriding exit.
calling pod2usage with -exitval => 'NOEXIT'
We are still here after using -exitval => 'NOEXIT'.
So this demonstrates that NOEXIT works, and that overriding CORE::GLOBAL::exit can work.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|