From 0e754169a099cd007d4a5abd72eae2832c34bc43 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Mon, 25 Oct 2010 18:21:40 +0200 Subject: add payload and form-data to the method object --- lib/Net/HTTP/Spore/Meta/Method.pm | 51 ++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/Net/HTTP/Spore/Meta/Method.pm b/lib/Net/HTTP/Spore/Meta/Method.pm index 54967e9..8a1e0a4 100644 --- a/lib/Net/HTTP/Spore/Meta/Method.pm +++ b/lib/Net/HTTP/Spore/Meta/Method.pm @@ -50,12 +50,20 @@ has path => ( is => 'ro', isa => 'UriPath', required => 1 ); has method => ( is => 'ro', isa => 'Method', required => 1 ); has description => ( is => 'ro', isa => 'Str', predicate => 'has_description' ); +has required_payload => ( + is => 'ro', + isa => 'Boolean', + predicate => 'payload_is_required', + lazy => 1, + default => 0, + coerce => 1, +); has authentication => ( is => 'ro', isa => 'Boolean', predicate => 'has_authentication', default => 0, - coerce => 1, + coerce => 1, ); has base_url => ( is => 'ro', @@ -77,17 +85,24 @@ has expected_status => ( handles => { find_expected_status => 'grep', }, ); has optional_params => ( - traits => ['Array'], - is => 'ro', - isa => ArrayRef [Str], - predicate => 'has_optional_params', + traits => ['Array'], + is => 'ro', + isa => ArrayRef [Str], + predicate => 'has_optional_params', auto_deref => 1, ); has required_params => ( - traits => ['Array'], - is => 'ro', - isa => ArrayRef [Str], - predicate => 'has_required_params', + traits => ['Array'], + is => 'ro', + isa => ArrayRef [Str], + predicate => 'has_required_params', + auto_deref => 1, +); +has form_data => ( + traits => ['Hash'], + is => 'ro', + isa => 'HashRef', + predicate => 'has_form_data', auto_deref => 1, ); has documentation => ( @@ -123,6 +138,24 @@ sub wrap { ? delete $method_args{spore_payload} : delete $method_args{payload}; + if ( $payload + && ( $method->method ne 'POST' || $method->method ne 'PUT' ) ) + { + die Net::HTTP::Spore::Response->new( 599, [], + { error => "payload requires a PUT or POST method" }, + ); + } + + if ( $method->payload_is_required && !$payload ) { + die Net::HTTP::Spore::Response->new( + 599, + [], + { + error => "this method require a payload, and no payload is provided", + } + ); + } + if ($method->has_required_params) { foreach my $required ( $method->required_params ) { if ( !grep { $required eq $_ } keys %method_args ) { -- cgit 1.4.1