ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.239 by root, Tue Dec 10 20:39:12 2013 UTC vs.
Revision 1.240 by root, Tue Dec 17 16:43:15 2013 UTC

496callback. 496callback.
497 497
498This callback will only be called on TLS shutdowns, not when the 498This callback will only be called on TLS shutdowns, not when the
499underlying handle signals EOF. 499underlying handle signals EOF.
500 500
501=item json => L<JSON> or L<JSON::XS> object 501=item json => L<JSON>, L<JSON::PP> or L<JSON::XS> object
502 502
503This is the json coder object used by the C<json> read and write types. 503This is the json coder object used by the C<json> read and write types.
504 504
505If you don't supply it, then AnyEvent::Handle will create and use a 505If you don't supply it, then AnyEvent::Handle will create and use a
506suitable one (on demand), which will write and expect UTF-8 encoded JSON 506suitable one (on demand), which will write and expect UTF-8 encoded JSON
507texts. 507texts.
508
509Note that you are responsible to depend on the L<JSON> module if you want
510to use this functionality, as AnyEvent does not have a dependency on it
511itself.
512 508
513=item cbor => L<CBOR::XS> object 509=item cbor => L<CBOR::XS> object
514 510
515This is the cbor coder object used by the C<cbor> read and write types. 511This is the cbor coder object used by the C<cbor> read and write types.
516 512
1106 1102
1107=cut 1103=cut
1108 1104
1109sub json_coder() { 1105sub json_coder() {
1110 eval { require JSON::XS; JSON::XS->new->utf8 } 1106 eval { require JSON::XS; JSON::XS->new->utf8 }
1111 || do { require JSON; JSON->new->utf8 } 1107 || do { require JSON::PP; JSON::PP->new->utf8 }
1112} 1108}
1113 1109
1114register_write_type json => sub { 1110register_write_type json => sub {
1115 my ($self, $ref) = @_; 1111 my ($self, $ref) = @_;
1116 1112
1708=item json => $cb->($handle, $hash_or_arrayref) 1704=item json => $cb->($handle, $hash_or_arrayref)
1709 1705
1710Reads a JSON object or array, decodes it and passes it to the 1706Reads a JSON object or array, decodes it and passes it to the
1711callback. When a parse error occurs, an C<EBADMSG> error will be raised. 1707callback. When a parse error occurs, an C<EBADMSG> error will be raised.
1712 1708
1713If a C<json> object was passed to the constructor, then that will be used 1709If a C<json> object was passed to the constructor, then that will be
1714for the final decode, otherwise it will create a JSON coder expecting UTF-8. 1710used for the final decode, otherwise it will create a L<JSON::XS> or
1711L<JSON::PP> coder object expecting UTF-8.
1715 1712
1716This read type uses the incremental parser available with JSON version 1713This read type uses the incremental parser available with JSON version
17172.09 (and JSON::XS version 2.2) and above. You have to provide a 17142.09 (and JSON::XS version 2.2) and above.
1718dependency on your own: this module will load the JSON module, but
1719AnyEvent does not depend on it itself.
1720 1715
1721Since JSON texts are fully self-delimiting, the C<json> read and write 1716Since JSON texts are fully self-delimiting, the C<json> read and write
1722types are an ideal simple RPC protocol: just exchange JSON datagrams. See 1717types are an ideal simple RPC protocol: just exchange JSON datagrams. See
1723the C<json> write type description, above, for an actual example. 1718the C<json> write type description, above, for an actual example.
1724 1719

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines