X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FREST.pm;h=9f866a129dcd10df71b99f321aa5a99576760ca7;hb=47c3e6b3694ea55015f839be8f1a10e4141e6e4a;hp=ae175eb2926d64f159241483e1bc1b9c2f7c6bdc;hpb=80c886bb829581482fd5a45e909dce92d14a505f;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index ae175eb..9f866a1 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.12'; $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 { @@ -245,6 +252,8 @@ Gerv http://www.gerv.net/ Colin Newell +Wallace Reis Ewreis@cpan.orgE + =head1 COPYRIGHT Copyright (c) 2006-2012 the above named AUTHOR and CONTRIBUTORS