A. Pagaltzis wrote:
> * Michael G Schwern <[EMAIL PROTECTED]> [2007-02-27 06:25]:
>> $SIG{__DIE__} = sub {
>>     # We don't want to muck with death in an eval, but $^S isn't
>>     # totally reliable.  5.005_03 and 5.6.1 both do the wrong thing
>>     # with it.  Instead, we use caller.  This also means it runs under
>>     # 5.004!
>>     my $in_eval = 0;
>>     for( my $stack = 1;  my $sub = (CORE::caller($stack))[3];  $stack++ ) {
>>         $in_eval = 1 if $sub =~ /^\(eval\)/;
>>     }
>>     ...
>> };
>>
>> That's how you do it "right" and maintain any sort of backwards 
>> compatibility.
> 
> Owh goodnessssss arrrrragh *twitch*
> 
> Together with the contortions required to safely examine $@ after
> an eval I’m getting tempted to put Unbreak::Eval on the CPAN.

I was poking around in CGI::Carp and found this:

# The mod_perl package Apache::Registry loads CGI programs by calling
# eval.  These evals don't count when looking at the stack backtrace.
sub _longmess {
    my $message = Carp::longmess();
    $message =~ s,eval[^\n]+(ModPerl|Apache)/(?:Registry|Dispatch)\w*\.pm.*,,s
        if exists $ENV{MOD_PERL};
    return $message;
}

sub ineval {
  (exists $ENV{MOD_PERL} ? 0 : $^S) || _longmess() =~ /eval [\{\']/m
}

Reply via email to