[Catalyst] Not sure how to go about this ... or if this idea is even a good one ...

Matt S Trout dbix-class at trout.me.uk
Sun Feb 10 15:42:51 GMT 2008


On Sun, Feb 10, 2008 at 02:16:12AM -0500, Joe Landman wrote:
> 
> Ok, starting to want to play with Chained actions for an app, and I am 
> not sure they are the right fit.  Possibly a round peg in this 
> particular square hole.
> 
> Here is what I want to do.  I want to capture 0, 1, or 2 arguments on 
> the URL.
> 
> If 0 args, then forward over to one method.
> 
> If 1 arg, then forward over to a specific method
> 
> If 2 args, then forward over to a different specific method.
> 
> I don't want to go beyond 2 args for this, but you should get the idea.
> 
> This is sort of a drill-in type application.
> 
> Ok.  Does chained make sense for this versus
> 
> sub do_stuff : Path('/') {
>   my ($self, $c, @my_args) = @_;
> 
>   if ($#my_args == -1)
>      {
>        $c->forward('zero_args');
>      }
>   elsif ($#my_args == 0)
>      {
>        $c->forward('one_arg', at my_args);
>      }
>   elsif ($#my_args == 1)
>      {
>        $c->forward('two_arg', at my_args);
>      }
>  }
> 
> The issue in this case is that I won't know the value of the first or 
> second arg in advance (they are coming from a database).  So I am not 
> sure if I can do something like
> 
>  #   root action - captures one argument after it


sub zero :Path('/') :Args(0) {

sub one :Path('/') :Args(1) {

sub two :Path('/') :Args(2) {

:Chained('/') :PathPart('') would substitute for :Path('/') just fine,
although unless you're actually building a chain I can't say I see a lot of
point in using one.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list