summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/Net/Riak/Bucket.pm5
-rw-r--r--lib/Net/Riak/Client.pm48
-rw-r--r--lib/Net/Riak/Link.pm2
-rw-r--r--lib/Net/Riak/MapReduce.pm2
-rw-r--r--lib/Net/Riak/MapReducePhase.pm1
-rw-r--r--lib/Net/Riak/Role/MapReduce.pm34
6 files changed, 86 insertions, 6 deletions
diff --git a/lib/Net/Riak/Bucket.pm b/lib/Net/Riak/Bucket.pm
index 4586d34..6c848f9 100644
--- a/lib/Net/Riak/Bucket.pm
+++ b/lib/Net/Riak/Bucket.pm
@@ -13,7 +13,7 @@ has name => (
);
has client => (
is => 'ro',
- isa => 'Net::Riak',
+ isa => 'Net::Riak::Client',
required => 1
);
has content_type => (
@@ -21,7 +21,6 @@ has content_type => (
isa => 'Str',
default => 'application/json'
);
-
has r => (
is => 'rw',
isa => 'Int',
@@ -127,7 +126,7 @@ sub new_object {
key => $key,
data => $data,
bucket => $self,
- client => $self->client
+ client => $self->client,
);
$object;
}
diff --git a/lib/Net/Riak/Client.pm b/lib/Net/Riak/Client.pm
new file mode 100644
index 0000000..21a52e9
--- /dev/null
+++ b/lib/Net/Riak/Client.pm
@@ -0,0 +1,48 @@
+package Net::Riak::Client;
+
+use Moose;
+use MIME::Base64;
+
+with qw/Net::Riak::Role::REST Net::Riak::Role::UserAgent/;
+
+has host => (
+ is => 'rw',
+ isa => 'Str',
+ default => 'http://127.0.0.1:8098'
+);
+has prefix => (
+ is => 'rw',
+ isa => 'Str',
+ default => 'riak'
+);
+has mapred_prefix => (
+ is => 'rw',
+ isa => 'Str',
+ default => 'mapred'
+);
+has r => (
+ is => 'rw',
+ isa => 'Int',
+ default => 2
+);
+has w => (
+ is => 'rw',
+ isa => 'Int',
+ default => 2
+);
+has dw => (
+ is => 'rw',
+ isa => 'Int',
+ default => 2
+);
+has client_id => (
+ is => 'rw',
+ isa => 'Str',
+ lazy_build => 1,
+);
+
+sub _build_client_id {
+ "perl_net_riak" . encode_base64(int(rand(10737411824)), '');
+}
+
+1;
diff --git a/lib/Net/Riak/Link.pm b/lib/Net/Riak/Link.pm
index 7a1afa3..f8df0dd 100644
--- a/lib/Net/Riak/Link.pm
+++ b/lib/Net/Riak/Link.pm
@@ -6,7 +6,7 @@ use Moose;
has client => (
is => 'ro',
- isa => 'Net::Riak',
+ isa => 'Net::Riak::Client',
required => 0,
);
has bucket => (
diff --git a/lib/Net/Riak/MapReduce.pm b/lib/Net/Riak/MapReduce.pm
index 3d5e6b3..a705c58 100644
--- a/lib/Net/Riak/MapReduce.pm
+++ b/lib/Net/Riak/MapReduce.pm
@@ -11,7 +11,7 @@ use Net::Riak::MapReducePhase;
has client => (
is => 'rw',
- isa => 'Net::Riak',
+ isa => 'Net::Riak::Client',
required => 1,
);
has phases => (
diff --git a/lib/Net/Riak/MapReducePhase.pm b/lib/Net/Riak/MapReducePhase.pm
index 2d66775..992644d 100644
--- a/lib/Net/Riak/MapReducePhase.pm
+++ b/lib/Net/Riak/MapReducePhase.pm
@@ -27,5 +27,4 @@ sub to_array {
return {$self->type => $step_def};
}
-
1;
diff --git a/lib/Net/Riak/Role/MapReduce.pm b/lib/Net/Riak/Role/MapReduce.pm
new file mode 100644
index 0000000..d80e242
--- /dev/null
+++ b/lib/Net/Riak/Role/MapReduce.pm
@@ -0,0 +1,34 @@
+package Net::Riak::Role::MapReduce;
+
+use Moose::Role;
+use Net::Riak::MapReduce;
+
+sub add {
+ my ($self, @args) = @_;
+ my $mr = Net::Riak::MapReduce->new(client => $self->client);
+ $mr->add(@args);
+ $mr;
+}
+
+sub link {
+ my ($self, @args) = @_;
+ my $mr = Net::Riak::MapReduce->new(client => $self->client);
+ $mr->link(@args);
+ $mr;
+}
+
+sub map {
+ my ($self, @args) = @_;
+ my $mr = Net::Riak::MapReduce->new(client => $self->client);
+ $mr->mapd(@args);
+ $mr;
+}
+
+sub reduce {
+ my ($self, @args) = @_;
+ my $mr = Net::Riak::MapReduce->new(client => $self->client);
+ $mr->reduce(@args);
+ $mr;
+}
+
+1;