ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.pm
(Generate patch)

Comparing JSON-XS/XS.pm (file contents):
Revision 1.74 by root, Wed Nov 28 13:57:15 2007 UTC vs.
Revision 1.77 by root, Tue Dec 4 10:37:42 2007 UTC

19 19
20 $coder = JSON::XS->new->ascii->pretty->allow_nonref; 20 $coder = JSON::XS->new->ascii->pretty->allow_nonref;
21 $pretty_printed_unencoded = $coder->encode ($perl_scalar); 21 $pretty_printed_unencoded = $coder->encode ($perl_scalar);
22 $perl_scalar = $coder->decode ($unicode_json_text); 22 $perl_scalar = $coder->decode ($unicode_json_text);
23 23
24 # Note that JSON version 2.0 and above will automatically use JSON::XS
25 # if available, at virtually no speed overhead either, so you should
26 # be able to just:
27
28 use JSON;
29
30 # and do the same things, except that you have a pure-perl fallback now.
31
24=head1 DESCRIPTION 32=head1 DESCRIPTION
25 33
26This module converts Perl data structures to JSON and vice versa. Its 34This module converts Perl data structures to JSON and vice versa. Its
27primary goal is to be I<correct> and its secondary goal is to be 35primary goal is to be I<correct> and its secondary goal is to be
28I<fast>. To reach the latter goal it was written in C. 36I<fast>. To reach the latter goal it was written in C.
37
38Beginning with version 2.0 of the JSON module, when both JSON and
39JSON::XS are installed, then JSON will fall back on JSON::XS (this can be
40overriden) with no overhead due to emulation (by inheritign constructor
41and methods). If JSON::XS is not available, it will fall back to the
42compatible JSON::PP module as backend, so using JSON instead of JSON::XS
43gives you a portable JSON API that can be fast when you need and doesn't
44require a C compiler when that is a problem.
29 45
30As this is the n-th-something JSON module on CPAN, what was the reason 46As this is the n-th-something JSON module on CPAN, what was the reason
31to write yet another JSON module? While it seems there are many JSON 47to write yet another JSON module? While it seems there are many JSON
32modules, none of them correctly handle all corner cases, and in most cases 48modules, none of them correctly handle all corner cases, and in most cases
33their maintainers are unresponsive, gone missing, or not listening to bug 49their maintainers are unresponsive, gone missing, or not listening to bug
427 JSON::XS->new->allow_nonref->encode ("Hello, World!") 443 JSON::XS->new->allow_nonref->encode ("Hello, World!")
428 => "Hello, World!" 444 => "Hello, World!"
429 445
430=item $json = $json->allow_blessed ([$enable]) 446=item $json = $json->allow_blessed ([$enable])
431 447
432=item $enabled = $json->get_allow_bless 448=item $enabled = $json->get_allow_blessed
433 449
434If C<$enable> is true (or missing), then the C<encode> method will not 450If C<$enable> is true (or missing), then the C<encode> method will not
435barf when it encounters a blessed reference. Instead, the value of the 451barf when it encounters a blessed reference. Instead, the value of the
436B<convert_blessed> option will decide whether C<null> (C<convert_blessed> 452B<convert_blessed> option will decide whether C<null> (C<convert_blessed>
437disabled or no C<to_json> method found) or a representation of the 453disabled or no C<TO_JSON> method found) or a representation of the
438object (C<convert_blessed> enabled and C<to_json> method found) is being 454object (C<convert_blessed> enabled and C<TO_JSON> method found) is being
439encoded. Has no effect on C<decode>. 455encoded. Has no effect on C<decode>.
440 456
441If C<$enable> is false (the default), then C<encode> will throw an 457If C<$enable> is false (the default), then C<encode> will throw an
442exception when it encounters a blessed object. 458exception when it encounters a blessed object.
443 459

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines