From dbdb9a3b028fe0c98d40a238062e9c3d09f06afe Mon Sep 17 00:00:00 2001 From: Andreas Marienborg Date: Mon, 6 Feb 2012 16:26:27 +0100 Subject: Support PATCH method (that github uses) --- lib/Net/HTTP/Spore/Meta/Method.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/Net') diff --git a/lib/Net/HTTP/Spore/Meta/Method.pm b/lib/Net/HTTP/Spore/Meta/Method.pm index 2e55a89..f3d440f 100644 --- a/lib/Net/HTTP/Spore/Meta/Method.pm +++ b/lib/Net/HTTP/Spore/Meta/Method.pm @@ -17,7 +17,7 @@ subtype UriPath => where { $_ =~ m!^/! } => message {"path must start with /"}; -enum Method => qw(OPTIONS HEAD GET POST PUT DELETE TRACE); +enum Method => qw(OPTIONS HEAD GET POST PUT DELETE TRACE PATCH); subtype 'JSON::XS::Boolean' => as 'JSON::XS::Boolean'; subtype 'JSON::PP::Boolean' => as 'JSON::PP::Boolean'; @@ -144,7 +144,7 @@ sub wrap { : delete $method_args{payload}; if ( $payload - && ( $method->method !~ /^P(?:OS|U)T$/i ) ) + && ( $method->method !~ /^(?:POST|PUT|PATCH)$/i ) ) { die Net::HTTP::Spore::Response->new( 599, [], { error => "payload requires a PUT or POST method" }, -- cgit 1.4.1 From 1c10f35f99c10f6f2e04b8826234e2585f6d9c22 Mon Sep 17 00:00:00 2001 From: Andreas Marienborg Date: Mon, 6 Feb 2012 16:30:01 +0100 Subject: Fix an error string, add a crude test --- lib/Net/HTTP/Spore/Meta/Method.pm | 2 +- t/spore-method/payload.t | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/Net') diff --git a/lib/Net/HTTP/Spore/Meta/Method.pm b/lib/Net/HTTP/Spore/Meta/Method.pm index f3d440f..9f95c48 100644 --- a/lib/Net/HTTP/Spore/Meta/Method.pm +++ b/lib/Net/HTTP/Spore/Meta/Method.pm @@ -147,7 +147,7 @@ sub wrap { && ( $method->method !~ /^(?:POST|PUT|PATCH)$/i ) ) { die Net::HTTP::Spore::Response->new( 599, [], - { error => "payload requires a PUT or POST method" }, + { error => "payload requires a PUT, PATCH or POST method" }, ); } diff --git a/t/spore-method/payload.t b/t/spore-method/payload.t index 483d9cc..369ec22 100644 --- a/t/spore-method/payload.t +++ b/t/spore-method/payload.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 6; use Test::Exception; @@ -15,6 +15,11 @@ my $api_with_payload = { path => '/user', required_payload => 1, }, + update_user => { + method => 'PATCH', + path => '/user', + required_payload => 1, + }, list_user => { method => 'GET', path => '/user', @@ -30,4 +35,7 @@ dies_ok { $obj->create_user(); }; like $@->body->{error}, qr/this method require a payload/; dies_ok { $obj->list_user( payload => {} ) }; -like $@->body->{error}, qr/payload requires a PUT or POST method/; +like $@->body->{error}, qr/payload requires a PUT, PATCH or POST method/; + +dies_ok { $obj->update_user(); }; +like $@->body->{error}, qr/this method require a payload/; -- cgit 1.4.1