[interchange] Make JSON non-required module
David Christensen
interchange-cvs at icdevgroup.org
Tue Dec 30 16:30:00 UTC 2014
commit 75bf32b7cccdfba3e864a441c4ab965882a56cf0
Author: David Christensen <david at endpoint.com>
Date: Tue Dec 30 10:29:38 2014 -0600
Make JSON non-required module
lib/Vend/Server.pm | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/lib/Vend/Server.pm b/lib/Vend/Server.pm
index 09fe475..dfd47a9 100644
--- a/lib/Vend/Server.pm
+++ b/lib/Vend/Server.pm
@@ -23,7 +23,7 @@
package Vend::Server;
-use vars qw($VERSION);
+use vars qw($VERSION $Has_JSON);
$VERSION = '2.107';
use Cwd;
@@ -35,9 +35,18 @@ use Errno qw/:POSIX/;
use Config;
use Socket;
use Symbol;
-use JSON ();
use strict;
+{
+ local $@;
+ eval {
+ require JSON;
+ };
+ unless ($@) {
+ $Has_JSON = 1;
+ }
+}
+
no warnings qw(uninitialized);
my $ppidsub = sub { return getppid };
@@ -323,13 +332,13 @@ sub parse_cgi {
if ($CGI::content_type =~ m{^(?:multipart/form-data|application/x-www-form-urlencoded|application/xml|application/json)\b}i) {
parse_post(\$CGI::query_string, 1)
if $Global::TolerateGet;
- if ($CGI::content_type =~ m{^application/json\s*(?:;|$)}i) {
+ if ($Has_JSON && $CGI::content_type =~ m{^application/json\s*(?:;|$)}i) {
$CGI::post_ref = $h->{entity};
undef $CGI::json_ref;
eval {
$CGI::json_ref = JSON::from_json($$CGI::post_ref);
#::logDebug('json: %s', ::uneval($CGI::json_ref));
- # populate CGI from json_ref; maybe make a directive?
+
if ($Global::UnpackJSON && ref $CGI::json_ref eq 'HASH') {
@CGI::values{keys %$CGI::json_ref} = values %$CGI::json_ref;
}
More information about the interchange-cvs
mailing list