CGI::Deurl.pm - a CGI parameter decoding package
version 1.08
use CGI::Deurl as => 'q'; ... print "$q{ParamName}\n";
This is a little module made for CGI scripting. It decodes the parameters passed to the CGI. It does nothing more, so it's much smaller and loads more quickly than CGI.pm.
Since version 0.04 it also exports the deurl
, deurlstr
and deurlarr
functions so that you are able to decode not only the parameters your
CGI got, but also an arbitrary string.
The module can take the arguments from several sources. CGI::Deurl tests the environmental variable 'REQUEST_METHOD' to find the arguments.
CGI::Deurl reads $ENV{QUERY_STRING} and parses the contents.
If you use CGI::Deurl NOTCGI;
the module doesn't look for the parameters
and just exports the functions. This is handy if you use CGI::Deurl.pm in a
script that is not a CGI.
The data are stored in a hash %CGI::Deurl::query
, but CGI::Deurl provides
two ways to specify otherwise. They may be stored either in a hash
you specify or be exported into a package.
The parameter separator is stored in variable $CGI::Deurl::ParamSeparator. You may change it any time you want.
If the argument in the query in in the form ``name=value''. $CGI::Deurl::query{name} is set to value. If it is just ``value'' (say myscript.pl?one&two), $CGI::Deurl::query{0}='one' and $CGI::Deurl::query{1}='two'. These kinds of parameters can be intermixed.
If there is more than one occurence of a variable, $CGI::Deurl::query{name} contains a refference to an array containing all the values.
Ex. ?x=one&y=two&x=three => $CGI::Deurl::query{x}=['one','three']; $CGI::Deurl::query{y}='two';
!!! If you 'export' such a variable it's not exported as a refference but as a real array!!!
That is if you use CGI::Deurl qw(export CGI::Deurl) you will get : @CGI::Deurl::x = ('one','three'); $CGI::Deurl::y = 'two';
! All changes made to $CGI::Deurl::variable are visible in $CGI::Deurl::query{variable} and vice versa.
Ex. deurl('a=5&b=13',\%query); leads to : $query{a} = 5; $query{b} = 13;
Ex. $result = deurlstr 'How+are+you%3F'; leads to: $result = 'How are you?' !!! but notice that !!! $result = deurlstr('a=5&b=13%25'); gives: $result = 'a=5&b=13%' !!!!!!
Ex. @result = deurlarr 'How&are+you%3f'; leads to @result = ( 'How', 'are you?');
@result = deurlstr('a=5&b=13%25'); gives: @result = ( 'a=5', 'b=13%'); which may but may not be what you want.
use CGI::Deurl ...;
Usefull only if you use CGI::Deurl NOTCGI;
, but later on you find out you want
the CGI parameters.
Ex.: joinquery %query, $delimiter it will join all multivalues it finds using the $delimiter.
joinquery %query, 'key' => $delimiter it will join only the multivalue for 'key'. All other values will remain the same.
joinquery %query, 'key' => ';', '-all' => ' ' it will join the multivalue for 'key' by semicolons. All other values will be joined using spaces.
You may call this function from the ``use'' statement.
Copyright (c) 1997 Jan Krynicky <Jenda@Krynicky.cz>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.