X-Git-Url: http://git.shiar.nl/perl/plp/.git/blobdiff_plain/0daff7b8f9f15f54cfd2af57e4c8f868db199dda..4565100c67dd7b0344e9eb332296d5fa64e7611b:/PLP/Fields.pm diff --git a/PLP/Fields.pm b/PLP/Fields.pm index 3dda7d3..7f07c4e 100644 --- a/PLP/Fields.pm +++ b/PLP/Fields.pm @@ -6,63 +6,59 @@ use strict; # and %header in PLP::Script. Also generates %cookie immediately. sub doit { - # %get - - my $get = \%PLP::Script::get; - if (length $ENV{QUERY_STRING}){ - for (split /[&;]/, $ENV{QUERY_STRING}) { - my @keyval = split /=/, $_, 2; - PLP::Functions::DecodeURI(@keyval); - $get->{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/; - push @{ $get->{ '@' . $keyval[0] } }, $keyval[1]; - } - } - - # %post - - tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub { - my %post; - my $post; - - return \%post if $ENV{CONTENT_TYPE} !~ - m!^(?:application/x-www-form-urlencoded|$)!; - - if ($ENV{MOD_PERL}) { - $post = Apache->request->content; - } else { - read *STDIN, $post, $ENV{CONTENT_LENGTH}; - } - - return \%post unless defined $post and length $post; + # %get - for (split /&/, $post) { - my @keyval = split /=/, $_, 2; - PLP::Functions::DecodeURI(@keyval); - $post{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/; - push @{ $post{ '@' . $keyval[0] } }, $keyval[1]; + my $get = \%PLP::Script::get; + if (length $ENV{QUERY_STRING}){ + for (split /[&;]/, $ENV{QUERY_STRING}) { + my @keyval = split /=/, $_, 2; + PLP::Functions::DecodeURI(@keyval); + $get->{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/; + push @{ $get->{ '@' . $keyval[0] } }, $keyval[1]; + } } - - return \%post; - }; - - # %fields - - tie %PLP::Script::fields, 'PLP::Tie::Delay', 'PLP::Script::fields', sub { - return { %PLP::Script::get, %PLP::Script::post }; - }; - - # %header - - tie %PLP::Script::header, 'PLP::Tie::Headers'; - - # %cookie - if (defined $ENV{HTTP_COOKIE} and length $ENV{HTTP_COOKIE}) { - for (split /; ?/, $ENV{HTTP_COOKIE}) { - my @keyval = split /=/, $_, 2; - $PLP::Script::cookie{$keyval[0]} ||= $keyval[1]; + # %post + + tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub { + my %post; + my $post; + + return \%post if $ENV{CONTENT_TYPE} !~ + m!^(?:application/x-www-form-urlencoded|$)!; + + $post = $PLP::read->($ENV{CONTENT_LENGTH}) if $ENV{CONTENT_LENGTH}; + + return \%post unless defined $post and length $post; + + for (split /&/, $post) { + my @keyval = split /=/, $_, 2; + PLP::Functions::DecodeURI(@keyval); + $post{$keyval[0]} = $keyval[1] unless $keyval[0] =~ /^\@/; + push @{ $post{ '@' . $keyval[0] } }, $keyval[1]; + } + + return \%post; + }; + + # %fields + + tie %PLP::Script::fields, 'PLP::Tie::Delay', 'PLP::Script::fields', sub { + return { %PLP::Script::get, %PLP::Script::post }; + }; + + # %header + + tie %PLP::Script::header, 'PLP::Tie::Headers'; + + # %cookie + + if (defined $ENV{HTTP_COOKIE} and length $ENV{HTTP_COOKIE}) { + for (split /; ?/, $ENV{HTTP_COOKIE}) { + my @keyval = split /=/, $_, 2; + $PLP::Script::cookie{$keyval[0]} ||= $keyval[1]; + } } - } } 1;