summaryrefslogtreecommitdiff
path: root/lib/Net
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-14 17:53:00 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-14 17:54:23 +0200
commitce47f3bb5e8c69a59b678c8ff8956d8a368bcb32 (patch)
treee1542c99df3edd44e9434f244318ff2d871df633 /lib/Net
parentis_alive moved to client (diff)
downloadnet-riak-ce47f3bb5e8c69a59b678c8ff8956d8a368bcb32.tar.gz
add mx::role::parameterized for replicas, bucket and client
Diffstat (limited to '')
-rw-r--r--lib/Net/Riak/Bucket.pm27
-rw-r--r--lib/Net/Riak/Link.pm13
-rw-r--r--lib/Net/Riak/MapReduce.pm8
-rw-r--r--lib/Net/Riak/Object.pm32
-rw-r--r--lib/Net/Riak/Role/Base.pm28
-rw-r--r--lib/Net/Riak/Role/Replica.pm25
6 files changed, 67 insertions, 66 deletions
diff --git a/lib/Net/Riak/Bucket.pm b/lib/Net/Riak/Bucket.pm
index 6c848f9..525fc39 100644
--- a/lib/Net/Riak/Bucket.pm
+++ b/lib/Net/Riak/Bucket.pm
@@ -6,39 +6,20 @@ use JSON;
use Moose;
use Net::Riak::Object;
+with 'Net::Riak::Role::Replica' => {keys => [qw/r w dw/]};
+with 'Net::Riak::Role::Base' =>
+ {classes => [{name => 'client', required => 1}]};
+
has name => (
is => 'ro',
isa => 'Str',
required => 1
);
-has client => (
- is => 'ro',
- isa => 'Net::Riak::Client',
- required => 1
-);
has content_type => (
is => 'rw',
isa => 'Str',
default => 'application/json'
);
-has r => (
- is => 'rw',
- isa => 'Int',
- lazy => 1,
- default => sub { (shift)->client->r }
-);
-has w => (
- is => 'rw',
- isa => 'Int',
- lazy => 1,
- default => sub { (shift)->client->w }
-);
-has dw => (
- is => 'rw',
- isa => 'Int',
- lazy => 1,
- default => sub { (shift)->client->dw }
-);
sub n_val {
my $self = shift;
diff --git a/lib/Net/Riak/Link.pm b/lib/Net/Riak/Link.pm
index c5ed863..980aabb 100644
--- a/lib/Net/Riak/Link.pm
+++ b/lib/Net/Riak/Link.pm
@@ -4,16 +4,9 @@ package Net::Riak::Link;
use Moose;
-has client => (
- is => 'ro',
- isa => 'Net::Riak::Client',
- required => 0,
-);
-has bucket => (
- is => 'ro',
- isa => 'Net::Riak::Bucket',
- required => 1,
-);
+with 'Net::Riak::Role::Base' => {classes =>
+ [{name => 'client', required => 0}, {name => 'bucket', required => 1},]};
+
has key => (
is => 'rw',
isa => 'Str',
diff --git a/lib/Net/Riak/MapReduce.pm b/lib/Net/Riak/MapReduce.pm
index a705c58..057f74e 100644
--- a/lib/Net/Riak/MapReduce.pm
+++ b/lib/Net/Riak/MapReduce.pm
@@ -9,11 +9,9 @@ use Scalar::Util;
use Net::Riak::LinkPhase;
use Net::Riak::MapReducePhase;
-has client => (
- is => 'rw',
- isa => 'Net::Riak::Client',
- required => 1,
-);
+with 'Net::Riak::Role::Base' =>
+ {classes => [{name => 'client', required => 0}]};
+
has phases => (
traits => ['Array'],
is => 'rw',
diff --git a/lib/Net/Riak/Object.pm b/lib/Net/Riak/Object.pm
index aee4b78..04f40d2 100644
--- a/lib/Net/Riak/Object.pm
+++ b/lib/Net/Riak/Object.pm
@@ -8,44 +8,20 @@ use Moose;
use Scalar::Util;
use Net::Riak::Link;
+with 'Net::Riak::Role::Replica' => {keys => [qw/r w dw/]};
+with 'Net::Riak::Role::Base' => {classes =>
+ [{name => 'bucket', required => 1}, {name => 'client', required => 1}]};
+
has key => (
is => 'rw',
isa => 'Str',
required => 1
);
-has client => (
- is => 'rw',
- isa => 'Net::Riak::Client',
- required => 1
-);
-has bucket => (
- is => 'rw',
- isa => 'Net::Riak::Bucket',
- required => 1
-);
has data => (
is => 'rw',
isa => 'Any',
clearer => '_clear_data'
);
-has r => (
- is => 'rw',
- isa => 'Int',
- lazy => 1,
- default => sub { (shift)->client->r }
-);
-has w => (
- is => 'rw',
- isa => 'Int',
- lazy => 1,
- default => sub { (shift)->client->w }
-);
-has dw => (
- is => 'rw',
- isa => 'Int',
- lazy => 1,
- default => sub { (shift)->client->dw }
-);
has content_type => (
is => 'rw',
isa => 'Str',
diff --git a/lib/Net/Riak/Role/Base.pm b/lib/Net/Riak/Role/Base.pm
new file mode 100644
index 0000000..fbeb9ba
--- /dev/null
+++ b/lib/Net/Riak/Role/Base.pm
@@ -0,0 +1,28 @@
+package Net::Riak::Role::Base;
+
+use MooseX::Role::Parameterized;
+
+parameter classes => (
+ isa => 'ArrayRef',
+ required => 1,
+);
+
+role {
+ my $p = shift;
+
+ my $attributes = $p->classes;
+
+ foreach my $attr (@$attributes) {
+ my $name = $attr->{name};
+ my $required = $attr->{required},
+ my $class = "Net::Riak::" . (ucfirst $name);
+ has $name => (
+ is => 'rw',
+ isa => $class,
+ required => $required,
+ );
+ }
+};
+
+1;
+
diff --git a/lib/Net/Riak/Role/Replica.pm b/lib/Net/Riak/Role/Replica.pm
new file mode 100644
index 0000000..d990de2
--- /dev/null
+++ b/lib/Net/Riak/Role/Replica.pm
@@ -0,0 +1,25 @@
+package Net::Riak::Role::Replica;
+
+use MooseX::Role::Parameterized;
+
+parameter keys => (
+ isa => 'ArrayRef',
+ required => 1,
+);
+
+role {
+ my $p = shift;
+
+ my $keys = $p->keys;
+
+ foreach my $k (@$keys) {
+ has $k => (
+ is => 'rw',
+ isa => 'Int',
+ lazy => 1,
+ default => sub { (shift)->client->$k }
+ );
+ }
+};
+
+1;