r31784 - in /branches/upstream/libhtml-tiny-perl/current: Changes META.yml Makefile.PL README SIGNATURE lib/HTML/Tiny.pm t/010-simple.t
ryan52-guest at users.alioth.debian.org
ryan52-guest at users.alioth.debian.org
Mon Mar 9 04:56:53 UTC 2009
Author: ryan52-guest
Date: Mon Mar 9 04:56:50 2009
New Revision: 31784
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=31784
Log:
[svn-upgrade] Integrating new upstream version, libhtml-tiny-perl (1.05)
Modified:
branches/upstream/libhtml-tiny-perl/current/Changes
branches/upstream/libhtml-tiny-perl/current/META.yml
branches/upstream/libhtml-tiny-perl/current/Makefile.PL
branches/upstream/libhtml-tiny-perl/current/README
branches/upstream/libhtml-tiny-perl/current/SIGNATURE
branches/upstream/libhtml-tiny-perl/current/lib/HTML/Tiny.pm
branches/upstream/libhtml-tiny-perl/current/t/010-simple.t
Modified: branches/upstream/libhtml-tiny-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/Changes?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/Changes (original)
+++ branches/upstream/libhtml-tiny-perl/current/Changes Mon Mar 9 04:56:50 2009
@@ -69,3 +69,6 @@
1.04 2009-03-07
Make link default to being closed. See #40990.
+1.05 2009-03-08
+ Add support for TO_JSON in json_encode.
+
Modified: branches/upstream/libhtml-tiny-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/META.yml?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/META.yml (original)
+++ branches/upstream/libhtml-tiny-perl/current/META.yml Mon Mar 9 04:56:50 2009
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: HTML-Tiny
-version: 1.04
+version: 1.05
abstract: Lightweight, dependency free HTML/XML generation
author:
- Andy Armstrong <andy at hexten.net>
Modified: branches/upstream/libhtml-tiny-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/Makefile.PL?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/Makefile.PL (original)
+++ branches/upstream/libhtml-tiny-perl/current/Makefile.PL Mon Mar 9 04:56:50 2009
@@ -7,9 +7,9 @@
WriteMakefile(
( MM->can( 'signature_target' ) ? ( SIGN => 1 ) : () ),
+ license( 'perl' ),
NAME => 'HTML::Tiny',
AUTHOR => 'Andy Armstrong <andy at hexten.net>',
- LICENSE => 'perl',
VERSION_FROM => 'lib/HTML/Tiny.pm',
ABSTRACT_FROM => 'lib/HTML/Tiny.pm',
PL_FILES => {},
@@ -17,3 +17,11 @@
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'HTML-Tiny-*' },
);
+
+sub license {
+ my $lic = shift;
+ local $^W = 0; # Silence warning about non-numeric version
+ return
+ unless $ExtUtils::MakeMaker::VERSION >= '6.31';
+ return ( LICENSE => $lic );
+}
Modified: branches/upstream/libhtml-tiny-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/README?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/README (original)
+++ branches/upstream/libhtml-tiny-perl/current/README Mon Mar 9 04:56:50 2009
@@ -1,4 +1,4 @@
-HTML-Tiny version 1.04
+HTML-Tiny version 1.05
INSTALLATION
Modified: branches/upstream/libhtml-tiny-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/SIGNATURE?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/SIGNATURE (original)
+++ branches/upstream/libhtml-tiny-perl/current/SIGNATURE Mon Mar 9 04:56:50 2009
@@ -14,17 +14,17 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
-SHA1 ec9fe960e341f5973f5ebe7809db6f7eb89d0cfd Changes
+SHA1 62e87f19330fb069a70c6ca5d9f46a3fd1496fb8 Changes
SHA1 2154be00d1d4424cbcf120a4877b821bcfb7a462 MANIFEST
-SHA1 2b6d7b7856ec393b45f8d5c899706c45e0688c4a META.yml
-SHA1 676da95cada2028e417fa29fbfd28fda2517bffc Makefile.PL
-SHA1 411be166b8b5c82e1964d816e791bbe439b3bb79 README
+SHA1 472edf6015f28af38ab13ad559ff37d38847590b META.yml
+SHA1 f5916918a7a71bed9bf24bd75b15a7cb68b09a79 Makefile.PL
+SHA1 d1941d887c402d594cb2b1821596da8e4ee53ed2 README
SHA1 e43a62a1d9e28cb27aa0398d04fdb3375525bec1 examples/js.pl
SHA1 d4252e83b7c13702f6b63da1d780c11ff85c22dc examples/simple.pl
SHA1 75ca2ec3d063d1df8879d1c1eeb3f697e4f20e92 examples/table.pl
-SHA1 2d316db07a1194d78b780fb0a16982e6926e9f7c lib/HTML/Tiny.pm
+SHA1 1674fa60eabf9c3950066383a517b6cbe9b90cda lib/HTML/Tiny.pm
SHA1 5c74290159e6f8bcbb090a644b3c0281e5d7df62 t/000-load.t
-SHA1 ca02e317dbfa0a3ddb45a23f655598963d522600 t/010-simple.t
+SHA1 a2637e357b8ccd9b8d61a8137e034369f3af5a4e t/010-simple.t
SHA1 8548114d87260c3a9819f29197063f1044fcae83 t/020-coverage.t
SHA1 1353dd0c96cd9571dab11704b294409f4a63857d t/030-tags.t
SHA1 668745e9922e535b23a418e4d00d2a224cf2e4bb t/040-lazy.t
@@ -34,7 +34,7 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
-iEYEARECAAYFAkmyrcgACgkQwoknRJZQnCEp7wCggHL2wqZehjLfkHD2wnXfOKvw
-QlQAniqC8r+oF/D0pyCzAyK8PD7Xa0ye
-=s58H
+iEYEARECAAYFAkm0AvUACgkQwoknRJZQnCF9SgCguXdQ3oSPntbttg3f0nNSQ0Ct
+Ib4AoIoqoJejnoRYU7kERTPgLuLe43Mg
+=Hy4e
-----END PGP SIGNATURE-----
Modified: branches/upstream/libhtml-tiny-perl/current/lib/HTML/Tiny.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/lib/HTML/Tiny.pm?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/lib/HTML/Tiny.pm (original)
+++ branches/upstream/libhtml-tiny-perl/current/lib/HTML/Tiny.pm Mon Mar 9 04:56:50 2009
@@ -9,12 +9,12 @@
=head1 VERSION
-This document describes HTML::Tiny version 1.04
+This document describes HTML::Tiny version 1.05
=cut
use vars qw/$VERSION/;
-$VERSION = '1.04';
+$VERSION = '1.05';
BEGIN {
@@ -665,6 +665,32 @@
x18 x19 x1a e x1c x1d x1e x1f
);
+ sub _json_encode_ref {
+ my ( $self, $seen, $obj ) = @_;
+ my $type = ref $obj;
+ if ( 'HASH' eq $type ) {
+ return '{' . join(
+ ',',
+ map {
+ $self->_json_encode( $seen, $_ ) . ':'
+ . $self->_json_encode( $seen, $obj->{$_} )
+ } sort keys %$obj
+ ) . '}';
+ }
+ elsif ( 'ARRAY' eq $type ) {
+ return
+ '['
+ . join( ',', map { $self->_json_encode( $seen, $_ ) } @$obj )
+ . ']';
+ }
+ elsif ( UNIVERSAL::can( $obj, 'can' ) && $obj->can( 'TO_JSON' ) ) {
+ return $self->_json_encode( $seen, $obj->TO_JSON );
+ }
+ else {
+ croak "Can't json_encode a $type";
+ }
+ }
+
# Minimal JSON encoder. Provided here for completeness - it's useful
# when generating JS.
sub _json_encode {
@@ -675,28 +701,9 @@
if ( my $type = ref $obj ) {
croak "json_encode can't handle self referential structures"
if $seen->{$obj}++;
- my $rep = ( 'HASH' eq $type )
- ? (
- '{' . join(
- ',',
- map {
- $self->_json_encode( $seen, $_ ) . ':'
- . $self->_json_encode( $seen, $obj->{$_} )
- } sort keys %$obj
- )
- . '}'
- )
- : ( 'ARRAY' eq $type ) ? (
- '['
- . join(
- ',',
- map { $self->_json_encode( $seen, $_ ) } @$obj
- )
- . ']'
- )
- : undef;
+ my $rep = $self->_json_encode_ref( $seen, $obj );
delete $seen->{$obj};
- return $rep if defined $rep;
+ return $rep;
}
return $obj if $obj =~ /^-?\d+(?:[.]\d+)?$/;
@@ -737,6 +744,11 @@
# <script type="text/javascript">
# var someVar = {"history":[32,37,41,45],"name":"Fred","score":45};
# </script>
+
+If you attempt to json encode a blessed object C<json_encode> will look
+for a C<TO_JSON> method and, if found, use its return value as the
+structure to be converted in place of the object. An attempt to encode a
+blessed object that does not implement C<TO_JSON> will fail.
=cut
Modified: branches/upstream/libhtml-tiny-perl/current/t/010-simple.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhtml-tiny-perl/current/t/010-simple.t?rev=31784&op=diff
==============================================================================
--- branches/upstream/libhtml-tiny-perl/current/t/010-simple.t (original)
+++ branches/upstream/libhtml-tiny-perl/current/t/010-simple.t Mon Mar 9 04:56:50 2009
@@ -60,6 +60,7 @@
package T::Obj;
sub new { bless {}, shift }
sub as_string { 'an object' }
+sub TO_JSON { 'a json object' }
package T::Obj2;
sub new { bless {}, shift }
@@ -124,8 +125,8 @@
'json simple hash OK';
is $h->json_encode( { ar => [ 1, 2, 3, { a => 1, b => 2 } ] } ),
'{"ar":[1,2,3,{"a":1,"b":2}]}', 'json complex OK';
-is $h->json_encode( { obj => $obj } ), '{"obj":"an object"}',
- 'json stringification OK';
+is $h->json_encode( { obj => $obj } ), '{"obj":"a json object"}',
+ 'TO_JSON used OK';
is $h->json_encode( undef ), 'null', 'json null OK';
is $h->json_encode( [undef] ), '[null]', 'json null in array OK';
More information about the Pkg-perl-cvs-commits
mailing list