summary refs log tree commit diff
path: root/lib/Net/Riak
diff options
context:
space:
mode:
authorben hengst <notbenh@cpan.org>2010-10-27 16:00:52 -0700
committerfranck cuny <franck@lumberjaph.net>2010-11-02 15:30:22 +0100
commitcab36c6047ab68a8a52bc65cea42ebf44c18fdd2 (patch)
treefb9a70906a28ed68b3fa0810a889d87807dfa742 /lib/Net/Riak
parentAdd 204 to Object::store expected status codes. (diff)
downloadnet-riak-cab36c6047ab68a8a52bc65cea42ebf44c18fdd2.tar.gz
pulling the =build me a link= logic in to a single method and then wrapping that around append, add, and remove so that they all act the same
Diffstat (limited to '')
-rw-r--r--lib/Net/Riak/Object.pm49
1 files changed, 22 insertions, 27 deletions
diff --git a/lib/Net/Riak/Object.pm b/lib/Net/Riak/Object.pm
index e440a13..8b1d5d4 100644
--- a/lib/Net/Riak/Object.pm
+++ b/lib/Net/Riak/Object.pm
@@ -219,38 +219,33 @@ sub sibling {
     $obj;
 }
 
+
+sub _build_link {
+    my ($self,$obj,$tag) = @_;
+    blessed $obj && $obj->isa('Net::Riak::Link')
+    ? $obj
+    : Net::Riak::Link->new(
+          bucket => $self->bucket,
+          key    => $self->key,
+          tag    => $tag || $self->bucket->name,
+      );
+}
+
+around [qw{append_link remove_link add_link}] => sub{
+   my $next = shift;
+   my $self = shift;
+   $self->$next($self->_build_link(@_));
+};
+
 sub add_link {
-    my ($self, $obj, $tag) = @_;
-    my $new_link;
-    if (blessed $obj && $obj->isa('Net::Riak::Link')) {
-        $new_link = $obj;
-    }
-    else {
-        $new_link = Net::Riak::Link->new(
-            bucket => $self->bucket,
-            key    => $self->key,
-            tag    => $tag || $self->bucket->name,
-        );
-    }
-    $self->remove_link($new_link);
-    $self->append_link($new_link);
+    my ($self, $link) = @_;
+    $self->remove_link($link);
+    $self->append_link($link);
     $self;
 }
 
 sub remove_link {
-    my ($self, $obj, $tag) = @_;
-    my $new_link;
-    if (blessed $obj && $obj->isa('Net::Riak::Link')) {
-        $new_link = $obj;
-    }
-    else {
-        $new_link = Net::Riak::Link->new(
-            bucket => $self->bucket,
-            key    => $self->key,
-            tag    => $tag || ''
-        );
-    }
-
+    my ($self, $link) = @_;
     # XXX purge links!
 }