X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FREST.pm;h=6882442a1b79891961ab2460a913f8c6c0dc7452;hb=cc188065d548c2c53c22000871a7d6dfab5c3c69;hp=4ab3963dedde850314e16d88ac342278999d5ab6;hpb=239c8eef9c9e06de347d1083733e7e0ce0d3be6a;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index 4ab3963..6882442 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -10,8 +10,7 @@ use Catalyst::Controller::REST; BEGIN { require 5.008001; } -our $VERSION = '1.02'; -$VERSION = eval $VERSION; +# VERSION sub BUILDARGS { my $class = shift; @@ -131,7 +130,9 @@ sub _dispatch_rest_method { || sub { $self->_return_not_implemented($self->name, @_) }; }, }; - my $respond = ($code_action->{$req->method} + my ( $http_method, $action_name ) = ( $rest_method, $self->name ); + $http_method =~ s{\Q$action_name\E\_}{}; + my $respond = ($code_action->{$http_method} || $code_action->{'default'})->(); return $respond unless $name; } @@ -150,8 +151,13 @@ sub _dispatch_rest_method { sub get_allowed_methods { my ( $self, $controller, $c, $name ) = @_; my $class = ref($controller) ? ref($controller) : $controller; - my $methods = Class::Inspector->methods($class); - return map { /^$name\_(.+)$/ } @$methods; + my $methods = { + map { /^$name\_(.+)$/ ? ( $1 => 1 ) : () } + @{ Class::Inspector->methods($class) } + }; + $methods->{'HEAD'} = 1 if $methods->{'GET'}; + delete $methods->{'not_implemented'}; + return sort keys %$methods; }; sub _return_options {