]> mj.ucw.cz Git - libucw.git/commitdiff
Added first two functions of the Poor Man's CGI module.
authorMartin Mares <mj@ucw.cz>
Fri, 6 Sep 2002 17:00:13 +0000 (17:00 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 6 Sep 2002 17:00:13 +0000 (17:00 +0000)
lib/perl/CGI.pm [new file with mode: 0644]
lib/perl/Makefile

diff --git a/lib/perl/CGI.pm b/lib/perl/CGI.pm
new file mode 100644 (file)
index 0000000..255859e
--- /dev/null
@@ -0,0 +1,39 @@
+#      Poor Man's CGI Module for Perl
+#
+#      (c) 2002 Martin Mares <mj@ucw.cz>
+#
+#      This software may be freely distributed and used according to the terms
+#      of the GNU Lesser General Public License.
+
+package Sherlock::CGI;
+
+use strict;
+use warnings;
+
+BEGIN {
+       # The somewhat hairy Perl export mechanism
+       use Exporter();
+       our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+       $VERSION = 1.0;
+       @ISA = qw(Exporter);
+       @EXPORT = qw(&html_escape &url_escape);
+       @EXPORT_OK = qw();
+       %EXPORT_TAGS = ();
+}
+
+sub url_escape($) {
+       my $x = shift @_;
+       $x =~ s/([^-\$_.+!*'(),0-9A-Za-z\x80-\xff])/"%".unpack('H2',$1)/ge;
+       return $x;
+}
+
+sub html_escape($) {
+       my $x = shift @_;
+       $x =~ s/&/&amp;/g;
+       $x =~ s/</&lt;/g;
+       $x =~ s/>/&gt;/g;
+       $x =~ s/"/&quot;/g;
+       return $x;
+}
+
+1;  # OK
index f0bddeebe97e6e8a3a4c0631e2afd11aa2d0e67a..3b9e9257d763418c55db4eb35f5094c62f2f7fea 100644 (file)
@@ -1,4 +1,4 @@
 # Perl modules
 
 DIRS+=lib/perl
-PROGS+=$(addprefix obj/lib/perl/,Config.pm Query.pm)
+PROGS+=$(addprefix obj/lib/perl/,Config.pm Query.pm CGI.pm)