line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2017 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Async::WebSocket::JSON::Client; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
132498
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
10
|
1
|
|
|
1
|
|
4
|
use mro 'c3'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
47
|
use base qw( Net::Async::WebSocket::Client Net::Async::WebSocket::JSON::Protocol ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
460
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
C - connect to a WebSocket server using JSON and C |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use IO::Async::Loop; |
22
|
|
|
|
|
|
|
use Net::Async::WebSocket::JSON::Client; |
23
|
|
|
|
|
|
|
use Data::Dump; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $client = Net::Async::WebSocket::JSON::Client->new( |
26
|
|
|
|
|
|
|
on_json => sub { |
27
|
|
|
|
|
|
|
my ( $self, $data ) = @_; |
28
|
|
|
|
|
|
|
print Data::Dump::pp( $data ); |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
33
|
|
|
|
|
|
|
$loop->add( $client ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$client->connect( |
36
|
|
|
|
|
|
|
url => "ws://$HOST:$PORT/", |
37
|
|
|
|
|
|
|
)->then( sub { |
38
|
|
|
|
|
|
|
$client->send_json( { message => "Hello, world!\n" } ); |
39
|
|
|
|
|
|
|
})->get; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$loop->run; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This subclass of L provides conveniences for |
46
|
|
|
|
|
|
|
using JSON-encoded data sent over text frames. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
It should be used identically to C, except that |
49
|
|
|
|
|
|
|
it has the new C method and C event defined by |
50
|
|
|
|
|
|
|
L. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 AUTHOR |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Paul Evans |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
0x55AA; |