6 # Has only one function: doit(), which ties the hashes %get, %post, %fields
7 # and %header in PLP::Script. Also generates %cookie immediately.
12 my $get = \%PLP::Script::get;
13 if (length $ENV{QUERY_STRING}){
14 for (split /[&;]/, $ENV{QUERY_STRING}) {
15 my @keyval = split /=/, $_, 2;
16 PLP::Functions::DecodeURI(@keyval);
17 $get->{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/;
18 push @{ $get->{ '@' . $keyval[0] } }, $keyval[1];
24 tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub {
28 return \%post if $ENV{CONTENT_TYPE} !~
29 m!^(?:application/x-www-form-urlencoded|$)!;
31 $post = $PLP::read->($ENV{CONTENT_LENGTH}) if $ENV{CONTENT_LENGTH};
33 return \%post unless defined $post and length $post;
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];
47 tie %PLP::Script::fields, 'PLP::Tie::Delay', 'PLP::Script::fields', sub {
48 return { %PLP::Script::get, %PLP::Script::post };
53 tie %PLP::Script::header, 'PLP::Tie::Headers';
57 if (defined $ENV{HTTP_COOKIE} and length $ENV{HTTP_COOKIE}) {
58 for (split /; ?/, $ENV{HTTP_COOKIE}) {
59 my @keyval = split /=/, $_, 2;
60 $PLP::Script::cookie{$keyval[0]} ||= $keyval[1];
69 PLP::Fields - Special hashes for PLP
73 For your convenience, PLP uses hashes to put things in. Some of these are tied
74 hashes, so they contain a bit magic. For example, building the hash can be
75 delayed until you actually use the hash.
79 =item C<%get> and C<%post>
81 These are built from the C<key=value&key=value> (or C<key=value;key=value>
82 strings in query string and post content. C<%post> is not built if the content
83 type is not C<application/x-www-form-urlencoded>. In post content, the
84 semi-colon is not a valid separator.
86 %post isn't built until it is used, to speed up your script if you
87 don't use it. Because POST content can only be read once, you can C<use CGI;>
88 and just never access C<%post> to avoid its building.
90 With a query string of C<key=firstvalue&key=secondvalue>, C<$get{key}> will
91 contain only C<secondvalue>. You can access both elements by using the array
92 reference C<$get{'@key'}>, which will contain C<[ 'firstvalue', 'secondvalue'
97 This hash combines %get and %post, and triggers creation of %post. POST gets
98 precedence over GET (note: not even the C<@>-keys contain both values).
100 This hash is built on first use, just like %post.
102 =item C<%cookie>, C<%cookies>
104 This is built immediately, because cookies are usually short in length. Cookies
105 are B<not> automatically url-decoded.
107 =item C<%header>, C<%headers>
109 In this hash, you can set headers. Underscores are converted to normal minus
110 signs, so you can leave out quotes. The hash is case insensitive: the case used
111 when sending the headers is the one you used first. The following are equal:
113 $header{CONTENT_TYPE}
114 $header{'Content-Type'}
115 $header{Content_Type}
116 $headers{CONTENT_type}
122 Juerd Waalboer <juerd@cpan.org>
124 Current maintainer: Mischa POSLAWSKY <shiar@cpan.org>