[Catalyst] Catalyst::Action::REST

Adam Jacob adam at stalecoffee.org
Mon Nov 20 17:05:14 GMT 2006


On Mon, Nov 20, 2006 at 08:47:17AM -0500, Christopher H. Laco wrote:
> Eek. Is this related to this in any way?
> http://marcusramberg.livejournal.com/37104.html
> 
> Hopefully this module will change when that becomes reality.

You can do both.  The Serialization parts have nothing to do
with the Dispatching parts, so if you wanted to dispatch with appending
Method(POST) you can.

use Catalyst::Controller::REST;

sub foo: Chained CaptureArgs(1) {
    setup_widget(); 
}

sub show: Chained('foo') PathPart('') Method(GET) {
    display_form();
}

sub proc: Chained('foo') PathPart('') Method(POST) {
    process_form();
}

Would be basically equivilant to:

use Catalyst::Controller::REST;

sub foo: Chained CaptureArgs(1) {
    setup_widget(); 
}

sub handle_foo: Chained('foo') PathPart('') ActionClass('REST') {} 

sub handle_foo_GET {
    display_form();
}

sub handle_foo_POST {
    process_form();
}

We talked about implementing things that way, with Method(POST) and
friends.  The reason we decided not to was that we preferred keeping the
same base sub name, and a single place to declare the action for
dispatching.  

At least for doing REST, it felt pretty intuitive to have a single place
where you tell the dispatcher you care about some entity, and then what
HTTP methods that entity will accept.

Additionally, using the Method(POST) mechanism would make it very
difficult to have things like the automatic 405 Not Implemented
handlers.

But it's perl, so TMTOWTDI.

Adam




More information about the Catalyst mailing list