I often find myself needing to make actions that should only be dispatched to by the POST method, or writing dispatch logic to distinguish between POST and GET in my various methods. It would be nice if the Catalyst dispatcher could handle this for me directly. However, we should probably support the whole HTTP spec, and adding those would pollute the attribute space pretty badly. Thus I suggest that we add a prefix, like do_POST or require_DELETE to the dispatch value. The other alternative is to add a method attribute, which would make the api look something like this
sub admin : Local Method('POST') {}
Obviously, it would have to match against specific methods first, then fall back on a generic handler without a specified method. Any other thoughts on the API?
sub admin : Local Method('POST') {}
Obviously, it would have to match against specific methods first, then fall back on a generic handler without a specified method. Any other thoughts on the API?


Comments
Especially if it's implemented in the actions match, so it can be used together with chained, e.g.:
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(); }gr.,
phaylon
I know from the existing Catalyst-based code that I've contributed to, at least 75% of their "Local" actions followed a predictable formula:
IF method is "POST" THEN return immediately, let view render the template for this path ELSE process the form Use $c->response->redirect() to go to a different template ENDIFRandy
I’d say add very short shortcuts for the common verbs, eg.
sub admin : Local POST {}, but support Method('FOO') for stuff beyond that. The list of common verbs would be (I think) just GET, PUT, POST, DELETE and HEAD.Note: HTTP is case sensitive. Please don’t make POST/Method('POST') synonymous with Method('post').