Dispatching with Chained vs HTTP method
\ Toby Corkindale (30 Apr 2008)
. \ Aristotle Pagaltzis (30 Apr 2008)
. \ Zbigniew Lukasiak (30 Apr 2008)
. . \ Moritz Onken (30 Apr 2008)
. . . \ Zbigniew Lukasiak (30 Apr 2008)
. . . . \ Moritz Onken (30 Apr 2008)
. \ Toby Corkindale (1 May 2008)
. . \ Zbigniew Lukasiak (1 May 2008)
. . . \ Toby Corkindale (7 May 2008)
. . . . \ Adam Clarke (7 May 2008)
. . . . . \ Toby Corkindale (7 May 2008)
. . . . . . \ Toby Corkindale (7 May 2008)
. . . . . . \ Zbigniew Lukasiak (7 May 2008)
. . . . . . . \ Toby Corkindale (7 May 2008)
. . . . . . . \ Garrett Goebel (7 May 2008)
. . . . . . . . \ paddy (7 May 2008)
. . . . . . \ Adam Clarke (7 May 2008)
. . . . . . . \ Toby Corkindale (7 May 2008)

1 msgdependency 'bug' in Catalyst::Runtime 5.7012
1 msgC::C::FormBuilder - self->formbuilder->su...
4 msgViewing username in Apache access_log (via Fast...
3 msgCatalyst website
1 msgHTTP::Body, utf8 filenames, and escaped strings.
27 msgMulti-language and REST
5 msgTT custom virtual methods available to all pages.
1 msgCatalyst Conference #1
9 msguri_for() doesn't encode to utf8 first argument
2 msgDBIC error when starting dev server
17 msgDispatching based on path and host/domain
12 msgCatalyst and PayPal
8 msgmodperl 1.3 wierdness
17 msgUnit Testing
5 msgCatalyst::Log::Log4perl autoflush
2 msgdoctype being modified
1 msgcurrent profile won't fill withC::P::FormValida...
4 msgTesting View
6 msgCGI::Dump()
Subject:Dispatching with Chained vs HTTP method
Group:Catalyst
From:Toby Corkindale
Date:30 Apr 2008


 
just looking for some advice on the best way to do something..

So I wrote a controller class using Chained that basically auto-converts any
DBIx::Schema (which includes a tiny extra base class itself) into a REST API..
Well, a simple one anyway - it supports find and search so far, and foreign
keys in the objects get serialised into hashes of the URIs to fetch them.

All working nicely so far, but this is all for GET queries.

But the behaviour should be different depending upon whether you
GET /item/1234
or
DELETE /item/1234
etc.

I was thinking something like this: (Abbreviated code below)

------------
sub item_by_id : Chained CaptureArgs(2) {
my ($self, $c, $type, $id) = @_;
$c->stash->{item} = $c->model("DB:$type")->find($id);
}

sub delete : Chained('item_by_id') Args ActionClass('MethodDELETE') {
my ($self, $c) = @_;
$c->stash->{item}->delete;
}

sub modify : Chained('item_by_id') Args ActionClass('MethodPUT') {
my ($self, $c) = @_;
$c->stash->{item}->update($c->request->params);
}
------------
Then the appropriate ActionClasses would check if the $c->req->method eq 'GET'
or 'DELETE' or whatever.

But I was just wondering if you had other ideas, and if using ActionClasses
with Chained actions is crackfuelled and going to lead to a world of misery and
pain.

Cheers!
Toby

_______________________________________________
List: Catalyst
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst/
Dev site: http://dev.catalyst.perl.org/


© 2004-2008 readlist.com