#package BrockCGI; #require 5.004; # BrockCGI.pm # A collection CGI routines. Well, one. # Read all CGI vars into a hash. It goes # Key->list of values. Even if there is only one # it makes it a list. This might be a bit annoying # to some people but I like it. I may add more # support routines. # Someone else wrote a good portion of this routine, # but seeing as how I don't know who they are, I # can't give them credit. Sorry. sub get_data { local($fdata, %fdata) ; local($name, $value) ; # First, read entire string of CGI vars into $fdata if (($ENV{'REQUEST_METHOD'} eq 'GET') || ($ENV{'REQUEST_METHOD'} eq 'HEAD')) { $fdata= $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { print "I got a POST!"; if ($ENV{'CONTENT_TYPE'}=~ m#^application/x-www-form-urlencoded$#i) { length($ENV{'CONTENT_LENGTH'}) || &HTMLdie("No Content-Length sent with the POST request."); read(STDIN, $fdata, $ENV{'CONTENT_LENGTH'}); } else { &HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}"); } } else { &HTMLdie("Script was called with unsupported REQUEST_METHOD."); } # Resolve and unencode name/value pairs into %fdata foreach (split('&', $fdata)) { s/\+/ /g; ($name, $value)= split('=', $_, 2); $name=~ s/%(..)/chr(hex($1))/ge; $value=~ s/%A0//ge; $value=~ s/%(..)/chr(hex($1))/ge; push (@{$fdata{$name}},$value); } return %fdata ; } # Die, outputting HTML error page # If no $title, use a default title sub HTMLdie { local($msg,$title)= @_ ; $title || ($title= "CGI Error") ; print < $title

$title

$msg

EOF exit; } 1; #To make people happy? I guess. # END OF BrockCGI.pm