You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "John K. Sterling" <st...@covalent.net> on 2000/11/01 17:15:34 UTC
Re: return from nested functions
even better: Apache->exit(SERVER_ERROR);. or die SERVER_ERROR;. this is
documented in the eagle book:
ch9 - The Apache::Constants Class
"...
While the HTTP constants are generally used as return codes from
handler subroutines, it is also possible to use the builtin die()
function to jump out of a handler with a status code that will be
propagated back to Apache. Example:
unless (-r _) {
die FORBIDDEN;
}
"
sterling
On Wed, 1 Nov 2000, Paul J. Lucas wrote:
> On Wed, 1 Nov 2000, Paul J. Lucas wrote:
>
> > Ideally, I want to be able to do:
> >
> > sub foo {
> > if ( $serious_problem )
> > stop_now_dammit( SERVER_ERROR );
> > }
> >
> > anywhere in the code like:
> >
> > sub bar {
> > foo();
> > }
> >
> > and I do *NOT* have to "catch" anything after the point of
> > call, i.e., every call of foo() is similar to an "assertion" in
> > C, i.e., if you get to the line of code after it, it worked; if
> > it didn't work, you never get to the line after it.
>
> I figured out that I can do this by having stop_now_dammit()
> use $r->notes() to set a note of the status code, call
> Apache->exit(), and have the downstream handler check the note.
> If it's anything but OK, simply return that value and the
> normal Apache error handline mechanism kicks in. :)
>
> - Paul
>
Re: return from nested functions
Posted by "John K. Sterling" <st...@covalent.net>.
On Wed, 1 Nov 2000, Paul J. Lucas wrote:
> On Wed, 1 Nov 2000, John K. Sterling wrote:
>
> > even better: Apache->exit(SERVER_ERROR);
>
> The documentation for exit() deosnt' explicitly say you can do
> that. It mentions only "0" and "DONE" (see pp. 464-465).
it works though, Apache.xs:exit() passes the status value to
perl_util.c:perl_call_halt(), which checks:
int is_http_code =
((status >= 100) && (status < 600) && ERRSV_CAN_BE_HTTP);
...
if(is_http_code) {
croak("%d\n", status);
}
the croak() call is caught the same way 'die SERVER_ERROR' is.
>
> > or die SERVER_ERROR;
>
> But that works. Thanks! :)
>
> - Paul
>
Re: return from nested functions
Posted by "Paul J. Lucas" <pj...@best.com>.
On Wed, 1 Nov 2000, John K. Sterling wrote:
> even better: Apache->exit(SERVER_ERROR);
The documentation for exit() deosnt' explicitly say you can do
that. It mentions only "0" and "DONE" (see pp. 464-465).
> or die SERVER_ERROR;
But that works. Thanks! :)
- Paul