X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx%2FJSONDump.pm;h=07ce9e99996e2f93e3ff82af7ad20a233440c70a;hb=febed4ec71f803b083c3e61b82b9464e9bfb0992;hp=f28e444bb978bf2116e7f91c6c0a6ba0fff26a95;hpb=ba92ea5b36cbcd9c03016491dfb06dfc74baf409;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex/JSONDump.pm b/lib/CGI/Ex/JSONDump.pm index f28e444..07ce9e9 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.16'; + $VERSION = '2.27'; @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