| 1 | package Data::Riak::Request::MapReduce; | ||
| 2 | { | ||
| 3 | $Data::Riak::Request::MapReduce::VERSION = '2.0'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Data::Riak::Result::Object; | ||
| 8 | use Data::Riak::Exception::FunctionFailed; | ||
| 9 | use Data::Riak::Exception::Timeout; | ||
| 10 | use JSON 'encode_json'; | ||
| 11 | use namespace::autoclean; | ||
| 12 | |||
| 13 | has data => ( | ||
| 14 | is => 'ro', | ||
| 15 | isa => 'HashRef', | ||
| 16 | required => 1, | ||
| 17 | ); | ||
| 18 | |||
| 19 | has chunked => ( | ||
| 20 | is => 'ro', | ||
| 21 | isa => 'Bool', | ||
| 22 | default => 0, | ||
| 23 | ); | ||
| 24 | |||
| 25 | sub as_http_request_args { | ||
| 26 | my ($self) = @_; | ||
| 27 | |||
| 28 | return +{ | ||
| 29 | method => 'POST', | ||
| 30 | uri => 'mapred', | ||
| 31 | content_type => 'application/json', | ||
| 32 | data => encode_json($self->data), | ||
| 33 | ($self->chunked ? (query => { chunked => 'true' }) : ()), | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub _build_http_exception_classes { | ||
| 38 | return { | ||
| 39 | 500 => Data::Riak::Exception::FunctionFailed::, | ||
| 40 | 503 => Data::Riak::Exception::Timeout::, | ||
| 41 | }; | ||
| 42 | } | ||
| 43 | |||
| 44 | with 'Data::Riak::Request', | ||
| 45 | 'Data::Riak::Request::WithHTTPExceptionHandling'; | ||
| 46 | |||
| 47 | __PACKAGE__->meta->make_immutable; | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ |