| 1 | package JSON::PP58; |
|---|
| 2 | |
|---|
| 3 | use 5.008; |
|---|
| 4 | use strict; |
|---|
| 5 | |
|---|
| 6 | my @properties; |
|---|
| 7 | |
|---|
| 8 | $JSON::PP58::VERSION = '1.02'; |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | BEGIN { |
|---|
| 12 | |
|---|
| 13 | unless ( defined &utf8::is_utf8 ) { |
|---|
| 14 | require Encode; |
|---|
| 15 | *utf8::is_utf8 = *Encode::is_utf8; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | *JSON::PP::JSON_PP_encode_ascii = \&JSON::PP::_encode_ascii; |
|---|
| 19 | *JSON::PP::JSON_PP_encode_latin1 = \&JSON::PP::_encode_latin1; |
|---|
| 20 | *JSON::PP::JSON_PP_decode_surrogates = \&JSON::PP::_decode_surrogates; |
|---|
| 21 | *JSON::PP::JSON_PP_decode_unicode = \&JSON::PP::_decode_unicode; |
|---|
| 22 | |
|---|
| 23 | if ($] >= 5.008 and $] < 5.008003) { # join() in 5.8.0 - 5.8.2 is broken. |
|---|
| 24 | package JSON::PP; |
|---|
| 25 | require subs; |
|---|
| 26 | subs->import('join'); |
|---|
| 27 | eval q| |
|---|
| 28 | sub join { |
|---|
| 29 | return '' if (@_ < 2); |
|---|
| 30 | my $j = shift; |
|---|
| 31 | my $str = shift; |
|---|
| 32 | for (@_) { $str .= $j . $_; } |
|---|
| 33 | return $str; |
|---|
| 34 | } |
|---|
| 35 | |; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | sub JSON::PP::incr_parse { |
|---|
| 42 | local $Carp::CarpLevel = 1; |
|---|
| 43 | ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_parse( @_ ); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | sub JSON::PP::incr_text : lvalue { |
|---|
| 48 | $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new; |
|---|
| 49 | |
|---|
| 50 | if ( $_[0]->{_incr_parser}->{incr_parsing} ) { |
|---|
| 51 | Carp::croak("incr_text can not be called when the incremental parser already started parsing"); |
|---|
| 52 | } |
|---|
| 53 | $_[0]->{_incr_parser}->{incr_text}; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | sub JSON::PP::incr_skip { |
|---|
| 58 | ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_skip; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | sub JSON::PP::incr_reset { |
|---|
| 63 | ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_reset; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | 1; |
|---|
| 68 | __END__ |
|---|
| 69 | |
|---|
| 70 | =pod |
|---|
| 71 | |
|---|
| 72 | =head1 NAME |
|---|
| 73 | |
|---|
| 74 | JSON::PP58 - Helper module in using JSON::PP in Perl 5.8 and lator |
|---|
| 75 | |
|---|
| 76 | =head1 DESCRIPTION |
|---|
| 77 | |
|---|
| 78 | JSON::PP calls internally. |
|---|
| 79 | |
|---|
| 80 | =head1 AUTHOR |
|---|
| 81 | |
|---|
| 82 | Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt> |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | =head1 COPYRIGHT AND LICENSE |
|---|
| 86 | |
|---|
| 87 | Copyright 2008 by Makamaka Hannyaharamitu |
|---|
| 88 | |
|---|
| 89 | This library is free software; you can redistribute it and/or modify |
|---|
| 90 | it under the same terms as Perl itself. |
|---|
| 91 | |
|---|
| 92 | =cut |
|---|
| 93 | |
|---|