summary refs log tree commit diff
path: root/lib/Net/Riak/MapReducePhase.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-09 16:38:20 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-09 16:38:20 +0200
commitb797f187a22f38142ac3ac957f0e874ca492c2cd (patch)
tree7c754fc69ddf91e7c4475b84479d543c0e395727 /lib/Net/Riak/MapReducePhase.pm
downloadnet-riak-b797f187a22f38142ac3ac957f0e874ca492c2cd.tar.gz
initial import
Diffstat (limited to 'lib/Net/Riak/MapReducePhase.pm')
-rw-r--r--lib/Net/Riak/MapReducePhase.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Net/Riak/MapReducePhase.pm b/lib/Net/Riak/MapReducePhase.pm
new file mode 100644
index 0000000..2d66775
--- /dev/null
+++ b/lib/Net/Riak/MapReducePhase.pm
@@ -0,0 +1,31 @@
+package Net::Riak::MapReducePhase;
+
+use Moose;
+use Scalar::Util;
+use JSON;
+
+has type     => (is => 'rw', isa => 'Str',      required => 1,);
+has function => (is => 'ro', isa => 'Str',      required => 1);
+has arg      => (is => 'ro', isa => 'ArrayRef', default  => 'None');
+has language => (is => 'ro', isa => 'Str',      default  => 'javascript');
+has keep => (is => 'rw', isa => 'JSON::Boolean', default => sub {JSON::false});
+
+sub to_array {
+    my $self = shift;
+
+    my $step_def = {
+        keep     => $self->keep,
+        language => $self->language,
+        arg      => $self->arg
+    };
+
+    if ($self->function =~ m!\{!) {
+        $step_def->{source} = $self->function;
+    }else{
+        $step_def->{name} = $self->function;
+    }
+    return {$self->type => $step_def};
+}
+
+
+1;