X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FREST.pm;h=cad0fe818bf177ad863b860a446cc67eaa33f783;hb=04f96b73abc2c408dde3d363a80f0bd112155b88;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..cad0fe8 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -10,7 +10,7 @@ use Catalyst::Controller::REST; BEGIN { require 5.008001; } -our $VERSION = '1.02'; +our $VERSION = '1.05'; $VERSION = eval $VERSION; sub BUILDARGS { @@ -131,7 +131,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 +152,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 {