X-Git-Url: http://git.shiar.net/gitweb.cgi/perl/plp/.git/blobdiff_plain/6b971262dcda8586066379c1b3fcea9c457ce575..b7a10718f1c1e5d0028cd367c337e9f85dc56618:/plpfields.pm diff --git a/plpfields.pm b/plpfields.pm index 2babb6e..5325d69 100644 --- a/plpfields.pm +++ b/plpfields.pm @@ -1,34 +1,49 @@ -if ($ENV{QUERY_STRING} ne ''){ - for (split /&/, $ENV{QUERY_STRING}) { - split /=/; - for (@_) { - $_ = DecodeURI($_); +#!/usr/bin/perl +# shebang only for color coding, just ignore it m'kay? +use strict; +use vars qw(%get %post %fields %cookie %INTERNAL); + +$INTERNAL{getsub} = sub { + my %get; + if ($ENV{QUERY_STRING} ne ''){ + for (split /&/, $ENV{QUERY_STRING}) { + my @keyval = split /=/; + DecodeURI(@keyval); + $get{$keyval[0]} = $keyval[1]; } - $get{$_[0]} = $_[1]; } -} + return \%get; +}; - -$INTERNAL{post} = ; -if ($INTERNAL{post} ne ''){ - for (split /&/, $INTERNAL{post}) { - split /=/; - for (@_) { - $_ = DecodeURI($_); +$INTERNAL{postsub} = sub { + my %post; + $INTERNAL{post} = ; + if (defined($INTERNAL{post}) && $INTERNAL{post} ne '' && + ($ENV{CONTENT_TYPE} eq '' || $ENV{CONTENT_TYPE} eq 'application/x-www-form-urlencoded')){ + for (split /&/, $INTERNAL{post}) { + my @keyval = split /=/; + DecodeURI(@keyval); + $post{$keyval[0]} = $keyval[1]; } - $post{$_[0]} = $_[1]; } -} -%fields=(%get, %post); + return \%post; +}; + +$INTERNAL{fieldssub} = sub { + $get{PLPdummy}, $post{PLPdummy}; # Trigger creation + return {%get, %post} +}; + +tie %get, 'PLP::Delay', 'main::get', $INTERNAL{getsub}; +tie %post, 'PLP::Delay', 'main::post', $INTERNAL{postsub}; +tie %fields, 'PLP::Delay', 'main::fields', $INTERNAL{fieldssub}; + +#%fields = (%get, %post); -$INTERNAL{koek} = $ENV{HTTP_COOKIE}; -if ($INTERNAL{koek} ne ''){ - for (split /; ?/, $INTERNAL{koek}) { - split /=/; - #for (@_) { - # $_ = DecodeURI($_); - #} - $cookie{$_[0]} ||= $_[1]; +if (defined($ENV{HTTP_COOKIE}) && $ENV{HTTP_COOKIE} ne ''){ + for (split /; ?/, $ENV{HTTP_COOKIE}) { + my @keyval = split /=/; + $cookie{$keyval[0]} ||= $keyval[1]; } }