[Catalyst] running a function once on all requests

John Napiorkowski jjn1056 at yahoo.com
Mon Jun 4 21:30:51 GMT 2007

--- Steve Francia <steve at takkle.com> wrote:

> Eden Cardim wrote:
> > On 6/4/07, Steve Francia <steve at takkle.com> wrote:
> >>  Anyone know of any good reason to do it
> differently, or has anyone used
> >> other strategies in the past?
> >
> > That looks like auto-chaining, you might want to
> take a look at "auto"
> > actions.
> >
> >
> >
> > http://dev.catalystframework.org/wiki/FlowChart
> >
> It does look like auto-chaining, so perhaps I should
> restate my original
> question.
> What I want to do is a bit more specific.
> I am using chaining a decent amount, often chaining
> across different
> controllers.
> The end result of what I want to do is pass into the
> template (TT) the
> top most level controller name IE the controller
> closest to root.
> This is accessed using $c->namespace, from within
> the controller.
> If I use auto-chaining like:
>     sub auto : Private {
>         my ( $self, $c ) = @_;
>         $c->stash->{ controller } = $c->namespace;
>     }
> in the root controller (Root.pm). It works until I
> chain across more
> than one controller.
> 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.
> Perhaps there is a different approach with
> autochaining I should try.

I've found similar things when using actions across
controllers with Chained actions.  If you have a
chained private path the spans more than one
controller it's the controller that owns the
terminating action that is associated with
$c->controller, not the root of the chain.  This
caused me trouble once as well; I guess for me it was
more intuitive that way always I can't rationally
defend it as better than the way it actually works.

At least the auto and chained action behavior is

One thing that might bite you here is that to me it
sounds like you are tying the controller a bit too
tightly to your view logic.  Because it sounds like
you are performing some sort of logic in the view
based on the controller name.  I don't know your exact
need so I could be totally wrong here, but I thought
to mention it.  It could work better for you in the
end to decouple the view and controller and if you
need to access some logic or data in the view that
resides in the controller using an intermediary class
might be better.

Anyway, I'd be interested to here more about your


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Catalyst mailing list