RFC 3875 The Common Gateway Interface (CGI) Version 1.1 4.1.5. PATH_INFO The PATH_INFO variable specifies a path to be interpreted by the CGI script. It identifies the resource or sub-resource to be returned by the CGI script, and is derived from the portion of the URI path hierarchy following the part that identifies the script itself. Unlike a URI path, the PATH_INFO is not URL-encoded, and cannot contain path-segment parameters. A PATH_INFO of "/" represents a single void path segment. PATH_INFO = "" | ( "/" path ) 4.1.13. SCRIPT_NAME The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded) which could identify the CGI script (rather than the script's output). The syntax is the same as for PATH_INFO (section 4.1.5) SCRIPT_NAME = "" | ( "/" path ) The leading "/" is not part of the path. It is optional if the path is NULL; however, the variable MUST still be set in that case. The SCRIPT_NAME string forms some leading part of the path component of the Script-URI derived in some implementation-defined manner. No PATH_INFO segment (see section 4.1.5) is included in the SCRIPT_NAME value.
Plack::App::URLMux - Map multiple applications in defferent url path.
use Plack::App::URLMux; my $app1 = sub { ... }; my $app2 = sub { ... }; my $app3 = sub { ... }; my $urlmap = Plack::App::URLMux->new; $urlmap->map("/" => $app1, foo => bar); $urlmap->map("/foo/:name/bar" => $app2); $urlmap->map("/foo/test/bar" => $app3); $urlmap->map("http://bar.example.com/" => $app4); $urlmap->map("/foo/:bar*/baz" => $app2); my $app = $urlmap->to_app;
Plack::App::URLMux is a PSGI application that can dispatch multiple applications based on URL path and host names (a.k.a "virtual hosting") and takes care of rewriting SCRIPT_NAME and PATH_INFO (See "HOW THIS WORKS" for details). This module is based on Plack::App::URLMap module but optimizied to handle a lot of urls and has additional rules for parameterized URL and add additional parameteres provided to application at mapping URL.
SCRIPT_NAME
PATH_INFO
Mapping rules for url with parameters /foo/:name/bar will mapped to any URL wich contains /foo/some/bar and call $app2 with additional parameters at environmentas name => 'some'. But if you mount /for/test/bar the same time, then for this URL /for/test/bar mapping will be exactly to $app3 to this URL without parameter and other URLs contain anything between /foo/ and /bar will be mapped to $app2 with parameter 'name'.
Format for parameters :name, parameter names may be repeated, mapper returned values as array of pairs name=>value in order as they meet in URL.
On call mapper provide next environment in request:
Array of pairs key=>value specified when mount app
-item plack.urlmux.params.url
Array of pairs name=>value extracted from url path by url format specified when mount app
$urlmap->map("/foo" => $app); $urlmap->map("http://bar.example.com/" => $another_app); $urlmap->map("/foo/:name/bar" => $app2);
Maps URL an absolute URL to a PSGI application. Module splits url path by '/' delimeter and add it into builded search tree structure.
URL paths need to match from the beginning and should match completely until the path separator (or the end of the path). For example, if you register the path /foo, it will match with the request /foo, /foo/ or /foo/bar but it won't match with /foox.
/foo
/foo/
/foo/bar
/foox
Mapping URLs with host names is also possible, and in that case the URL mapping works like a virtual host.
Alias for map.
map
my $handler = $urlmap->to_app;
Returns the PSGI application code reference.
No restriction on number of urls, of course perl has trouble to store 1M records, it takes a lot of memory. Mounting hundreds of applications cause a small affect on runtime request performance. Algorithm complexity is near logN.
Aleksey Ozhigov
Plack::App::URLMap
1 POD Error
The following errors were encountered while parsing the POD:
=pod directives shouldn't be over one line long! Ignoring all 14 lines of content
To install Plack::App::URLMux, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::App::URLMux
CPAN shell
perl -MCPAN -e shell install Plack::App::URLMux
For more information on module installation, please visit the detailed CPAN module installation guide.