]> mj.ucw.cz Git - libucw.git/blob - lib/perl/CGI.pm
Added first two functions of the Poor Man's CGI module.
[libucw.git] / lib / perl / CGI.pm
1 #       Poor Man's CGI Module for Perl
2 #
3 #       (c) 2002 Martin Mares <mj@ucw.cz>
4 #
5 #       This software may be freely distributed and used according to the terms
6 #       of the GNU Lesser General Public License.
7
8 package Sherlock::CGI;
9
10 use strict;
11 use warnings;
12
13 BEGIN {
14         # The somewhat hairy Perl export mechanism
15         use Exporter();
16         our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
17         $VERSION = 1.0;
18         @ISA = qw(Exporter);
19         @EXPORT = qw(&html_escape &url_escape);
20         @EXPORT_OK = qw();
21         %EXPORT_TAGS = ();
22 }
23
24 sub url_escape($) {
25         my $x = shift @_;
26         $x =~ s/([^-\$_.+!*'(),0-9A-Za-z\x80-\xff])/"%".unpack('H2',$1)/ge;
27         return $x;
28 }
29
30 sub html_escape($) {
31         my $x = shift @_;
32         $x =~ s/&/&amp;/g;
33         $x =~ s/</&lt;/g;
34         $x =~ s/>/&gt;/g;
35         $x =~ s/"/&quot;/g;
36         return $x;
37 }
38
39 1;  # OK