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

Joe Landman landman at scalableinformatics.com
Sun Feb 10 07:16:12 GMT 2008


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('/') {
       my ( $self, $c  ) = @_;
       ...
   }

   sub one_arg : Chained('/') PathPart('') CaptureArgs(1) {
       my ( $self, $c, $foo_arg ) = @_;
      ...
   }

   sub two_arg : Chained('/') PathPart('') CaptureArgs(2) {
       my ( $self, $c, $foo_arg, $bar_arg) = @_;
      ...
   }

that is, the particular sub to execute is a function not of the path, 
but of the number of arguments.

Is this a job for chained?

--
Joe Landman
landman at scalableinformatics.com



More information about the Catalyst mailing list