[cgiapp] How to retrieve 'action'

Richard Jones ra.jones at dpw.clara.co.uk
Wed Dec 3 09:07:02 EST 2008


Clayton Scott wrote:
> On Wed, Dec 3, 2008 at 6:03 AM, Richard Jones <ra.jones at dpw.clara.co.uk>wrote:
> 
>> As in Catalyst action. Currently doing this:
>>
>> my $action = (split '/', $ENV{PATH_INFO})[1];
>>
>> So in a request http://localhost/myapp/admin/list_users, the action would
>> be 'admin', so I can highlight the appropriate navigation link.
>>
>> But I'd assume there's a better way, something build-in to CGI::App?
>>
> 
> 
> The simplest idea is to just do this:
> 
> my $action = (split '/', $self->query->path_info)[1];

Yes, thanks, that gave me the idea to use c.query.path_info in the 
template (using CAP::TT) to achieve the desired result. Like this:

[% IF c.query.path_info.match('^/foo') %]id="selected"[% END %]

> If you are doing path based dispatching have you looked at the Routes Plugin
> ( http://search.cpan.org/dist/CGI-Application-Plugin-Routes/ )
> or the path_info option to mode_param (
> http://search.cpan.org/dist/CGI-Application/lib/CGI/Application.pm#mode_param())?

Not using Routes, but am using CA::Dispatch. I don't think mode_param is 
going to help as it seems to be a 'setter' rather than being able to 
tell me the class that Dispatch loaded.

> These options can make your life easier by setting the runmode (action) from
> the information in the path_info and then you
> can get the name of the current action via $self->current_run_mode.

I think it's $self->get_current_runmode, but it's not actually runmode I 
need, but the part of the url before it eg /myapp/foo/do_stuff 
translates to runmode/method do_stuff() in app Foo.pm, and it's 'foo' 
I'm after here.
-- 
Richard Jones


More information about the cgiapp mailing list