1package Net::Riak::Role::PBC::MapReduce;
2{
3  $Net::Riak::Role::PBC::MapReduce::VERSION = '0.1702';
4}
5use Moose::Role;
6use JSON;
7use List::Util 'sum';
8
9sub execute_job {
10    my ($self, $job, $timeout, $returned_phases) = @_;
11
12    $job->{timeout} = $timeout;
13
14    my $job_request = JSON::encode_json($job);
15
16    my $results;
17
18    my $resp = $self->send_message( MapRedReq => {
19            request => $job_request,
20            content_type => 'application/json'
21        }, sub { push @$results, $self->decode_phase(shift) })
22        or
23    die "MapReduce query failed!";
24
25
26    return $returned_phases == 1 ? $results->[0] : $results;
27}
28
29sub decode_phase {
30    my ($self, $resp) = @_;
31
32    if (defined $resp->response && length($resp->response)) {
33        return JSON::decode_json($resp->response);
34    }
35
36    return;
37}
38
391;
40
41__END__
42
43=pod
44
45=head1 NAME
46
47Net::Riak::Role::PBC::MapReduce
48
49=head1 VERSION
50
51version 0.1702
52
53=head1 AUTHOR
54
55franck cuny <franck@lumberjaph.net>, robin edwards <robin.ge@gmail.com>
56
57=head1 COPYRIGHT AND LICENSE
58
59This software is copyright (c) 2013 by linkfluence.
60
61This is free software; you can redistribute it and/or modify it under
62the same terms as the Perl 5 programming language system itself.
63
64=cut
65