chiark / gitweb /
Make it pass W3C validator: add DTD, work around crazy javascript escaping, etc
[ypp-sc-tools.main.git] / yarrg / CommodsWeb.pm
index 0c86e6cbfe0976b20fa6e39f50c057d354486563..46b32e6763ebb25d2b75f0f1a3a6670b63caf1a2 100644 (file)
@@ -38,6 +38,7 @@ use warnings;
 
 use DBI;
 use POSIX;
+use JSON;
 
 use Commods;
 use CommodsDatabase;
@@ -50,7 +51,8 @@ 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 to_json_protecttags);
     %EXPORT_TAGS = ( );
 
     @EXPORT_OK   = qw();
@@ -100,4 +102,11 @@ sub dbw_connect ($) {
     return dbr_connect($datadir, $ocean);
 }
 
+sub to_json_protecttags ($) {
+    my ($v) = @_;
+    my $j= to_json($v);
+    $j =~ s,/,\\/,g;
+    return $j;
+}
+
 1;