nerd.org.uk
package Net::Async::WebSocket::JSON;
use strict;
use warnings;
our $VERSION = '0.01';
=head1 NAME
C<Net::Async::WebSocket::JSON> - use JSON-encoded data over WebSockets with C<IO::Asy
t add convenient wrappers for encoding or decoding JSON data in text frames
over websockets.
To implement a server, use L<Net::Async::WebSocket::JSON::Server> as if it was
L<Net::Async::WebSocket::Se
::JSON::Client> as if it was
L<Net::Async::WebSocket::Client>.
In either cases, connected client instances will be instances of
L<Net::Async::WebSocket::JSON::Protocol>, and have the new C<send_json>
Perl itself)
#
# (C) Paul Evans, 2017 -- leonerd@leonerd.org.uk
package Net::Async::WebSocket::JSON::Protocol;
use strict;
use warnings;
use base qw( Net::Async::WebSocket::Protocol );
Net::Async:
send and receive JSON-encoded data over WebSockets
=head1 DESCRIPTION
This subclass of L<Net::Async::WebSocket::Protocol> provides some conveniences
for sending and receiving JSON-encoded data over
iply, it
provides one new method, L<send_json>, for encoding Perl values into JSON and
sending them, and one new method, L<on_json>, for decoding received JSON
content into Perl values when received.
Perl itself)
#
# (C) Paul Evans, 2017 -- leonerd@leonerd.org.uk
package Net::Async::WebSocket::JSON::Server;
use strict;
use warnings;
use base qw( Net::Async::WebSocket::Server );
Net::Async::Web
::JSON::Protocol;
=head1 NAME
C<Net::Async::WebSocket::JSON::Server> - server WebSocket clients using JSON and C<IO::Async>
=head1 SYNOPSIS
use IO::Async::Loop;
use Net::Async::WebSocket::JSON::
my $server = Net::Async::WebSocket::JSON::Server->new(
on_client => sub {
my ( undef, $client ) = @_;
$client->configure(
on_json => sub {
my ( $self, $fra
rg.uk
package Net::Async::WebSocket::JSON::Client;
use strict;
use warnings;
use mro 'c3';
use base qw( Net::Async::WebSocket::Client Net::Async::WebSocket::JSON::Protocol );
our $VERSION = '0.01';
C<Net::Async::WebSocket::JSON::Client> - connect to a WebSocket server using JSON and C<IO::Async>
=head1 SYNOPSIS
use IO::Async::Loop;
use Net::Async::WebSocket::JSON::Client;
use Data::Dump;
my $client = Net::Async::WebSocket::JSON::Client->new(
on_json => sub {
my ( $self, $data ) = @_;
print Data::Dump::pp( $data );
},
);
my $loop = IO::Async::Loop->new;
$loo