[Catalyst] running a function once on all requests

Eden Cardim edencardim at gmail.com
Mon Jun 4 21:06:01 GMT 2007


On 6/4/07, Steve Francia <steve at takkle.com> wrote:
>  Instead of the first, it gives me last controller in the chain, which leads
> me to believe that this method is either called once for each controller or
> called only once, but from the last controller in the chain.

It runs for all controllers in the hierarchy, top-most first. Even if
it ran the other way around, you'd still get the wrong result because
you're calling $c->namespace, which gives you the namespace of the
current running action, you want $self->namespace instead.

>  Perhaps there is a different approach with autochaining I should try.

you could do something like:

sub auto : Private {
    my($self, $c) = @_;
    push @{$c->stash->{controllers}}, $self->namespace;
    return 1;
}

# in Root
sub end : Private {
    my($self, $c) = @_;
    $c->stash{controller} = $c->stash->{controllers}[0];
}

Although I'm not sure if this is the best way to do it, I'd much
prefer this over subclassing since things can get messy if you need to
inherit from another controller like FormBuilder or REST.

-- 
Eden Cardim
Instituto Baiano de Biotecnologia
Núcleo de Biologia Computacional e Gestão de Informações Biotecnológicas
Laboratório de Bioinformática



More information about the Catalyst mailing list