chiark / gitweb /
Cope with JSON.pm version 2 which has an incompatible change
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Jul 2009 18:28:54 +0000 (19:28 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Jul 2009 18:28:54 +0000 (19:28 +0100)
pctb/database-info-fetch

index b7ebe4159292c98456ba73239b3a3d2ff2026f17..d3619caba4b3f15b70c219cc8b46e5b7a986c4d2 100755 (executable)
@@ -68,13 +68,24 @@ sub ptcl ($) {
     p("{$_[0]}");
 }
 
+sub json_convert_shim ($) {
+    my ($json) = @_;
+    # In JSON.pm 2.x, jsonToObj prints a warning to stderr which
+    # our callers don't like at all.
+    if ($JSON::VERSION >= 2) {
+       return from_json($json);
+    } else {
+       return jsonToObj($json);
+    }
+}
+
 sub get_arches_islands () {
     my $ocean= $ENV{'YPPSC_OCEAN'};  die unless $ocean;
     my $url= "$pctb/islands.php?oceanName=".uc $ocean;
     my $resp= $ua->get($url);
     die $resp->status_line unless $resp->is_success;
     $jsonresp= $resp->content;
-    my $jobj= jsonToObj($resp->content);
+    my $jobj= json_convert_shim($resp->content);
     my $arches= [ jparsetable($jobj, 'arches') ];
     my $islands= [ jparsetable($jobj, 'islands') ];
     return ($arches,$islands);