… | |
… | |
1461 | my ($pl, $buf) = @_; |
1461 | my ($pl, $buf) = @_; |
1462 | |
1462 | |
1463 | my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; |
1463 | my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; |
1464 | |
1464 | |
1465 | if (ref $msg) { |
1465 | if (ref $msg) { |
1466 | my ($type, $reply, @payload) = |
1466 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
1467 | "ARRAY" eq ref $msg |
|
|
1468 | ? @$msg |
|
|
1469 | : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove |
|
|
1470 | |
1467 | |
1471 | my @reply; |
1468 | my @reply; |
1472 | |
1469 | |
1473 | if (my $cb = $EXTCMD{$type}) { |
1470 | if (my $cb = $EXTCMD{$type}) { |
1474 | @reply = $cb->($pl, @payload); |
1471 | @reply = $cb->($pl, @payload); |
… | |
… | |
3190 | =cut |
3187 | =cut |
3191 | |
3188 | |
3192 | sub cf::client::ext_reply($$@) { |
3189 | sub cf::client::ext_reply($$@) { |
3193 | my ($self, $id, @msg) = @_; |
3190 | my ($self, $id, @msg) = @_; |
3194 | |
3191 | |
3195 | if ($self->extcmd == 2) { |
3192 | return unless $self->extcmd == 2; |
|
|
3193 | |
3196 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
3194 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
3197 | } elsif ($self->extcmd == 1) { |
|
|
3198 | #TODO: version 1, remove |
|
|
3199 | unshift @msg, msgtype => "reply", msgid => $id; |
|
|
3200 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
|
|
3201 | } |
|
|
3202 | } |
3195 | } |
3203 | |
3196 | |
3204 | =item $success = $client->query ($flags, "text", \&cb) |
3197 | =item $success = $client->query ($flags, "text", \&cb) |
3205 | |
3198 | |
3206 | Queues a query to the client, calling the given callback with |
3199 | Queues a query to the client, calling the given callback with |
… | |
… | |
3261 | my ($ns, $buf) = @_; |
3254 | my ($ns, $buf) = @_; |
3262 | |
3255 | |
3263 | my $msg = eval { $ns->{json_coder}->decode ($buf) }; |
3256 | my $msg = eval { $ns->{json_coder}->decode ($buf) }; |
3264 | |
3257 | |
3265 | if (ref $msg) { |
3258 | if (ref $msg) { |
3266 | my ($type, $reply, @payload) = |
3259 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
3267 | "ARRAY" eq ref $msg |
|
|
3268 | ? @$msg |
|
|
3269 | : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove |
|
|
3270 | |
3260 | |
3271 | my @reply; |
3261 | my @reply; |
3272 | |
3262 | |
3273 | if (my $cb = $EXTICMD{$type}) { |
3263 | if (my $cb = $EXTICMD{$type}) { |
3274 | @reply = $cb->($ns, @payload); |
3264 | @reply = $cb->($ns, @payload); |