From: hadeshyp Date: Tue, 16 Oct 2012 20:42:34 +0000 (+0000) Subject: Json alternative support X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=680ad2f65ab929dedf4d38a51db8c00a207dd512;p=daqtools.git Json alternative support --- diff --git a/cts/htdocs/cts.pl b/cts/htdocs/cts.pl index f62bf1e..b2b10f8 100755 --- a/cts/htdocs/cts.pl +++ b/cts/htdocs/cts.pl @@ -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 = {};