On Thu, 28 Oct 1999, Public Interactive wrote:
> I'd like to be able to prematurely end the thread of execution
> within a Perl apache module from someplace *other than* the
> PerlHandler entry point subroutine (usually "handler()"). That is,
> when I'm a few subroutines deep inside my module, I want to be able
> to spit out an error page and have the module finish as if handler()
> had returned OK. Right now I'm painstakingly propagating return
> values back up to my handler() subroutine, but I'm hoping there's a
> better way.
for what it's worth, here's what i do:
package Foo::Bar;
use strict;
use Apache;
use Apache::Constants qw(:common);
use Foo::Error;
sub handler {
my $r = shift;
eval {
# any statements that could die go here....
do_something or die "can't do that";
};
return err_out($r, $@) if $@;
$r->content_type('text/html');
$r->send_http_header;
$r->print($t->output);
return OK;
}
sub err_out {
my $r = shift;
my $err = shift;
$r->push_handlers(PerlHandler => \&Foo::Error::handler);
$r->pnotes(ERROR_NAME, $err);
return DECLINED;
1;
# ----------------------------
package Foo::Error;
use strict;
use Apache;
use Apache::Constants qw(:common);
use CGI qw(:html);
use HTML::Template;
# custom stuff
use lib '/tech/bgeplib';
use BGEP::Splank::Constants;
sub handler {
my $r = shift;
my $err = $r->pnotes(ERROR_NAME) or return OK;
$r->content_type('text/html');
$r->send_http_header;
my $template = TEMPLATE_DIR.'Error.html';
my $t = HTML::Template->new(filename => $template,
die_on_bad_params => 0,
cache => 1);
$t->param('err', $err);
$r->print($t->output);
return OK;
}
1;
hth!
ken