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.72 by root, Sun Nov 25 19:11:07 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
84 100
85package JSON::XS; 101package JSON::XS;
86 102
87use strict; 103use strict;
88 104
89our $VERSION = '1.53'; 105our $VERSION = '2.0';
90our @ISA = qw(Exporter); 106our @ISA = qw(Exporter);
91 107
92our @EXPORT = qw(to_json from_json); 108our @EXPORT = qw(to_json from_json);
93 109
94use Exporter; 110use Exporter;
276 292
277 use Encode; 293 use Encode;
278 $object = JSON::XS->new->decode (decode "UTF-32LE", $jsontext); 294 $object = JSON::XS->new->decode (decode "UTF-32LE", $jsontext);
279 295
280=item $json = $json->pretty ([$enable]) 296=item $json = $json->pretty ([$enable])
281
282=item $enabled = $json->get_pretty
283 297
284This enables (or disables) all of the C<indent>, C<space_before> and 298This enables (or disables) all of the C<indent>, C<space_before> and
285C<space_after> (and in the future possibly more) flags in one call to 299C<space_after> (and in the future possibly more) flags in one call to
286generate the most readable (or most compact) form possible. 300generate the most readable (or most compact) form possible.
287 301
429 JSON::XS->new->allow_nonref->encode ("Hello, World!") 443 JSON::XS->new->allow_nonref->encode ("Hello, World!")
430 => "Hello, World!" 444 => "Hello, World!"
431 445
432=item $json = $json->allow_blessed ([$enable]) 446=item $json = $json->allow_blessed ([$enable])
433 447
434=item $enabled = $json->get_allow_bless 448=item $enabled = $json->get_allow_blessed
435 449
436If 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
437barf when it encounters a blessed reference. Instead, the value of the 451barf when it encounters a blessed reference. Instead, the value of the
438B<convert_blessed> option will decide whether C<null> (C<convert_blessed> 452B<convert_blessed> option will decide whether C<null> (C<convert_blessed>
439disabled 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
440object (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
441encoded. Has no effect on C<decode>. 455encoded. Has no effect on C<decode>.
442 456
443If 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
444exception when it encounters a blessed object. 458exception when it encounters a blessed object.
445 459

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines