On Wed 12 Dec 2007, Rolf Schaufelberger wrote:
> I'm on the way moving my app from mod_perl1 to mod_perl2.
> The app is build with HTML::Mason an MasonX::WebApp.
> Now I have a problem when trying to install a cleanup_handler.
> My expectations are, that the funtcion I call returns to the browser and
> move some long time computing to a cleanup_handler.
> The code I use (sample):
>
> ================
> use APR::Pool ();
>
> sub cleanup {
> my $arg = shift;
> for (1 .. $arg->{cnt} ) {
> print STDERR "$_ = ", $arg->{name}, "\n";
> sleep(1);
> }
> }
>
> sub T_cleanup {
> my $self= shift;
>
> # either
> my $r = $self->{__apache_req__};
> $r->pool->cleanup_register (\&cleanup, {name=> 'test', cnt=>10});
This should work, see below.
> # nor this works
> # my $p = APR::Pool->new();
> # $p->cleanup_register (\&cleanup, {name=> 'test', cnt=>10});
and it should not. $p is destroyed at the end of the subroutine. Hence the
cleanup is run at that time, that means before Perl returns to mod_perl.
> $self->redirect(path=>'/index.html');
> }
> =================
>
> So when I call my method T_cleanup, the redirect is done AFTER cleanup has
> counted down , i.e. after 10 seconds. I would expect that it returns at
> once, an cleanup starts working AFTER the redirect.
> The docs says, it would start the executen "after the pool goes out of
> scope", which should be after the request object gets detroyed. Right ?
>
> So what am I doing wrong ?
This one works for me:
<Perl>
package My::Test;
use strict;
use Apache2::RequestRec ();
use APR::Pool ();
use Apache2::Const qw/-compile OK REDIRECT/;
sub cleanup {
my $arg = shift;
for (1 .. $arg->{cnt} ) {
print STDERR "$_ = ", $arg->{name}, "\n";
sleep(1);
}
}
sub handler {
my $r=$_[0];
$r->pool->cleanup_register(\&cleanup, {name=> 'test', cnt=>10});
$r->headers_out->{Location}='http://blah.blah/';
return Apache2::Const::REDIRECT;
}
</Perl>
<Location /cleanup-test>
SetHandler modperl
PerlResponseHandler My::Test
</Location>
Torsten
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?