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.105 by root, Sat May 24 21:55:43 2008 UTC vs.
Revision 1.110 by root, Sun Jul 20 17:55:19 2008 UTC

101 101
102=cut 102=cut
103 103
104package JSON::XS; 104package JSON::XS;
105 105
106no warnings;
106use strict; 107use strict;
107 108
108our $VERSION = '2.2'; 109our $VERSION = '2.2222';
109our @ISA = qw(Exporter); 110our @ISA = qw(Exporter);
110 111
111our @EXPORT = qw(encode_json decode_json to_json from_json); 112our @EXPORT = qw(encode_json decode_json to_json from_json);
112 113
113sub to_json($) { 114sub to_json($) {
706In some cases, there is the need for incremental parsing of JSON 707In some cases, there is the need for incremental parsing of JSON
707texts. While this module always has to keep both JSON text and resulting 708texts. While this module always has to keep both JSON text and resulting
708Perl data structure in memory at one time, it does allow you to parse a 709Perl data structure in memory at one time, it does allow you to parse a
709JSON stream incrementally. It does so by accumulating text until it has 710JSON stream incrementally. It does so by accumulating text until it has
710a full JSON object, which it then can decode. This process is similar to 711a full JSON object, which it then can decode. This process is similar to
711using C<decode_prefix> to see if a full JSON object is available, but is 712using C<decode_prefix> to see if a full JSON object is available, but
712much more efficient (JSON::XS will only attempt to parse the JSON text 713is much more efficient (and can be implemented with a minimum of method
714calls).
715
716JSON::XS will only attempt to parse the JSON text once it is sure it
713once it is sure it has enough text to get a decisive result, using a very 717has enough text to get a decisive result, using a very simple but
714simple but truly incremental parser). 718truly incremental parser. This means that it sometimes won't stop as
719early as the full parser, for example, it doesn't detect parenthese
720mismatches. The only thing it guarantees is that it starts decoding as
721soon as a syntactically valid JSON text has been seen. This means you need
722to set resource limits (e.g. C<max_size>) to ensure the parser will stop
723parsing in the presence if syntax errors.
715 724
716The following two methods deal with this. 725The following methods implement this incremental parser.
717 726
718=over 4 727=over 4
719 728
720=item [void, scalar or list context] = $json->incr_parse ([$string]) 729=item [void, scalar or list context] = $json->incr_parse ([$string])
721 730
763 772
764This will reset the state of the incremental parser and will remove the 773This will reset the state of the incremental parser and will remove the
765parsed text from the input buffer. This is useful after C<incr_parse> 774parsed text from the input buffer. This is useful after C<incr_parse>
766died, in which case the input buffer and incremental parser state is left 775died, in which case the input buffer and incremental parser state is left
767unchanged, to skip the text parsed so far and to reset the parse state. 776unchanged, to skip the text parsed so far and to reset the parse state.
777
778=item $json->incr_reset
779
780This completely resets the incremental parser, that is, after this call,
781it will be as if the parser had never parsed anything.
782
783This is useful if you want ot repeatedly parse JSON objects and want to
784ignore any trailing data, which means you have to reset the parser after
785each successful decode.
768 786
769=back 787=back
770 788
771=head2 LIMITATIONS 789=head2 LIMITATIONS
772 790

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines