X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FREST.pm;h=a525ed6013f34cae557d8b9b77d4035512cfba5a;hb=a400ef8b6bb950a4fb6d17e20d912d920370549a;hp=f4e0a2fa759dc243f82d98d9d84a0d113a882f7d;hpb=7eda8b409a03580ac0ab857f643d4c5231fb617e;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index f4e0a2f..a525ed6 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -1,23 +1,16 @@ -# -# REST.pm -# Created by: Adam Jacob, Marchex, -# Created on: 10/12/2006 03:00:32 PM PDT -# -# $Id$ - package Catalyst::Action::REST; -use strict; -use warnings; +use Moose; +use namespace::autoclean; -use base 'Catalyst::Action'; +extends 'Catalyst::Action'; use Class::Inspector; use Catalyst::Request::REST; use Catalyst::Controller::REST; BEGIN { require 5.008001; } -our $VERSION = '0.76'; +our $VERSION = '0.80'; $VERSION = eval $VERSION; sub new { @@ -41,15 +34,18 @@ Catalyst::Action::REST - Automated REST Method Dispatching ... do something for GET requests ... } - sub foo_PUT { - ... do somethign for PUT requests ... + # alternatively use an Action + sub foo_PUT : Action { + ... do something for PUT requests ... } =head1 DESCRIPTION This Action handles doing automatic method dispatching for REST requests. It takes a normal Catalyst action, and changes the dispatch to append an -underscore and method name. +underscore and method name. First it will try dispatching to an action with +the generated name, and failing that it will try to dispatch to a regular +method. For example, in the synopsis above, calling GET on "/foo" would result in the foo_GET method being dispatched. @@ -129,14 +125,8 @@ sub dispatch { sub _get_allowed_methods { my ( $self, $controller, $c, $name ) = @_; my $class = ref($controller) ? ref($controller) : $controller; - my $methods = Class::Inspector->methods($class); - my @allowed; - foreach my $method ( @{$methods} ) { - if ( $method =~ /^$name\_(.+)$/ ) { - push( @allowed, $1 ); - } - } - return @allowed; + my $methods = Class::Inspector->methods($class); + return map { /^$name\_(.+)$/ } @$methods; }; sub _return_options { @@ -182,14 +172,22 @@ one of the accepted return formats. You can do this by setting it in your query accepted return formats. You can do this by setting it in your query string thusly: C<< ?content-type=application%2Fjson (where %2F == / uri escaped). >> -B Apache will refuse %2F unless configured otherise. -Make sure C<< AllowEncodedSlashes On >> is in your httpd.conf file in orde +B Apache will refuse %2F unless configured otherwise. +Make sure C is in your httpd.conf file in order for this to run smoothly. =back +=head1 AUTHOR + +Adam Jacob , with lots of help from mst and jrockway + +Marchex, Inc. paid me while I developed this module. (L) + =head1 CONTRIBUTORS +Arthur Axel "fREW" Schmidt + Christopher Laco Luke Saunders @@ -204,11 +202,9 @@ Hans Dieter Pearcey Tomas Doran (t0m) -=head1 AUTHOR - -Adam Jacob , with lots of help from mst and jrockway +=head1 COPYRIGHT -Marchex, Inc. paid me while I developed this module. (L) +Copyright the above named AUTHOR and CONTRIBUTORS =head1 LICENSE