chiark / gitweb /
website copes with older JSON.pm
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 14 Aug 2009 19:41:54 +0000 (20:41 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 15 Aug 2009 23:46:57 +0000 (00:46 +0100)
yarrg/CommodsWeb.pm
yarrg/web/routetextstring

index 5f85511f5fed815f2d73e70e435c710a383e2daa..d423a299c48136c20d7fe9ab3c408cffba402ec7 100644 (file)
@@ -52,7 +52,7 @@ BEGIN {
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&dbw_connect &ocean_list $sourcebasedir
-                     &to_json &to_json_protecttags
+                     &to_json_shim &to_json_protecttags
                      &set_ctype_utf8);
     %EXPORT_TAGS = ( );
 
@@ -103,9 +103,20 @@ sub dbw_connect ($) {
     return dbr_connect($datadir, $ocean);
 }
 
+sub to_json_shim ($) {
+    my ($obj) = @_;
+    # In JSON.pm 2.x, jsonToObj prints a warning to stderr which
+    # our callers don't like at all.
+    if ($JSON::VERSION >= 2.0) {
+       return to_json($obj);
+    } else {
+       return objToJson($obj);
+    }
+}
+
 sub to_json_protecttags ($) {
     my ($v) = @_;
-    my $j= to_json($v);
+    my $j= to_json_shim($v);
     $j =~ s,/,\\/,g;
     return $j;
 }
index 9107780def29f20e6f28715178efe4397c9c6176..be009d4e5a4b8fa624a5f809a079a432d0b1da2f 100755 (executable)
@@ -69,12 +69,12 @@ my ($output, $output_wrong);
 
 if ($format =~ /json/) {
        $r->content_type($ctype or $format);
-       $output= sub { print to_json({
+       $output= sub { print to_json_shim({
                success => 1,
                show => length $canontext ? encode_entities($canontext)
                        : '&nbsp;',
                })};
-       $output_wrong= sub { print to_json({
+       $output_wrong= sub { print to_json_shim({
                success => 0,
                show => $_[0],
                })};
@@ -108,7 +108,7 @@ foreach my $each (split m#[/|,]#, $string) {
        if (!$results) {
                if (!%m) {
                        return $err->('no island or arch matches "%s"');
-               } elsif (%m > 5) {
+               } elsif (keys(%m) > 5) {
                        return $err->('&nbsp;');
                } else {
                        return $err->('ambiguous island or arch "%s",'.