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.43 by root, Sat Jun 23 23:49:29 2007 UTC vs.
Revision 1.44 by root, Mon Jun 25 04:08:17 2007 UTC

85 85
86package JSON::XS; 86package JSON::XS;
87 87
88use strict; 88use strict;
89 89
90our $VERSION = '1.3'; 90our $VERSION = '1.4';
91our @ISA = qw(Exporter); 91our @ISA = qw(Exporter);
92 92
93our @EXPORT = qw(to_json from_json objToJson jsonToObj); 93our @EXPORT = qw(to_json from_json objToJson jsonToObj);
94 94
95use Exporter; 95use Exporter;
315Example, encode a Perl scalar as JSON value with enabled C<allow_nonref>, 315Example, encode a Perl scalar as JSON value with enabled C<allow_nonref>,
316resulting in an invalid JSON text: 316resulting in an invalid JSON text:
317 317
318 JSON::XS->new->allow_nonref->encode ("Hello, World!") 318 JSON::XS->new->allow_nonref->encode ("Hello, World!")
319 => "Hello, World!" 319 => "Hello, World!"
320
321=item $json = $json->allow_blessed ([$enable])
322
323If C<$enable> is true (or missing), then the C<encode> method will not
324barf when it encounters a blessed reference. Instead, the value of the
325B<convert_blessed> option will decide wether C<null> (C<convert_blessed>
326disabled or no C<to_json> method found) or a representation of the
327object (C<convert_blessed> enabled and C<to_json> method found) is being
328encoded. Has no effect on C<decode>.
329
330If C<$enable> is false (the default), then C<encode> will throw an
331exception when it encounters a blessed object.
332
333=item $json = $json->convert_blessed ([$enable])
334
335If C<$enable> is true (or missing), then C<encode>, upon encountering a
336blessed object, will check for the availability of the C<TO_JSON> method
337on the object's class. If found, it will be called in scalar context
338and the resulting scalar will be encoded instead of the object. If no
339C<TO_JSON> method is found, the value of C<allow_blessed> will decide what
340to do.
341
342The C<TO_JSON> method may safely call die if it wants. If C<TO_JSON>
343returns other blessed objects, those will be handled in the same
344way. C<TO_JSON> must take care of not causing an endless recursion cycle
345(== crash) in this case. The name of C<TO_JSON> was chosen because other
346methods called by the Perl core (== not the user of the object) are
347usually in upper case letters and to avoid collisions with the C<to_json>
348function.
349
350If C<$enable> is false, then the C<allow_blessed> setting will decide what
351to do when a blessed object is found.
320 352
321=item $json = $json->shrink ([$enable]) 353=item $json = $json->shrink ([$enable])
322 354
323Perl usually over-allocates memory a bit when allocating space for 355Perl usually over-allocates memory a bit when allocating space for
324strings. This flag optionally resizes strings generated by either 356strings. This flag optionally resizes strings generated by either
757sub true() { $true } 789sub true() { $true }
758sub false() { $false } 790sub false() { $false }
759 791
760sub is_bool($) { 792sub is_bool($) {
761 UNIVERSAL::isa $_[0], "JSON::XS::Boolean" 793 UNIVERSAL::isa $_[0], "JSON::XS::Boolean"
762 or UNIVERSAL::isa $_[0], "JSON::Literal" 794# or UNIVERSAL::isa $_[0], "JSON::Literal"
763} 795}
764 796
765XSLoader::load "JSON::XS", $VERSION; 797XSLoader::load "JSON::XS", $VERSION;
766 798
767package JSON::XS::Boolean; 799package JSON::XS::Boolean;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines