Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
REQ:
while ($query=CGI::Fast->new)
{
# Тело программы
}
next REQ;
"next" cannot be used to exit a block which returns a value such as "eval {}", "sub {}" or "do {}", and should not be used to exit a grep() or map() operation.Так что, увы, next не годится. Либо die, либо goto...
...
eval { do_something() };
die if $@ && $@ eq "PLEASE PROPAGATE: NORMAL EXIT\n";
...
use strict;
use CGI::Fast;
REQ:
while ($query=CGI::Fast->new)
{
&main_func()
}
sub main_func
{
Собственно программа.
}
package ApacheTestHandler;
sub handler {
# собственно программа
}
1;
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 "XXX\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 code
*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.
goto в CORE:: GLOBAL:: exit — где грабли?