powerman has asked for the wisdom of the Perl Monks concerning the following question:
Now, in my FastCGI application, I must call this cgi script. Of course, I must intercept exit(), to prevent exiting to continue with FCGI->Accept(). There two options how to do this - with die():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() }
and with goto():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 q{} && $@ ne $FCGI_EXIT; $CGI::Fast::Ext_Request->Finish(); }
AFAIK recommended is first solution with die(), and it used in mod_perl. But die() unable to break more than one eval, and in example above in case "3) may redirect" after calling exit I'll not return into my FastCGI loop, but continue executing inside that_cgi_script() after it eval (which will not propagate my die()). Second solution with goto() will work correctly. But I'm not sure is it safe. perldoc -f goto says:BEGIN { *CORE::GLOBAL::exit = sub { goto EXIT }; } while (CGI::Fast->new()) { eval { that_cgi_script(); }; die $@ if $@ ne q{}; EXIT: $CGI::Fast::Ext_Request->Finish(); }
It may not be used to go into any construct that requires initialization, such as a subroutine or a "foreach" loop. It also can't be used to go into a construct that is optimized away, or to get out of a block or subroutine given to "sort".Looks like only possible case in my situation is calling exit() inside sort(). :) I believe this cgi script will not do this. Amen. Is there any other possible issues with goto() from CORE::GLOBAL::exit() handler?
P.S. A little offtopic, but any recommendations about CPAN modules for FastCGI support are welcome. Maybe it's better to use some other module instead of CGI::Fast because of some reason, etc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: goto in CORE::GLOBAL::exit - is it safe?
by sgt (Deacon) on Aug 30, 2007 at 15:40 UTC | |
by powerman (Friar) on Aug 30, 2007 at 15:52 UTC | |
|
Re: goto in CORE::GLOBAL::exit - is it safe?
by SFLEX (Chaplain) on Aug 30, 2007 at 16:08 UTC | |
by powerman (Friar) on Aug 30, 2007 at 16:15 UTC | |
by SFLEX (Chaplain) on Aug 30, 2007 at 16:22 UTC | |
by powerman (Friar) on Aug 30, 2007 at 16:41 UTC | |
by SFLEX (Chaplain) on Aug 30, 2007 at 17:12 UTC | |
|
Re: goto in CORE::GLOBAL::exit - is it safe?
by powerman (Friar) on Aug 31, 2007 at 13:58 UTC | |
by sgt (Deacon) on Aug 31, 2007 at 16:15 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |