]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
Json alternative support
authorhadeshyp <hadeshyp>
Tue, 16 Oct 2012 20:42:34 +0000 (20:42 +0000)
committerhadeshyp <hadeshyp>
Tue, 16 Oct 2012 20:42:34 +0000 (20:42 +0000)
cts/htdocs/cts.pl

index f62bf1ec5743bf375aff0dec4b9b31a8c71393c0..b2b10f864a373b2f7d4800ea79c0a213fc0fabab 100755 (executable)
@@ -5,7 +5,16 @@ use lib "./include/";
 
 use Cts;
 use CtsConfig;
-use JSON;
+
+BEGIN {
+   if (eval "require JSON::PP;") {
+      *JSON_BIND:: = *JSON::PP::;
+   } else {
+      eval "require JSON;";
+      *JSON_BIND:: = *JSON::XS::;
+   }
+}
+
 
 sub connectToCTS {
    my $endpoint = shift;
@@ -23,7 +32,7 @@ my $cts = connectToCTS( CtsConfig->getDefaultEndpoint );
 my $query = $ENV{'QUERY_STRING'};
 
 if ($query eq "init") {
-   print JSON::XS->new->allow_blessed->convert_blessed->encode({
+   print JSON_BIND->new->allow_blessed->convert_blessed->encode({
       'registers' => $cts->getRegisters,
       'properties' => $cts->getProperties
    });
@@ -39,7 +48,7 @@ if ($query eq "init") {
       $result{$key} = $op eq "read" ? $reg->read() : $reg->format();
    }
    
-   print JSON::XS->new->allow_blessed->convert_blessed->encode(\%result);
+   print JSON_BIND->new->allow_blessed->convert_blessed->encode(\%result);
 } elsif ($query =~ /^write,([\w\d_,\.\[\]]+)$/) {
    my @values = split /,/, $1;
    my $regs = {};