[Catalyst] how to get controller path

Alok Sharma alok at deeproot.co.in
Wed Nov 21 06:01:40 GMT 2007

On Tuesday 20 November 2007 18:22:54 Matt S Trout wrote:
> On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote:
> > Given a path we have ways to get the uri using the method uri_for(path).
> > Is there a  possible way to get the controller path given the uri so I am
> > able to do some thing like this
> > 	$c->res->redirect(uri); $c->forward(controller_path(uri));
> Why can't you start off with a controller action?
> my $action = $c->controller('Foo')->action_for('bar'); #
> Controller::Foo->bar
> $c->res->redirect($c->uri_for($action));
> $c->forward($action->reverse);

I was trying to write a module where the user asks for a particular URI but 
for certain reasons ( say session expired or not yet logged etc. ) has to be 
authenticated again and then user will be automatically redirected to the 
requested page,in a way furnishing something before actual request is 
For this I saved the URI requested ( say as $path ) as a session variable, 
redirected to the authentication page ( say to the standard login page ). But 
the issue was to redirect to the page requested by the user for which I got 
back the URI path from the session variable, till here all fine. But without 
knowing the action for that URI name I cant forward to it. That is where I 
needed something like 		$c->forward(controller_path(uri));

Or is there another approach to this problem.

On Tue, Nov 20, 2007 at 08:30:58AM -0600, Peter Karman wrote:
> The Catalyst::Dispatcher seems to be the correct
> place to interrogate the action map for any given URL, maybe with
> get_action_by_path().

The dispatcher does produce the list of all the actions, but the process is 
complicated, if there is a way access the list of all actions that it 
produces then may be have to parse through the list to identify the right 

Regards Alok

More information about the Catalyst mailing list