First of all, there's the special variable $^S that is set in a special way inside eval. Check perlvar [perl.org] for the details. So, you check its value in the $SIG{__DIE__} handler, and respond appropriately to its current value.
Second, I think I saw a module recently that did a
local $SIG{__DIE__};
before invoking the eval or even inside it, before doing anything dangerous.
Some modules even do
local $SIG{__DIE__} = 'DEFAULT';
though I don't know about any benefit. I guess there is none.
That special var looks like what I want! Thank you!. Although by now I've adopted a totally different approach to get around it.:) But I still wanted to know the answer, because this is going to bite me again.
I tried local and the DEFAULT thing, but it still became a problem because I'm using modules by other people that do eval's.
-- J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Unfortunately, it's just a problem you have to live with. I've got local $SIG{__DIE__}; scattered all over my code, not because I've written a DIE handler, but because Mason has one. I can see why they do it, but it's a nuisance. I'd really like a way for the handler to only apply in certain circumstances...
The consensus (that I only partially agree with) appears to be that every $SIG{__DIE__} handler is supposed to check $^S. So it really should be considered a bug in Mason.
Personally I would have preferred it if $SIG{__DIE__} handlers would just not be called in eval. Life would have been a lot simpler, then.
Surely there's more than one way to do it... (Score:2)
Second, I think I saw a module recently that did a
before invoking the eval or even inside it, before doing anything dangerous.
Some modules even do
though I don't know about any benefit. I guess there is none.
Re: (Score:2)
That special var looks like what I want! Thank you!. Although by now I've adopted a totally different approach to get around it. :) But I still wanted to know the answer, because this is going to bite me again.
I tried local and the DEFAULT thing, but it still became a problem because I'm using modules by other people that do eval's.
J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
Re: (Score:2)
-Dom
Re: (Score:2)
Personally I would have preferred it if $SIG{__DIE__} handlers would just not be called in eval. Life would have been a lot simpler, then.