1 #----------------------#
3 #----------------------#
6 # Has only one function: doit(), which ties the hashes %get, %post, %fields and %header in
7 # PLP::Script. Also generates %cookie immediately.
9 tie %PLP::Script::get, 'PLP::Tie::Delay', 'PLP::Script::get', sub {
11 my $get = $ENV{QUERY_STRING};
13 for (split /[&;]/, $get) {
14 my @keyval = split /=/, $_, 2;
15 PLP::Functions::DecodeURI(@keyval);
16 $get{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/;
17 push @{ $get{'@' . $keyval[0]} }, $keyval[1];
23 tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub {
27 $post = Apache->request->content;
29 read(*STDIN, $post, $ENV{CONTENT_LENGTH});
33 and $ENV{CONTENT_TYPE} =~ m!^(?:application/x-www-form-urlencoded|$)!
35 for (split /&/, $post) {
36 my @keyval = split /=/, $_, 2;
37 PLP::Functions::DecodeURI(@keyval);
38 $post{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/;
39 push @{ $post{'@' . $keyval[0]} }, $keyval[1];
45 tie %PLP::Script::fields, 'PLP::Tie::Delay', 'PLP::Script::fields', sub {
46 # $PLP::Script::get{PLPdummy}, $PLP::Script::post{PLPdummy}; # Trigger creation
47 # No longer necessary, as PLP::Tie::Delay has been fixed since 3.00
48 # And fixed even more in 3.13
49 return { %PLP::Script::get, %PLP::Script::post };
52 tie %PLP::Script::header, 'PLP::Tie::Headers';
54 if (defined($ENV{HTTP_COOKIE}) && $ENV{HTTP_COOKIE} ne ''){
55 for (split /; ?/, $ENV{HTTP_COOKIE}) {
56 my @keyval = split /=/, $_, 2;
57 $PLP::Script::cookie{$keyval[0]} ||= $keyval[1];
66 PLP::Fields - Special hashes for PLP
70 For your convenience, PLP uses hashes to put things in. Some of these are tied
71 hashes, so they contain a bit magic. For example, building the hash can be
72 delayed until you actually use the hash.
76 =item C<%get> and C<%post>
78 These are built from the C<key=value&key=value> (or C<key=value;key=value>
79 strings in query string and post content. C<%post> is not built if the content
80 type is not C<application/x-www-form-urlencoded>. In post content, the
81 semi-colon is not a valid separator.
83 These hashes aren't built until they are used, to speed up your script if you
84 don't use them. Because POST content can only be read once, you can C<use CGI;>
85 and just never access C<%post> to avoid its building.
87 With a query string of C<key=firstvalue&key=secondvalue>, C<$get{key}> will
88 contain only C<secondvalue>. You can access both elements by using the array
89 reference C<$get{'@key'}>, which will contain C<[ 'firstvalue', 'secondvalue'
94 This hash combines %get and %post, and triggers creation of both. POST gets
95 precedence over GET (note: not even the C<@>-keys contain both values).
97 =item C<%cookie>, C<%cookies>
99 This is built immediately, because cookies are usually short in length. Cookies
100 are not automatically url-decoded.
102 =item C<%header>, C<%headers>
104 In this hash, you can set headers. Underscores are converted to normal minus
105 signs, so you can leave out quotes. The hash is case insensitive: the case used
106 when sending the headers is the one you used first. The following are equal:
108 $header{CONTENT_TYPE}
109 $header{'Content-Type'}
110 $header{Content_Type}
111 $headers{CONTENT_type}
117 Juerd Waalboer <juerd@juerd.nl>