[Catalyst] Re: How to redirect before some code excute
Eden Cardim
edencardim at gmail.com
Fri Oct 27 16:25:42 GMT 2006
On 10/26/06, Fayland Lam <fayland at gmail.com> wrote:
> Matt S Trout wrote:
> > Fayland Lam wrote:
> >> Lee Standen wrote:
> >>> It's a subroutine, right?
> >>>
> >>> Tried a return?....such as:
> >>>
> >>> $c->res->redirect('http://www.yahoo.com');
> >>> return undef;
> >>
> >> Indeed I want to run the 'while' loop in backend. 'return' would not
> >> run the loop I think.
> >
> > $c->res->redirect(...);
> > $c->finalize_headers;
> >
> > <while loop or whatever here>
> >
> > might do the trick
> >
>
> no, it doesn't work. maybe there is something concerned with 'butter',
> it's not sent immediately.
> and I use mod_perl2, so I'd like to have a try of system.
> Thanks any way.
It works if you manage to run your stuff after Catalyst calls
$c->finalize() in handle_request(). Funny, I just wrote a hack, err,
plugin yesterday which gives me the option to set up a hook that's
called right after $c->finalize(). I'm not sure if this is the correct
way to do it or if there are any side-effects, if any of the more
experient Catalyst users/developers think its a good idea for a
plugin, let me know and I'll can carve it up and release it.
I use mod_perl and haven't had any trouble so far, this approach lets
me delegate all the pre-fork management to apache. I have a Catalyst
front-end which adds jobs to a queue like mentioned before in the
thread and a another Catalyst server running XMLRPC that gets notified
about incoming jobs and runs them after responding to the XMLRPC
notification.
In MyApp.pm:
use Catalyst qw/AfterFinalize/;
In a controller action somewhere:
sub myaction : Local {
$c->res->body('running job');
$c->after_finalize(sub { run_job() } );
}
-- =
Eden Cardim
Instituto Baiano de Biotecnologia
N=FAcleo de Biologia Computacional e Gest=E3o de Informa=E7=F5es Biotecnol=
=F3gicas
Laborat=F3rio de Bioinform=E1tica
--
"you seem to think that 'close enough' is close enough...
please learn to be 'literal' around programming."
merlyn - on irc.freenode.net#perl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AfterFinalize.pm
Type: application/x-perl
Size: 376 bytes
Desc: not available
Url : http://jules.scsys.co.uk/pipermail/catalyst/attachments/20061027/2f15=
08ac/AfterFinalize.bin
More information about the Catalyst
mailing list