[Catalyst] Chaining on complex PathParts

Eric Wright info at rapidsynergy.com
Tue Jan 6 17:36:05 GMT 2009


Hiya folks,

I just started playing around with chaining and it's very cool. However, I'm
encountering difficulty with getting something to work the way I want where
I have different actions at different path depths. Is there something about
chaining that I don't understand?

The following does what I would expect:

sub just_hello : PathPart('hello') Chained('/') Args(1) {
  my ( $self, $c, $integer ) =3D @_;
  $c->response->body("JUST HELLO! $integer");
}

sub hello : PathPart('hello') Chained('/') CaptureArgs(1) {
  my ( $self, $c, $integer ) =3D @_;
  $c->stash->{ message } =3D "Hello ";
  $c->stash->{ arg_sum } =3D $integer;
}

sub world : PathPart('world') Chained('hello') Args(0) {
  my ( $self, $c, $integer ) =3D @_;
  $c->stash->{ message } .=3D "World!";

  $c->response->body( join "<br/>\n" =3D>
     $c->stash->{ message }, $c->stash->{ arg_sum } );
}

In this scenario I can request:

/hello/1 (which fires just_hello)
/hello/1/world (which fires the chain to the endpoint "world")

However, if I want to use a more complex path such as:

sub just_hello : PathPart('prefix/hello') Chained('/') Args(1) {
  my ( $self, $c, $integer ) =3D @_;
  $c->response->body("JUST HELLO! $integer");
}

sub hello : PathPart('prefix/hello') Chained('/') CaptureArgs(1) {
  my ( $self, $c, $integer ) =3D @_;
  $c->stash->{ message } =3D "Hello ";
  $c->stash->{ arg_sum } =3D $integer;
}

#   this is our endpoint, because it has no :CaptureArgs
sub world : PathPart('world') Chained('prefix/hello') Args(0) {
  my ( $self, $c, $integer ) =3D @_;
  $c->stash->{ message } .=3D "World!";

  $c->response->body( join "<br/>\n" =3D>
      $c->stash->{ message }, $c->stash->{ arg_sum } );
}

In this example all I've done is add "prefix" to the path. In this scenario
I can request:

/prefix/hello/1 (which again fires just_hello)
/prefix/hello/1/world (FAILS!)

Is it not possible to define chains in this way? Or am I just missing
something obvious here?

Thanks in advance for any insight anyone may have into this.

-Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090106/108f0=
a99/attachment.htm


More information about the Catalyst mailing list