[Catalyst] Can't detach from root / create action object

André Walker andre at andrewalker.net
Wed Nov 27 15:45:32 GMT 2013


On Wed, Nov 27, 2013 at 02:51:23PM +0000, Craig Chant wrote:
> So I assume
>
> $c->controller('ComplianceUpdate')->action_for('index');
>
> is returning an action object that is passed to detach.

True.

> However, your example just has a string path '/a/my_action_1' , how is that
> an action object?

It's not :) Catalyst magically converts that for you.

See this:

https://metacpan.org/source/JJNAPIORK/Catalyst-Runtime-5.90051/lib/Catalyst/Dispatcher.pm#L148

It either gets an action object, or it translates the path to an object for
you.

> Having just tested with:
>
> $c->detach('/complianceupdates/index');
>
> is working.
>
> So the question now is which is better...
>
> $c->controller('ComplianceUpdate')->action_for('index');
>
> or
>
> $c->detach('/complianceupdates/index');
>
> Pass a string or a pass an object?

I like the string option better. It's cleaner to read. But you should be fine
with both.

Cheers,
André




More information about the Catalyst mailing list