5 # Has only one function: doit(), which ties the hashes %get, %post, %fields
6 # and %header in PLP::Script. Also generates %cookie immediately.
11 my $get = \%PLP::Script::get;
12 if (length $ENV{QUERY_STRING}){
13 for (split /[&;]/, $ENV{QUERY_STRING}) {
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 return \%post if $ENV{CONTENT_TYPE} !~
28 m!^(?:application/x-www-form-urlencoded|$)!;
31 $post = Apache->request->content;
33 read *STDIN, $post, $ENV{CONTENT_LENGTH};
36 return \%post unless defined $post and length $post;
38 for (split /&/, $post) {
39 my @keyval = split /=/, $_, 2;
40 PLP::Functions::DecodeURI(@keyval);
41 $post{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/;
42 push @{ $post{ '@' . $keyval[0] } }, $keyval[1];
50 tie %PLP::Script::fields, 'PLP::Tie::Delay', 'PLP::Script::fields', sub {
51 return { %PLP::Script::get, %PLP::Script::post };
56 tie %PLP::Script::header, 'PLP::Tie::Headers';
60 if (defined $ENV{HTTP_COOKIE} and length $ENV{HTTP_COOKIE}) {
61 for (split /; ?/, $ENV{HTTP_COOKIE}) {
62 my @keyval = split /=/, $_, 2;
63 $PLP::Script::cookie{$keyval[0]} ||= $keyval[1];
72 PLP::Fields - Special hashes for PLP
76 For your convenience, PLP uses hashes to put things in. Some of these are tied
77 hashes, so they contain a bit magic. For example, building the hash can be
78 delayed until you actually use the hash.
82 =item C<%get> and C<%post>
84 These are built from the C<key=value&key=value> (or C<key=value;key=value>
85 strings in query string and post content. C<%post> is not built if the content
86 type is not C<application/x-www-form-urlencoded>. In post content, the
87 semi-colon is not a valid separator.
89 %post isn't built until it is used, to speed up your script if you
90 don't use it. Because POST content can only be read once, you can C<use CGI;>
91 and just never access C<%post> to avoid its building.
93 With a query string of C<key=firstvalue&key=secondvalue>, C<$get{key}> will
94 contain only C<secondvalue>. You can access both elements by using the array
95 reference C<$get{'@key'}>, which will contain C<[ 'firstvalue', 'secondvalue'
100 This hash combines %get and %post, and triggers creation of %post. POST gets
101 precedence over GET (note: not even the C<@>-keys contain both values).
103 This hash is built on first use, just like %post.
105 =item C<%cookie>, C<%cookies>
107 This is built immediately, because cookies are usually short in length. Cookies
108 are B<not> automatically url-decoded.
110 =item C<%header>, C<%headers>
112 In this hash, you can set headers. Underscores are converted to normal minus
113 signs, so you can leave out quotes. The hash is case insensitive: the case used
114 when sending the headers is the one you used first. The following are equal:
116 $header{CONTENT_TYPE}
117 $header{'Content-Type'}
118 $header{Content_Type}
119 $headers{CONTENT_type}
125 Juerd Waalboer <juerd@cpan.org>