r55501 - in /trunk/libjson-perl: Changes MANIFEST META.yml README debian/changelog eg/bench_decode.pl eg/bench_encode.pl eg/bench_pp_xs.pl lib/JSON.pm
angelabad-guest at users.alioth.debian.org
angelabad-guest at users.alioth.debian.org
Mon Apr 5 12:54:46 UTC 2010
Author: angelabad-guest
Date: Mon Apr 5 12:54:33 2010
New Revision: 55501
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=55501
Log:
New upstream release 2.21
Added:
trunk/libjson-perl/eg/bench_decode.pl
- copied unchanged from r55500, branches/upstream/libjson-perl/current/eg/bench_decode.pl
trunk/libjson-perl/eg/bench_encode.pl
- copied unchanged from r55500, branches/upstream/libjson-perl/current/eg/bench_encode.pl
Removed:
trunk/libjson-perl/eg/bench_pp_xs.pl
Modified:
trunk/libjson-perl/Changes
trunk/libjson-perl/MANIFEST
trunk/libjson-perl/META.yml
trunk/libjson-perl/README
trunk/libjson-perl/debian/changelog
trunk/libjson-perl/lib/JSON.pm
Modified: trunk/libjson-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjson-perl/Changes?rev=55501&op=diff
==============================================================================
--- trunk/libjson-perl/Changes (original)
+++ trunk/libjson-perl/Changes Mon Apr 5 12:54:33 2010
@@ -15,6 +15,12 @@
!! Since 2.16, PP's relaxed option caused an infinite loop in some condition.
!! Recommend to update old versions.
+
+2.21 Mon Apr 5 14:56:52 2010
+ [JSON]
+ - enhanced 'HOW DO I DECODE A DATA FROM OUTER AND ENCODE TO OUTER'
+ - renamed eg/bench_pp_xs.pl to eg/bench_decode.pl
+ - added eg/bench_encode.pl
2.20 Fri Apr 2 12:50:08 2010
[JSON]
Modified: trunk/libjson-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjson-perl/MANIFEST?rev=55501&op=diff
==============================================================================
--- trunk/libjson-perl/MANIFEST (original)
+++ trunk/libjson-perl/MANIFEST Mon Apr 5 12:54:33 2010
@@ -1,5 +1,6 @@
Changes
-eg/bench_pp_xs.pl
+eg/bench_decode.pl
+eg/bench_encode.pl
lib/JSON.pm
lib/JSON/PP.pm
lib/JSON/PP/Boolean.pm
Modified: trunk/libjson-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjson-perl/META.yml?rev=55501&op=diff
==============================================================================
--- trunk/libjson-perl/META.yml (original)
+++ trunk/libjson-perl/META.yml Mon Apr 5 12:54:33 2010
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: JSON
-version: 2.20
+version: 2.21
abstract: JSON (JavaScript Object Notation) encoder/decoder
author:
- Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
Modified: trunk/libjson-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjson-perl/README?rev=55501&op=diff
==============================================================================
--- trunk/libjson-perl/README (original)
+++ trunk/libjson-perl/README Mon Apr 5 12:54:33 2010
@@ -1,4 +1,4 @@
-JSON version 2.20
+JSON version 2.21
=================
INSTALLATION
@@ -45,7 +45,7 @@
# recommend to use (en|de)code_json.
VERSION
- 2.20
+ 2.21
This version is compatible with JSON::XS 2.27 and later.
@@ -240,8 +240,8 @@
If you know a JSON text from an outer world - a network, a file content,
and so on, is encoded in UTF-8, you should use "decode_json" or "JSON"
- module object with "utf8" enable. And the decoded data contains UNICODE
- characters.
+ module object with "utf8" enable. And the decoded result will contain
+ UNICODE characters.
# from network
my $json = JSON->new->utf8;
@@ -254,50 +254,67 @@
$json_text = <$fh>;
$perl_scalar = decode_json( $json_text );
- If your data is not encoded in UTF-8, firstly you should "decode" it.
+ If an outer data is not encoded in UTF-8, firstly you should "decode"
+ it.
use Encode;
local $/;
- open( my $fh, '<', 'json.data' ); # ex. this data is encoded in cp932.
- $json_text = decode( 'cp932', <$fh> ); # UNICODE
+ open( my $fh, '<', 'json.data' );
+ my $encoding = 'cp932';
+ my $unicode_json_text = decode( $encoding, <$fh> ); # UNICODE
# or you can write the below code.
#
- # open( my $fh, '<:encoding(cp932)', 'json.data' );
- # $json_text = <$fh>;
-
- In this case, $json_text is UNICODE string. So you cannot use
- "decode_json" nor "JSON" module object with "utf8" enable. Instead of
- them, you use "JSON" module object with "utf8" disable or "from_json".
-
- $perl_scalar = $json->utf8(0)->decode( $json_text );
+ # open( my $fh, "<:encoding($encoding)", 'json.data' );
+ # $unicode_json_text = <$fh>;
+
+ In this case, $unicode_json_text is of course UNICODE string. So you
+ cannot use "decode_json" nor "JSON" module object with "utf8" enable.
+ Instead of them, you use "JSON" module object with "utf8" disable or
+ "from_json".
+
+ $perl_scalar = $json->utf8(0)->decode( $unicode_json_text );
# or
- $perl_scalar = from_json( $json_text );
+ $perl_scalar = from_json( $unicode_json_text );
+
+ Or "encode 'utf8'" and "decode_json":
+
+ $perl_scalar = decode_json( encode( 'utf8', $unicode_json_text ) );
+ # this way is not efficient.
And now, you want to convert your $perl_scalar into JSON data and send
it to an outer world - a network or a file content, and so on.
- If your data contains UNICODE strings and you want the converted data to
- be encoded in UTF-8, you should use "encode_json" or "JSON" module
- object with "utf8" enable.
+ Your data usually contains UNICODE strings and you want the converted
+ data to be encoded in UTF-8, you should use "encode_json" or "JSON"
+ module object with "utf8" enable.
print encode_json( $perl_scalar ); # to a network? file? or display?
# or
print $json->utf8->encode( $perl_scalar );
- And if $perl_scalar does not contain UNICODE, then your characters are
- latin1 for perl. So you cannot use "encode_json" nor "JSON" module
- object with "utf8" enable. Instead of them, you use "JSON" module object
- with "utf8" disable or "to_json".
-
- $json_text = $json->utf8(0)->encode( $perl_scalar );
+ If $perl_scalar does not contain UNICODE but $encoding-encoded strings
+ for some reason, then its characters are regarded as latin1 for perl
+ (because it does not concern with your $encoding). You cannot use
+ "encode_json" nor "JSON" module object with "utf8" enable. Instead of
+ them, you use "JSON" module object with "utf8" disable or "to_json".
+ Note that the resulted text is a UNICODE string but no problem to print
+ it.
+
+ # $perl_scalar contains $encoding encoded string values
+ $unicode_json_text = $json->utf8(0)->encode( $perl_scalar );
# or
- $json_text = to_json( $perl_scalar );
-
- # and then print or convert to UNICODE
- print $json_text;
-
- $unicode_json_text = encode( $encoding, $json_text );
+ $unicode_json_text = to_json( $perl_scalar );
+ # $unicode_json_text consists of characters less than 0x100
+ print $unicode_json_text;
+
+ Or "decode $encoding" all string values and "encode_json":
+
+ $perl_scalar->{ foo } = decode( $encoding, $perl_scalar->{ foo } );
+ # ... do it to each string values, then encode_json
+ $json_text = encode_json( $perl_scalar );
+
+ This method is a proper way but probably not efficient.
See to Encode, perluniintro.
Modified: trunk/libjson-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjson-perl/debian/changelog?rev=55501&op=diff
==============================================================================
--- trunk/libjson-perl/debian/changelog (original)
+++ trunk/libjson-perl/debian/changelog Mon Apr 5 12:54:33 2010
@@ -1,3 +1,9 @@
+libjson-perl (2.21-1) unstable; urgency=low
+
+ * New upstream release
+
+ -- Angel Abad <angelabad at gmail.com> Mon, 05 Apr 2010 14:54:11 +0200
+
libjson-perl (2.20-1) unstable; urgency=low
* New upstream release.
Modified: trunk/libjson-perl/lib/JSON.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjson-perl/lib/JSON.pm?rev=55501&op=diff
==============================================================================
--- trunk/libjson-perl/lib/JSON.pm (original)
+++ trunk/libjson-perl/lib/JSON.pm Mon Apr 5 12:54:33 2010
@@ -7,7 +7,7 @@
@JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json);
BEGIN {
- $JSON::VERSION = '2.20';
+ $JSON::VERSION = '2.21';
$JSON::DEBUG = 0 unless (defined $JSON::DEBUG);
}
@@ -608,7 +608,7 @@
=head1 VERSION
- 2.20
+ 2.21
This version is compatible with JSON::XS B<2.27> and later.
@@ -819,7 +819,7 @@
If you know a JSON text from an outer world - a network, a file content, and so on,
is encoded in UTF-8, you should use C<decode_json> or C<JSON> module object
-with C<utf8> enable. And the decoded data contains UNICODE characters.
+with C<utf8> enable. And the decoded result will contain UNICODE characters.
# from network
my $json = JSON->new->utf8;
@@ -832,49 +832,63 @@
$json_text = <$fh>;
$perl_scalar = decode_json( $json_text );
-If your data is not encoded in UTF-8, firstly you should C<decode> it.
+If an outer data is not encoded in UTF-8, firstly you should C<decode> it.
use Encode;
local $/;
- open( my $fh, '<', 'json.data' ); # ex. this data is encoded in cp932.
- $json_text = decode( 'cp932', <$fh> ); # UNICODE
+ open( my $fh, '<', 'json.data' );
+ my $encoding = 'cp932';
+ my $unicode_json_text = decode( $encoding, <$fh> ); # UNICODE
# or you can write the below code.
#
- # open( my $fh, '<:encoding(cp932)', 'json.data' );
- # $json_text = <$fh>;
-
-In this case, C<$json_text> is UNICODE string.
+ # open( my $fh, "<:encoding($encoding)", 'json.data' );
+ # $unicode_json_text = <$fh>;
+
+In this case, C<$unicode_json_text> is of course UNICODE string.
So you B<cannot> use C<decode_json> nor C<JSON> module object with C<utf8> enable.
Instead of them, you use C<JSON> module object with C<utf8> disable or C<from_json>.
- $perl_scalar = $json->utf8(0)->decode( $json_text );
+ $perl_scalar = $json->utf8(0)->decode( $unicode_json_text );
# or
- $perl_scalar = from_json( $json_text );
+ $perl_scalar = from_json( $unicode_json_text );
+
+Or C<encode 'utf8'> and C<decode_json>:
+
+ $perl_scalar = decode_json( encode( 'utf8', $unicode_json_text ) );
+ # this way is not efficient.
And now, you want to convert your C<$perl_scalar> into JSON data and
send it to an outer world - a network or a file content, and so on.
-If your data contains UNICODE strings and you want the converted data to be encoded
+Your data usually contains UNICODE strings and you want the converted data to be encoded
in UTF-8, you should use C<encode_json> or C<JSON> module object with C<utf8> enable.
print encode_json( $perl_scalar ); # to a network? file? or display?
# or
print $json->utf8->encode( $perl_scalar );
-And if C<$perl_scalar> does not contain UNICODE, then your characters are latin1 for perl.
-So you B<cannot> use C<encode_json> nor C<JSON> module object with C<utf8> enable.
+If C<$perl_scalar> does not contain UNICODE but C<$encoding>-encoded strings
+for some reason, then its characters are regarded as B<latin1> for perl
+(because it does not concern with your $encoding).
+You B<cannot> use C<encode_json> nor C<JSON> module object with C<utf8> enable.
Instead of them, you use C<JSON> module object with C<utf8> disable or C<to_json>.
-
- $json_text = $json->utf8(0)->encode( $perl_scalar );
+Note that the resulted text is a UNICODE string but no problem to print it.
+
+ # $perl_scalar contains $encoding encoded string values
+ $unicode_json_text = $json->utf8(0)->encode( $perl_scalar );
# or
- $json_text = to_json( $perl_scalar );
-
- # and then print or convert to UNICODE
- print $json_text;
-
- $unicode_json_text = encode( $encoding, $json_text );
-
+ $unicode_json_text = to_json( $perl_scalar );
+ # $unicode_json_text consists of characters less than 0x100
+ print $unicode_json_text;
+
+Or C<decode $encoding> all string values and C<encode_json>:
+
+ $perl_scalar->{ foo } = decode( $encoding, $perl_scalar->{ foo } );
+ # ... do it to each string values, then encode_json
+ $json_text = encode_json( $perl_scalar );
+
+This method is a proper way but probably not efficient.
See to L<Encode>, L<perluniintro>.
More information about the Pkg-perl-cvs-commits
mailing list