X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2FCommodsWeb.pm;h=d423a299c48136c20d7fe9ab3c408cffba402ec7;hb=e05f0567ea23491da8e48f892a3337f37139628f;hp=0c86e6cbfe0976b20fa6e39f50c057d354486563;hpb=31e88e03ff6e24e5c744b7f3f02346221ae5bab0;p=ypp-sc-tools.db-live.git diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 0c86e6c..d423a29 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -38,6 +38,7 @@ use warnings; use DBI; use POSIX; +use JSON; use Commods; use CommodsDatabase; @@ -50,7 +51,9 @@ BEGIN { our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); - @EXPORT = qw(&dbw_connect &ocean_list $sourcebasedir); + @EXPORT = qw(&dbw_connect &ocean_list $sourcebasedir + &to_json_shim &to_json_protecttags + &set_ctype_utf8); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); @@ -100,4 +103,22 @@ sub dbw_connect ($) { return dbr_connect($datadir, $ocean); } +sub to_json_shim ($) { + my ($obj) = @_; + # In JSON.pm 2.x, jsonToObj prints a warning to stderr which + # our callers don't like at all. + if ($JSON::VERSION >= 2.0) { + return to_json($obj); + } else { + return objToJson($obj); + } +} + +sub to_json_protecttags ($) { + my ($v) = @_; + my $j= to_json_shim($v); + $j =~ s,/,\\/,g; + return $j; +} + 1;