[Catalyst] Programmatic way to determine the needed number of captures for an action?

Ash Berlin ash at cpan.org
Sat Nov 4 15:22:26 GMT 2006


John Napiorkowski wrote:
> --- Ash Berlin <ash at cpan.org> wrote:
> 
>> This has been discussed before, tho a fully
>> satisfactory solution never 
>> appeared. Something that we touched upon that could
>> work was to have a 
>> stack of actions which been used/hit in the chain -
>> though this wouldn't 
>> help when going cross controller.
>>
>> But yes, its something that has been niggling me as
>> well.
>>
>> Ash
> 
> I came up with this hack that worked for my client,
> but it's dependent on the order of the captures unless
> you are using some sort of named parameter system for
> them:
> 
> my $uri = $c->uri_for(
> 
>    $c->controller->action_for('list'), 
>    $c->request->query_parameters
> );
> 
> my @captures = ();
> 	
> foreach my $capture ( @{$c->request->captures} )
> {
>    last if $uri;
> 		
>    push @captures, $capture;	
> 
>    $uri = $c->uri_for(
> 
>       $c->controller->action_for('list'), 
>       [@captures], 
>       $c->request->query_parameters
>    );
> }
> 
> As you can see it far from elegant.  Basically it
> takes advantage of the fact that $c->uri_for will
> always return false if it can't make a uri and just
> walks through your current capture list.
> 
> I could probably rewrite this more cleanly, but it was
> the best I could come up with on a friday late
> afternoon :)
> 
> --john


Evil yes, but it looks like it works better than anything we have 
currently ;)




More information about the Catalyst mailing list