| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package AnyEvent::JSONRPC; | 
| 2 | 5 |  |  | 5 |  | 6705 | use strict; | 
|  | 5 |  |  |  |  | 13 |  | 
|  | 5 |  |  |  |  | 238 |  | 
| 3 | 5 |  |  | 5 |  | 24 | use warnings; | 
|  | 5 |  |  |  |  | 9 |  | 
|  | 5 |  |  |  |  | 167 |  | 
| 4 | 5 |  |  | 5 |  | 25 | use base 'Exporter'; | 
|  | 5 |  |  |  |  | 10 |  | 
|  | 5 |  |  |  |  | 156 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '0.15'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our @EXPORT = qw/jsonrpc_client jsonrpc_server/; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 5 |  |  | 5 |  | 2819 | use AnyEvent::JSONRPC::TCP::Client; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | use AnyEvent::JSONRPC::TCP::Server; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub jsonrpc_client($$) { | 
| 14 |  |  |  |  |  |  | my ($host, $port) = @_; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | AnyEvent::JSONRPC::TCP::Client->new( | 
| 17 |  |  |  |  |  |  | host => $host, | 
| 18 |  |  |  |  |  |  | port => $port, | 
| 19 |  |  |  |  |  |  | ); | 
| 20 |  |  |  |  |  |  | } | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub jsonrpc_server($$) { | 
| 23 |  |  |  |  |  |  | my ($address, $port) = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | AnyEvent::JSONRPC::TCP::Server->new( | 
| 26 |  |  |  |  |  |  | address => $address, | 
| 27 |  |  |  |  |  |  | port    => $port, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | 1; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | __END__ | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =encoding utf-8 | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =for stopwords TCP TCP-based JSONRPC RPC | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =head1 NAME | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | AnyEvent::JSONRPC - Simple TCP-based JSONRPC client/server | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | use AnyEvent::JSONRPC; | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | my $server = jsonrpc_server '127.0.0.1', '4423'; | 
| 48 |  |  |  |  |  |  | $server->reg_cb( | 
| 49 |  |  |  |  |  |  | echo => sub { | 
| 50 |  |  |  |  |  |  | my ($res_cv, @params) = @_; | 
| 51 |  |  |  |  |  |  | $res_cv->result(@params); | 
| 52 |  |  |  |  |  |  | }, | 
| 53 |  |  |  |  |  |  | ); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | my $client = jsonrpc_client '127.0.0.1', '4423'; | 
| 56 |  |  |  |  |  |  | my $d = $client->call( echo => 'foo bar' ); | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | my $res = $d->recv; # => 'foo bar'; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | This module provide TCP-based JSONRPC server/client implementation. | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | L<AnyEvent::JSONRPC> provide you a couple of export functions that are | 
| 65 |  |  |  |  |  |  | shortcut of L<AnyEvent::JSONRPC::TCP::Client> and L<AnyEvent::JSONRPC::TCP::Server>. | 
| 66 |  |  |  |  |  |  | One is C<jsonrpc_client> for Client, another is C<jsonrpc_server> for Server. | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head2 DIFFERENCES FROM THE "Lite" MODULE | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | This module is a fork of Daisuke Murase's L<AnyEvent::JSONRPC::Lite> updated | 
| 71 |  |  |  |  |  |  | to use Yuval Kogman's JSON::RPC::Common for handling the JSONRPC messages. | 
| 72 |  |  |  |  |  |  | This enables support for handling messages complying to all versions of the | 
| 73 |  |  |  |  |  |  | JSONRPC standard. | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | The System Services/Service Description parts of version 1.1-wd and 1.1-alt is | 
| 76 |  |  |  |  |  |  | unimplemented and left to users to implement. | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | As none of the specs really defines JSON-RPC over TCP I consider this module | 
| 79 |  |  |  |  |  |  | an otherwise full-spec implementation. | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head2 jsonrpc_server $address, $port; | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | Create L<AnyEvent::JSONRPC::TCP::Server> object and return it. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | This is equivalent to: | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | AnyEvent::JSONRPC::TCP::Server->new( | 
| 90 |  |  |  |  |  |  | address => $address, | 
| 91 |  |  |  |  |  |  | port    => $port, | 
| 92 |  |  |  |  |  |  | ); | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | See L<AnyEvent::JSONRPC::TCP::Server> for more detail. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head2 jsonrpc_client $hostname, $port | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | Create L<AnyEvent::JSONRPC::TCP::Client> object and return it. | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | This is equivalent to: | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | AnyEvent::JSONRPC::TCP::Client->new( | 
| 103 |  |  |  |  |  |  | host => $hostname, | 
| 104 |  |  |  |  |  |  | port => $port, | 
| 105 |  |  |  |  |  |  | ); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | See L<AnyEvent::JSONRPC::TCP::Client> for more detail. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | L<AnyEvent>, L<AnyEvent::JSONRPC::Lite>, L<JSON::RPC::Common>. | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | L<http://json-rpc.org/> | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 AUTHOR | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | Peter Makholm <peter@makholm.net> | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | Copyright (c) 2010 by Peter Makholm. | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | This program is free software; you can redistribute | 
| 124 |  |  |  |  |  |  | it and/or modify it under the same terms as Perl itself. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | The full text of the license can be found in the | 
| 127 |  |  |  |  |  |  | LICENSE file included with this module. | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =cut | 
| 130 |  |  |  |  |  |  |  |