diff options
Diffstat (limited to 'lib/Net/Riak/Object.pm')
-rw-r--r-- | lib/Net/Riak/Object.pm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/Net/Riak/Object.pm b/lib/Net/Riak/Object.pm index 80997c1..1a533d5 100644 --- a/lib/Net/Riak/Object.pm +++ b/lib/Net/Riak/Object.pm @@ -40,6 +40,24 @@ has links => ( }, clearer => '_clear_links', ); + +has metadata => ( + traits => ['Hash'], + is => 'rw', + isa => 'HashRef[Str]', + auto_deref => 1, + lazy => 1, + default => sub { {} }, + handles => { + set_meta => 'set', + get_meta => 'get', + remove_meta => 'delete', + has_meta => 'count', + all_meta => 'elements', + }, + clearer => '_clear_meta', +); + has siblings => ( traits => ['Array'], is => 'rw', @@ -126,6 +144,7 @@ sub clear { my $self = shift; $self->_clear_data; $self->_clear_links; + $self->_clear_meta; $self->exists(0); $self; } @@ -286,6 +305,38 @@ Add a new sibling Return a sibling +=item all_meta + +Returns a hash containing all the meta name/value pairs + + my %metadata = $obj->all_meta; + +=item has_meta + +Returns the number of usermetas associated with the object. Typical use is as a +predicate method. + + if ( $obj->has_meta ) { ... } + +=item set_meta + +Sets a usermeta on the object, overriding any existing value for that key + + $obj->set_meta( key => $value ); + +=item get_meta + +Reads a single usermeta from the object. If multiple usermeta headers have been +set for a single key (eg via another client), the values will be separated with +a comma; Riak will concatenate the input headers and only return a single one. + +=item remove_meta + +removes a single usermeta from the object. Returns false on failure, eg if the +key did not exist on the object. + + $obj->remove_meta( 'key' ) || die( "could not remove" ); + =item store $obj->store($w, $dw); |