X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx%2FJSONDump.pm;h=b45b11bd67b1ae1ceee203ac4a381a06219ed770;hb=fdecaac30a1168ed894c46d61b6c95524ec62a4e;hp=6d58f0923803880524ac40ab9711a427982c49e1;hpb=a2f50b1efd2bc986617e1de5f5a0bfd8a2953b0e;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex/JSONDump.pm b/lib/CGI/Ex/JSONDump.pm index 6d58f09..b45b11b 100644 --- a/lib/CGI/Ex/JSONDump.pm +++ b/lib/CGI/Ex/JSONDump.pm @@ -17,7 +17,7 @@ use strict; use base qw(Exporter); BEGIN { - $VERSION = '2.19'; + $VERSION = '2.32'; @EXPORT = qw(JSONDump); @EXPORT_OK = @EXPORT; @@ -75,7 +75,7 @@ sub _dump { return "{}" if ! @keys; return "{$self->{hash_nl}${prefix}$self->{indent}" . join(",$self->{hash_nl}${prefix}$self->{indent}", - map { $self->js_escape($_, "${prefix}$self->{indent}") + map { $self->js_escape($_, "${prefix}$self->{indent}", 1) . $self->{'hash_sep'} . $self->_dump($data->{$_}, "${prefix}$self->{indent}") } @keys) @@ -99,11 +99,11 @@ sub _dump { } sub js_escape { - my ($self, $str, $prefix) = @_; + my ($self, $str, $prefix, $no_num) = @_; return 'null' if ! defined $str; ### allow things that look like numbers to show up as numbers (and those that aren't quite to not) - return $str if $str =~ /^ -? (?: [1-9][0-9]{0,12} | 0) (?: \. \d* [1-9])? $/x; + return $str if ! $no_num && $str =~ /^ -? (?: [1-9][0-9]{0,12} | 0) (?: \. \d* [1-9])? $/x; my $quote = $self->{'single_quote'} ? "'" : '"'; @@ -142,11 +142,11 @@ __END__ use CGI::Ex::JSONDump; - my $js = JSONDump(\%complex_data, {pretty => 0}); + my $js = JSONDump(\%complex_data, {pretty => 1}); ### OR - my $js = CGI::Ex::JSONDump->new({pretty => 0})->dump(\%complex_data); + my $js = CGI::Ex::JSONDump->new({pretty => 1})->dump(\%complex_data); =head1 DESCRIPTION