exit() - which is also, in general, not original.exit() can be called inside eval() , or even several nested evals - for example, if CGIshka decides to give the user a redirect somewhere in the depth of the calculations. At the same time, it calls the framework function, it does the print "Location: ..." and exit() .exit() cannot be done.die() (just like it does , for example, mod_perl), or goto . The problem with die() is that if exit() was called inside eval() , and after calling eval, the user will not pass an unknown error above by calling die() again (and guarantee this behavior after each eval in this CGI file I can not - I can rather guarantee that this usually does not happen), then exit() will simply lead to exit from the nearest eval() , which the CGI card that caused the redirect obviously did not expect!sub that_cgi_script {
...
eval { do_something() };
...
}
sub do_something {
# 1) may return if everything ok
# 2) may die on error, but such error non-important to
# calling code in above case and will be catched by
# eval and ignored
# 3) may redirect: print Location header and call exit()
}
my $FCGI_EXIT = "FCGI NORMAL EXIT\n";
BEGIN { *CORE::GLOBAL::exit = sub { die $FCGI_EXIT }; }
while (CGI::Fast->new()) {
eval { that_cgi_script(); };
die $@ if $@ && $@ ne $FCGI_EXIT;
$CGI::Fast::Ext_Request->Finish();
}
BEGIN { *CORE::GLOBAL::exit = sub { goto EXIT }; }
while (CGI::Fast->new()) {
eval { that_cgi_script(); };
die $@ if $@;
EXIT:
$CGI::Fast::Ext_Request->Finish();
}
goto problem that applies to this situation is the exit() call inside the sort . :) I sincerely believe that this CGIshka does not allow this to itself. Amen.goto in CORE::GLOBAL::exit ? It is alarming to me that goto does not use mod_perl, although it seems to be a more efficient solution than die() .Source: https://habr.com/ru/post/13681/
All Articles