X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=lib%2FCGI%2FEx%2FJSONDump.pm;h=69222bf85bdeb46ab150908394c75e65093d277e;hp=fe7c562b2fad2efaeb9e1cf475a6aecddb0e017f;hb=48c4840be1f154e262de2c161cb86dc5000dfe47;hpb=d710d6cd21be21c0ab2df3566c2bd61d9015cac6 diff --git a/lib/CGI/Ex/JSONDump.pm b/lib/CGI/Ex/JSONDump.pm index fe7c562..69222bf 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.04'; + $VERSION = '2.05'; @EXPORT = qw(JSONDump); @EXPORT_OK = @EXPORT; @@ -108,8 +108,8 @@ sub js_escape { my $quote = $self->{'single_quote'} ? "'" : '"'; $str =~ s/\\/\\\\/g; - $str =~ s/\r/\\\r/g; - $str =~ s/\t/\\\t/g; + $str =~ s/\r/\\r/g; + $str =~ s/\t/\\t/g; $self->{'single_quote'} ? $str =~ s/\'/\\\'/g : $str =~ s/\"/\\\"/g; ### allow for really odd chars @@ -238,7 +238,7 @@ include whitespace to make them more readable. with single quotes. Otherwise values are quoted with double quotes. JSONDump("a", {single_quote => 0}); - JSONDump('a', {single_quote => 0}); + JSONDump("a", {single_quote => 1}); Would print @@ -249,7 +249,7 @@ with single quotes. Otherwise values are quoted with double quotes. 0 or 1. Default 1 (true) -If true, then key/value pairs of hashrefs will be sorted will be output in sorted order. +If true, then key/value pairs of hashrefs will be output in sorted order. =item play_coderefs @@ -294,9 +294,10 @@ with unknown types will not be included in the javascript output. =item skip_keys -Should contain an arrayref of keys or a hashref whose keys are the keys to skip. Default -is unset. Any keys of hashrefs that are in the skip_keys item will not be included in -the javascript output. +Should contain an arrayref of keys or a hashref whose keys are the +keys to skip. Default is unset. Any keys of hashrefs (including +nested hashrefs) that are in the skip_keys item will not be included +in the javascript output. JSONDump({a => 1, b => 1}, {skip_keys => ['a'], pretty => 0}); @@ -306,8 +307,9 @@ the javascript output. =item skip_keys_qr -Similar to skip_keys but should contain a regex. Any keys of hashrefs that match the -skip_keys_qr regex will not be included in the javascript output. +Similar to skip_keys but should contain a regex. Any keys of hashrefs +(including nested hashrefs) that match the skip_keys_qr regex will not +be included in the javascript output. JSONDump({a => 1, _b => 1}, {skip_keys_qr => qr/^_/, pretty => 0}); @@ -346,7 +348,7 @@ greater than 80 characters. Default is "\n". +"with plenty of embedded newlines\n" +"and is greater than 80 characters.\n" -If the string is less than 80 characters, or if str_nl is set to '', then the escaped +If the string is less than 80 characters, or if str_nl is set to "", then the escaped string will be contained on a single line. =back