diff options
author | franck cuny <franck@lumberjaph.net> | 2010-04-11 17:19:55 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-04-11 17:19:55 +0200 |
commit | 61c5d22e63d49decaf2ea150fbb0870a7e57944f (patch) | |
tree | 9a986ce63a9c75fbefe49083dcbdb82d7f8169de | |
parent | more API cleanup and POD (diff) | |
download | anyevent-riak-61c5d22e63d49decaf2ea150fbb0870a7e57944f.tar.gz |
fix store and fetch
-rw-r--r-- | lib/AnyEvent/Riak.pm | 16 | ||||
-rw-r--r-- | t/basic.t | 4 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/AnyEvent/Riak.pm b/lib/AnyEvent/Riak.pm index 74fb700..d86a254 100644 --- a/lib/AnyEvent/Riak.pm +++ b/lib/AnyEvent/Riak.pm @@ -184,7 +184,12 @@ sub fetch { ), headers => $self->_build_headers( $options{parameters} ), sub { - $cv->send( $cb->(@_) ); + my ($body, $headers) = @_; + if ($body && $headers->{Status} == 200) { + $cv->send( $cb->(JSON::decode_json($body)) ); + }else{ + $cv->send( $cb->(0) ); + } } ); $cv; @@ -212,7 +217,14 @@ sub store { headers => $self->_build_headers( $options{parameters} ), body => $json, sub { - $cv->send( $cb->(@_) ); + my ($body, $headers) = @_; + my $result; + if ($headers->{Status} == 204) { + $result = $body ? JSON::decode_json($body) : 1; + }else{ + $result = 0; + } + $cv->send( $cb->($result) ); } ); $cv; diff --git a/t/basic.t b/t/basic.t index a898f68..89da815 100644 --- a/t/basic.t +++ b/t/basic.t @@ -65,8 +65,8 @@ my $value = { ok my $res = $riak->store('foo', 'bar', $value)->recv, 'set a new key'; -# ok $res = $riak->fetch( 'foo', 'bar' )->recv, 'fetch our new key'; -# is_deeply $res, $value, 'value is ok'; +ok $res = $riak->fetch( 'foo', 'bar' )->recv, 'fetch our new key'; +is_deeply $res, $value, 'value is ok'; # ok $res = $riak->delete( 'foo', 'bar' )->recv, 'delete our key'; # ok my $store_w_cb = $riak->store( |