JSON/Client.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 18 / 18 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« JSON.pm ↑ Summary JSON/Server.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base qw( Net::Async::WebSocket::Client Net::Async::WebSocket::JSON::Protocol );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = '0.01';
14  
15 =head1 NAME
16  
17 C<Net::Async::WebSocket::JSON::Client> - connect to a WebSocket server using JSON and C<IO::Async>
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<Net::Async::WebSocket::Client> provides conveniences for
46 using JSON-encoded data sent over text frames.
47  
48 It should be used identically to C<Net::Async::WebSocket::Client>, except that
49 it has the new C<send_json> method and C<on_json> event defined by
50 L<Net::Async::WebSocket::JSON::Protocol>.
51  
52 =cut
53  
54 =head1 AUTHOR
55  
56 Paul Evans <leonerd@leonerd.org.uk>
57  
58 =cut
59  
60 1 0x55AA;
« JSON.pm ↑ Summary JSON/Server.pm »