[Catalyst] How to get the name of the subroutine accessed?

Brian Cassidy brian.cassidy at gmail.com
Tue Dec 8 19:39:31 GMT 2009


2009/12/8 Octavian Râşniţă <orasnita at gmail.com>:
> Is there a similar method for $c->action that can be used for getting the
> name of the subroutine which is accessed?
>
> For example, if I have:
>
> sub main_action : Local {
>  my ($self, $c) = @_;
>  # Here I can use $c->action to get the name/of/the/main_action.
>
>  # But if I do:
>  $c->forward('another_subroutine');
> }
>
> sub another_subroutine {
>  my ($self, $c) = @_;
>  #Here I can't use $c->action for getting the name/of/the/another_subroutine
>  # because it would return the name/of/the/main_action.
> }
>
> I want to use that unique name of the private subroutine, because I want to
> include it in a hash which will be used as a cache key and it would be nice
> if if there would be a possibility to not need writing it manually.

If the information from my post from long ago [1] still holds true,
you should be able to use $c->stack->[ -1 ] to get the most "recent"
action.

-- 
Brian Cassidy (brian.cassidy at gmail.com)

[1] http://bricas.vox.com/library/post/catalyst-tip-were-we-forwarded-here.html



More information about the Catalyst mailing list