X-Git-Url: http://git.shiar.nl/perl/plp/.git/blobdiff_plain/c8e35e0b2ab35f8af3d98fa0b69c41a73b62c714..d7eecb5ca73d043897b6e49c14845bda97ba2202:/PLP/Functions.pm?ds=sidebyside
diff --git a/PLP/Functions.pm b/PLP/Functions.pm
index 1b233c4..fa23270 100644
--- a/PLP/Functions.pm
+++ b/PLP/Functions.pm
@@ -1,11 +1,10 @@
-#-------------------------#
- package PLP::Functions;
-#-------------------------#
+package PLP::Functions;
+
use base 'Exporter';
use Fcntl qw(:flock);
use strict;
-our @EXPORT = qw/HiddenFields Entity DecodeURI EncodeURI Entity include PLP_END
+our @EXPORT = qw/Entity DecodeURI EncodeURI include PLP_END
AddCookie ReadFile WriteFile AutoURL Counter Include exit/;
sub Include ($) {
@@ -16,7 +15,7 @@ sub Include ($) {
local $@;
eval 'package PLP::Script; ' . PLP::source($PLP::file, 0, join ' ', (caller)[2,1]);
if ($@) {
- PLP::Functions::exit if $@ =~ /\cS\cT\cO\cP/;
+ PLP::Functions::exit() if $@ =~ /\cS\cT\cO\cP/;
PLP::error($@, 1);
}
}
@@ -33,16 +32,6 @@ sub PLP_END (&) {
push @PLP::END, shift;
}
-sub HiddenFields ($@) {
- my $hash = shift;
- my %saves;
- @saves{@_} = ();
- for (keys %$hash) {
- print qq{}
- unless exists $saves{$_};
- }
-}
-
sub Entity (@) {
my $ref;
my @copy;
@@ -67,9 +56,9 @@ sub Entity (@) {
return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
}
-# Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life
-# situations.
sub DecodeURI (@) {
+ # Browsers do s/ /+/ - I don't care about RFC's, but I do care about real-life
+ # situations.
my @r;
local $_;
for (@_) {
@@ -85,6 +74,7 @@ sub DecodeURI (@) {
}
return defined wantarray ? (wantarray ? @r : "@r") : undef;
}
+
sub EncodeURI (@) {
my @r;
local $_;
@@ -253,17 +243,26 @@ In void context, B the values of the given variables. In other contexts
<: print Entity($user_input); :>
+Be warned that this function also HTMLizes consecutive whitespace and newlines (using and respectively).
+For simple escaping, use L. To escape high-bit characters as well, use L.
+
=item EncodeURI LIST
-Replaces characters by their %-encoded values.
+Encodes URI strings according to RFC 3986. All disallowed characters are replaced by their %-encoded values.
In void context, B the values of the given variables. In other contexts, returns the changed versions.
Link
+Note that the following reserved characters are I percent-encoded, even though they may have a special meaning in URIs:
+
+ / ? : @ $
+
+This should be safe for escaping query values (as in the example above), but it may be a better idea to use L instead.
+
=item DecodeURI LIST
-Decodes %-encoded strings.
+Decodes %-encoded strings. Unlike L, it also translates + characters to spaces (as browsers use those).
In void context, B the values of the given variables. In other contexts, returns the changed versions.
@@ -297,7 +296,9 @@ Adds a Set-Cookie header. STRING must be a valid Set-Cookie header value.
=head1 AUTHOR
-Juerd Waalboer
+Juerd Waalboer
+
+Current maintainer: Mischa POSLAWSKY
=cut