[Catalyst] Add a /doc/ path at the end of all paths?

Ovid publiustemp-catalyst at yahoo.com
Thu Feb 26 16:23:38 GMT 2009


_______________________________
From: J. Shirley <jshirley at gmail.com>

> If you structure your base class properly, and then in each class you configure where to chain from:
> 
> __PACKAGE__->config(
>      actions => { 'setup' => { Chained => '/some/other/chain', PathPart => 'api' } }
> );
> 
> You can override any of the methods along the way.  I tend to use this structure in my base class:
> 
> sub setup : Chained('.') PathPart('something') CaptureArgs(0) { } 
> 
> sub root : Chained('setup') PathPart('') Args(0) { }
> 
> sub object_setup : Chained('setup') PathPart('id') CaptureArgs(1) { } 
> 
> sub object : Chained('object_setup') PathPart('') Args(0) { } 
> 
> This way, you could add a: sub doc : Chained('setup') PathPart('doc') Args(0) { } method and you would always have it.

I'm not entirely sure I follow all of that.  Right now, our PIPs::C::API::V1::Episode might handle:

  /api/v1/episode/
  /api/v1/episode/pid.b0070xmk/
  /api/v1/episode/pid.b0070xmk/children/
  /api/v1/episode/pid.b0070xmk/children/versions

And each of those needs a doc:

  /api/v1/episode/doc/
  /api/v1/episode/pid.b0070xmk/doc/
  /api/v1/episode/pid.b0070xmk/children/doc/
  /api/v1/episode/pid.b0070xmk/children/versions/doc/

It doesn't really look like your solution handles variable length URL paths, will it?

So Catalyst doesn't offer any simple way of saying "globally match {^(.*)/doc$} against a desired controller?  (the controller for $1 in this case)

> I have an example app on github that demonstrates this idea more: http://github.com/jshirley/catalystx-example-chained/tree/master
>
> I'm currently using this same mechanism in a similar way, except instead of a 'doc' it is a 'search' method ...

I can't find that "search" method anywhere in that code (forced to examine it through the Web interface due to our firewalls).

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6



More information about the Catalyst mailing list