From 73b9410420484bd642745678877a3dadd626967c Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 1 Dec 2005 22:54:42 +0000 Subject: [PATCH] cleaning up the pretty printer git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@595 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perlmods/JSON.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/perlmods/JSON.pm b/src/perlmods/JSON.pm index e36638f..a17a91a 100644 --- a/src/perlmods/JSON.pm +++ b/src/perlmods/JSON.pm @@ -100,7 +100,7 @@ sub JSON2perl { s/:/ => /sog; # Do numbers... -# s/\b(-?\d+\.?\d*)\b/ JSON::number::new($1) /sog; + #s/\b(-?\d+\.?\d*)\b/ JSON::number::new($1) /sog; # Change javascript stuff to perl... s/null/ undef /sog; @@ -222,6 +222,8 @@ sub perl2JSON { $c++; } $output .= ']'; + } elsif (ref($perl) and ref($perl) =~ /CODE/) { + $output .= perl2JSON(undef,$perl->(), $strict); } elsif (ref($perl) and ("$perl" =~ /^([^=]+)=(\w+)/o)) { my $type = $2; my $name = $1; @@ -279,7 +281,7 @@ sub perl2prettyJSON { $depth++; for my $key (sort keys %$perl) { $output .= ",\n" if ($c); - + $output .= " "x$depth; $output .= perl2prettyJSON($key)." : ".perl2prettyJSON($$perl{$key}, undef, 1); $c++; } @@ -294,7 +296,7 @@ sub perl2prettyJSON { $depth++; for my $part (@$perl) { $output .= ",\n" if ($c); - + $output .= " "x$depth; $output .= perl2prettyJSON($part); $c++; } @@ -302,6 +304,8 @@ sub perl2prettyJSON { $output .= "\n"; $output .= " "x$depth; $output .= "]"; + } elsif (ref($perl) and ref($perl) =~ /CODE/) { + $output .= perl2prettyJSON(undef,$perl->(), $nospace); } elsif (ref($perl) and "$perl" =~ /^([^=]+)=(\w{4,5})\(0x/) { my $type = $2; my $name = $1; @@ -322,7 +326,6 @@ sub perl2prettyJSON { } else { $output = '"'.$perl.'"'; } - $output .= '"'.$perl.'"'; } return $output; -- 2.11.0