[Catalyst] RESTy Chained actions

John Lifsey - Contractor - 5595 john.lifsey at nrl.navy.mil
Tue Jun 29 13:06:12 GMT 2010


On 6/25/10 12:08 PM, Stephen Howard wrote:
> /tutorials
> /tutorials/*
> /tutorials/*/comments
> /tutorials/*/comments/*
> /tutorials/*/comments/*/replies
> /tutorials/*/comments/*/replies/*
>
> #
> ------------------------------------------------------------------------------
>
> sub list :Chained('/') PathPart('tutorials') Args(0) :
> ActionClass('REST') {}
>
> sub list_GET { ... }
> sub list_POST { ... }
> sub list_HEAD { ... }
>
> #
> ------------------------------------------------------------------------------
>
> sub find_tutorial :Chained('/') PathPart('tutorials') CaptureArgs(1) {
> ... }
>
> #
> ------------------------------------------------------------------------------
>
> sub single :Chained('find_tutorial') PathPart('') Args(0)
> ActionClass('REST') { ... }
> sub single_GET { ... }
> sub single_POST { ... }
>
> #
> ------------------------------------------------------------------------------
>
> sub comments :Chained('find_tutorial') PathPart('comments') Args(0)

Well, if you teach a man to fish, apparently he'll ask you to teach him 
how to fly spaceships next.

While this example worked well, it led me to another related problem. I 
have a parent Controller class for typical behavior on a resource from 
which I inherit and override as needed for each type of resource.

package MyBaseController;
extends 'Catalyst::Controller::REST';

sub index : Chained PathPrefix Args(0) ActionClass('REST') {}
sub find : Chained PathPrefix CaptureArgs(1) {}
sub single : Chained('find') PathPart('') Args(0) {}
etc..

1;

Using the previous poster's example this works just fine in
MyApp::Controller::Tutorial

but it will not work for MyApp::Controller::Tutorial::Comments
At first, from looking at the documentation I thought that setting the 
controller config key "path" to a regex or "/tutorial/*/" might do the 
trick, but alas it does not.

This is further complicated by my desire to break from the previous 
example and allow Comments to be at the same hierarchical level as 
Tutorial. That is to say:

MyApp::Controller::Tutorial ISA MyBaseController;
and
MyApp::Controller::Comments ISA MyBaseController;

So that I could reference a particular comment ID at /myapp/comments/* 
or at /myapp/tutorial/*/comments/*

Upon documentation review I thought __PACKAGE__->config(action=>{'*'=>{ 
blah, blah }}); would be my salvation, but it appears that '*' doesn't 
actually work in myapp, at least as written in the documentation.

Now that I've gotten myself worked entirely into a lather thinking in 
circles it's time to request insight from the crowd. Any suggestions?




More information about the Catalyst mailing list