[cgiapp] How to retrieve 'action'

Clayton Scott clayton.scott at gmail.com
Wed Dec 3 07:56:39 EST 2008


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];

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())?

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.

Clayton

-- 

Clayton Scott
clayton.scott at gmail.com


More information about the cgiapp mailing list