This example output:perl -e ' BEGIN { *CORE::GLOBAL::exit = sub { goto FASTCGI_NEXT_REQUEST; }; } while (1) { eval { that_cgi_script() }; FASTCGI_NEXT_REQUEST: last; } sub that_cgi_script { local $SIG{__DIE__} = sub { print "<p>error: $_[0]"; exit; print "XX +X\n" }; print "before buggy code\n"; eval { buggy_code() }; print "after buggy code\n"; } sub buggy_code { die "error!"; print "after die\n"; } '
before buggy code <p>error: error! at -e line 20. after buggy codei.e. goto doesn't work as expected, and execution continue after eval. Actually exit in $SIG{__DIE__} handler work like return - because "print "XXX"" doesn't executed.
I've found a workaround for this bug. In BEGIN block must be added no-op handler for CORE::GLOBAL::die (which just emulate how perl's handler work):
and now this example work correctly and output:*CORE::GLOBAL::die = sub { if ($SIG{__DIE__}) { my $s = $_[0]; $s .= sprintf " at %s line %d.\n", (caller)[1,2] if $s !~ /\n\z/ +; $SIG{__DIE__}->($s); } };
before buggy code <p>error: error! at -e line 27.Sadly, but I'm not ready to explain, why adding that handler force goto to work correctly. :( Probably it's because my handler isn't work exactly like perl's handler. But I run a lot of different tests, and my handler work exactly like perl default handler for all tests except example shown above.
In reply to Re: goto in CORE::GLOBAL::exit - is it safe?
by powerman
in thread goto in CORE::GLOBAL::exit - is it safe?
by powerman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |