summaryrefslogtreecommitdiff
path: root/lib/TUWF/Misc.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/TUWF/Misc.pm')
-rw-r--r--lib/TUWF/Misc.pm13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/TUWF/Misc.pm b/lib/TUWF/Misc.pm
index 6c08aff..e887409 100644
--- a/lib/TUWF/Misc.pm
+++ b/lib/TUWF/Misc.pm
@@ -231,4 +231,17 @@ sub TUWF::Object::validate {
_compile({ type => 'hash', keys => { @_ } })->validate($source);
}
+
+# Internal function used by other TUWF modules to find an appropriate JSON
+# module. Kinda like JSON::MaybeXS, but without an extra dependency.
+sub _JSON {
+ return 'JSON::XS' if $INC{'JSON/XS.pm'};
+ return 'Cpanel::JSON::XS' if $INC{'Cpanel/JSON/XS.pm'};
+ return 'JSON::PP' if $INC{'JSON/PP.pm'};
+ return 'JSON::XS' if eval { require JSON::XS; 1 };
+ return 'Cpanel::JSON::XS' if eval { require Cpanel::JSON::XS; 1 };
+ die "Unable to load a suitable JSON module: $@" if !eval { require JSON::PP; 1 };
+ 'JSON::PP'
+}
+
1;