support JSON version 1 and 2 for Red Hat EL and Debian compatibilities

This commit is contained in:
Thomas CHEMINEAU 2010-04-13 16:43:32 +00:00
parent bc21f58b46
commit 19256b0aaa

View File

@ -372,12 +372,22 @@ sub fileUpload {
$content =~ s!<!&lt;!g;
$content =~ s!>!&gt;!g;
# Red Hat / Debian compatibilities
my $json = new JSON();
$json = $json->allow_nonref( ['1'] );
$json = $json->utf8( ['1'] );
my $json_content = $json->encode($content);
my $content = '{"status":"OK", "content":' . $json_content . '}';
my $json_content = '';
if ($JSON::VERSION lt 2) {
local $JSON::UTF8 = 1;
$json_content = $json->objToJson([$content]);
$json_content =~ s/^\[//;
$json_content =~ s/\]$//;
}
else {
$json = $json->allow_nonref( ['1'] );
$json = $json->utf8( ['1'] );
$json_content = $json->encode($content);
}
my $content = '{"status":"OK", "content":' . $json_content . '}';
print $self->header(
-type => 'text/html; charset=utf-8',
-Content_Length => length $content
@ -407,12 +417,22 @@ sub urlUpload {
$content =~ s!>!&gt;!g;
# Build JSON reponse
# Require Red Hat and Debian compatibilites
my $json = new JSON();
$json = $json->allow_nonref( ['1'] );
$json = $json->utf8( ['1'] );
my $json_content = $json->encode($content);
$content = '{"status":"OK", "content":' . $json_content . '}';
my $json_content = '';
if ($JSON::VERSION lt 2) {
local $JSON::UTF8 = 1;
$json_content = $json->objToJson([$content]);
$json_content =~ s/^\[//;
$json_content =~ s/\]$//;
}
else {
$json = $json->allow_nonref( ['1'] );
$json = $json->utf8( ['1'] );
$json_content = $json->encode($content);
}
$content = '{"status":"OK", "content":' . $json_content . '}';
print $self->header(
-type => 'text/html; charset=utf-8',
-Content_Length => length $content