8 # Has only one function: doit(), which ties the hashes %get, %post, %fields
9 # and %header in PLP::Script. Also generates %cookie immediately.
14 my $get = \%PLP::Script::get;
15 if (length $ENV{QUERY_STRING}){
16 for (split /[&;]/, $ENV{QUERY_STRING}) {
17 my @keyval = split /=/, $_, 2;
18 PLP::Functions::DecodeURI(@keyval);
19 $get->{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/;
20 push @{ $get->{ '@' . $keyval[0] } }, $keyval[1];
26 tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub {
30 return \%post if $ENV{CONTENT_TYPE} !~
31 m!^(?:application/x-www-form-urlencoded|$)!;
33 $post = $PLP::read->($ENV{CONTENT_LENGTH}) if $ENV{CONTENT_LENGTH};
35 return \%post unless defined $post and length $post;
37 for (split /&/, $post) {
38 my @keyval = split /=/, $_, 2;
39 PLP::Functions::DecodeURI(@keyval);
40 $post{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/;
41 push @{ $post{ '@' . $keyval[0] } }, $keyval[1];
49 tie %PLP::Script::fields, 'PLP::Tie::Delay', 'PLP::Script::fields', sub {
50 return { %PLP::Script::get, %PLP::Script::post };
55 tie %PLP::Script::header, 'PLP::Tie::Headers';
59 if (defined $ENV{HTTP_COOKIE} and length $ENV{HTTP_COOKIE}) {
60 for (split /; ?/, $ENV{HTTP_COOKIE}) {
61 my @keyval = split /=/, $_, 2;
62 $PLP::Script::cookie{$keyval[0]} ||= $keyval[1];
71 PLP::Fields - Special hashes for PLP
75 For your convenience, PLP uses hashes to put things in. Some of these are tied
76 hashes, so they contain a bit magic. For example, building the hash can be
77 delayed until you actually use the hash.
81 =item C<%get> and C<%post>
83 These are built from the C<key=value&key=value> (or C<key=value;key=value>
84 strings in query string and post content. C<%post> is not built if the content
85 type is not C<application/x-www-form-urlencoded>. In post content, the
86 semi-colon is not a valid separator.
88 %post isn't built until it is used, to speed up your script if you
89 don't use it. Because POST content can only be read once, you can C<use CGI;>
90 and just never access C<%post> to avoid its building.
92 With a query string of C<key=firstvalue&key=secondvalue>, C<$get{key}> will
93 contain only C<secondvalue>. You can access both elements by using the array
94 reference C<$get{'@key'}>, which will contain C<[ 'firstvalue', 'secondvalue'
99 This hash combines %get and %post, and triggers creation of %post. POST gets
100 precedence over GET (note: not even the C<@>-keys contain both values).
102 This hash is built on first use, just like %post.
104 =item C<%cookie>, C<%cookies>
106 This is built immediately, because cookies are usually short in length. Cookies
107 are B<not> automatically url-decoded.
109 =item C<%header>, C<%headers>
111 In this hash, you can set headers. Underscores are converted to normal minus
112 signs, so you can leave out quotes. The hash is case insensitive: the case used
113 when sending the headers is the one you used first. The following are equal:
115 $header{CONTENT_TYPE}
116 $header{'Content-Type'}
117 $header{Content_Type}
118 $headers{CONTENT_type}
120 If a value contains newlines, the header is repeated for each line:
122 $header{Allow} = "HEAD\nGET"; # equivalent to HEAD,GET
128 Juerd Waalboer <juerd@cpan.org>
130 Current maintainer: Mischa POSLAWSKY <shiar@cpan.org>