Munkey has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I require your wisdom!

I am using Catalyst and am very happily chaining away, however, I was trying to use begin/end methods in my controllers to do controller-specific stuff which would be needed in the respective controller.

now when I have a Root, a Foo and a Foo::Bar controller, and call a path resolving to an action in Foo::Bar, I was expecting this:

Root->begin gets called

Foo->begin gets called

Foo::Bar->begin gets called

... called action doing stuff here, e.g. Foo::Bar->hello

Foo::Bar->end gets called

Foo->end gets called

Root->end comes last.

Is this expectation entirely off? Or is it spot on and I am doing something wrong somehow? I have built a simple Catalyst application like hinted at, and I only see Root->begin and Root->end ... If anyone could provide me with an insight on what I am wrong about or how to achieve what I would like, that would be really neat :)

Replies are listed 'Best First'.
Re: Catalyst begin/end methods
by Your Mother (Archbishop) on Feb 12, 2015 at 00:19 UTC

    http://dev.catalystframework.org/old-wiki/wiki/FlowChart/—try that. It’s old but I believe it’s still accurate. I think your understanding of begin is closer to what auto is. You get one begin and one end unless you specifically code around it. The resolution would also be easy to test in any specific cases, I think, by looking at the debug output of the test server. FWIW, I can’t remember ever needing begin. It is probably an indication of design mistake that could be better handled with an attribute attached to the class.

        thank you!

        I have ended up moving everything to auto, begin ( I was checking user permission to enter controller ) is better there anyhow - just return 0 to break flow,

        end ( preparing things for templates specific to that controller ) did not have to be in end, it was just a matter of taste I guess, and no logical reason to do it there.

        After reading the chart: my expectation was off, only the most specific match for begin and end is run. Auto does what I need here.

        Thank you for the information, I did not find the part on begin/end ( or overlooked it ) in the docs for some reason.

Re: Catalyst begin/end methods
by Anonymous Monk on Feb 12, 2015 at 00:10 UTC

    I was expecting this

    Why were you expecting that? What did the docs say?