From cbc2429862a5c72812b00bbb5dd5789fad0bbcc1 Mon Sep 17 00:00:00 2001 From: Pedro Melo Date: Sun, 20 Jul 2014 22:11:46 +0100 Subject: [PATCH] Update _process_success_frame: If it looks like JSON, parse it as JSON. If not assume normal success message and send it to cb inside a hash on the 'msg' key. Signed-off-by: Pedro Melo --- lib/AnyEvent/NSQ/Connection.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/AnyEvent/NSQ/Connection.pm b/lib/AnyEvent/NSQ/Connection.pm index 2424850..5a73a0c 100644 --- a/lib/AnyEvent/NSQ/Connection.pm +++ b/lib/AnyEvent/NSQ/Connection.pm @@ -289,16 +289,17 @@ sub _process_success_frame { $self->nop; } else { - if ($msg ne 'OK') { - my $info = eval { JSON::XS::decode_json($msg) }; + my $info = { msg => $msg }; + if ($msg =~ m/^\s*[{]/) { + $info = eval { JSON::XS::decode_json($msg) }; unless ($info) { $self->_log_error(qq{unexpected/invalid JSON response '$msg'}); return; } - - my $cb = shift @{ $self->{success_cb_queue} || [] }; - $cb->($self, $info) if $cb; } + + my $cb = shift @{ $self->{success_cb_queue} || [] }; + $cb->($self, $info) if $cb; } return 'keep_reading_frames';