Apache::URI2param - PerlInitHandler to use with CGI::URI2param
in your httpd.conf
<Location /somewhere> PerlInitHandler Apache::URI2param PerlAddVar URI2param_regex "sort sort_(\w+)" PerlAddVar URI2param_regex "style style_(fancy|plain)" PerlAddVar URI2param_regex "id news(\d+)" </Location> <Location /somewhere/else> PerlAddVar URI2param_regex "id article(\d+)" </Location>
Apache::URI2param is a small PerlInitHandler to wrap around CGI::URI2param so you don't have to call CGI::URI2param::uri2param from your mod_perl scripts/apps.
As an added bonus, it uses PerlAddVar to set the regexes, so you can let Apache figure out what regexes to apply to what URIs via the Apache Configuration File.
You should start your own handlers with: sub handler { my $r=Apache::Request->instance(shift); ...
i.e., use the new feature of Apache::request, instance to use a singelton Apache Request object
instance
After installing Apache::URI2param as a PerlInitHandler, you can pass regexes that should be applied to the URI via PerlAddVar. The format is:
PerlAddVar URI2param_regex "PARAM REGEX"
where PARAM is the name of the parameter to be set, and REGEX is a regular expression containing capturing parenthenses.
You should use PerlAddVar instead of PerlSetVar, because Apache will then figure out for you what regexes to apply for an given URI.
If you look at the example given in SYNOPSIS, if you'd request the URI /somewhere/else/style_fancy/article123.html you would get the following parameters:
/somewhere/else/style_fancy/article123.html
print $r->param('style') # fancy print $r->param('id') # 123 print $r->param('sort') # undef
As you can see here, you can use the "style" regex defined for /somewhere, but the "id" definition in /somewhere/else overrides the one in /somewhere.
/somewhere
/somewhere/else
This routine gets called as a PerlInitHandler very early in the Apache Request Cycle. Thus you can access the generated params in nearly all other phases.
handler basically just generates a hash of param names and regexes and passes the hash to CGI::URI2param::uri2param for processing there.
handler
Apache::URI2param gets installed along with CGI::URI2param
None so far.
Apache::Request (0.33)
CGI::URI2param
Thomas Klausner, domm@zsi.at, http://domm.zsi.at
Thanks Darren Chamberlain <dlc@users.sourceforge.net> for the idea to write a mod_perl handler for CGI::URI2param
Apache::URI2param is Copyright (c) 2002 Thomas Klausner, ZSI. All rights reserved.
You may use and distribute this module according to the same terms that Perl is distributed under
To install CGI::URI2param, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::URI2param
CPAN shell
perl -MCPAN -e shell install CGI::URI2param
For more information on module installation, please visit the detailed CPAN module installation guide.