-
-
30 Nov 2020 00:21:36 UTC
- Distribution: Plack
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (98)
- Testers (4633 / 10 / 0)
- Kwalitee
Bus factor: 1- 80.40% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity
24 month- Tools
- Download (185.98KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 131 contributors- Tatsuhiko Miyagawa
-
Aaron Trevena
-
Ævar Arnfjörð Bjarmason
-
Akzhan Abdulin
-
Alexandr Ciornii
-
Alex J. G. Burzyński
-
Allan Whiteford
-
Andrew Fresh
-
Andrew Rodland
-
Andy Wardley
-
Aristotle Pagaltzis
-
Arthur Axel 'fREW' Schmidt
-
Asato Wakisaka
-
Ashley Pond V
-
Ask Bjørn Hansen
-
ben hengst
-
Ben Morrow
-
Bernhard Graf
-
Chad Granum
-
chansen
-
Chia-liang Kao
-
cho45
-
Christian Walde
-
chromatic
-
Cosimo Streppone
-
Dagfinn Ilmari Mannsåker
-
Daisuke Maki
-
Daisuke Murase
-
Dave Marr
-
Dave Rolsky
-
David E. Wheeler
-
David Schmidt
-
David Steinbrunner
-
dmaestro
-
Eduardo Arino de la Rubia
-
Emmanuel Seyman
-
Eric Johnson
-
Eugen Konkov
-
Fabrice Gabolde
-
fayland
-
Flavio Poletti
-
Florian Ragwitz
-
franck cuny
-
Gianni Ceccarelli
-
Graham Knop
-
Grant McLean
-
Hans Dieter Pearcey
-
Haruka Iwao
-
Henry Baragar
-
hiratara
-
HIROSE Masaaki
-
Hiroshi Sakai
-
Ian Bradley
-
Ian Burrell
-
Jakob Voss
-
Jay Hannah
-
Jesse Luehrs
-
Jiro Nishiguchi
-
Johannes Plunien
-
John Beppu
-
John Napiorkowski
-
Jonathan Swartz
-
José Pinheiro Neta
-
Justin Davis
-
kakuno
-
Kang-min Liu
-
Karen Etheridge
-
Kazuho Oku
-
Keedi Kim
-
Lee Aylward
-
Leo Lapworth
-
mala
-
Marco Pessotto
-
Marian Schubert
-
Mark Fowler
-
Mark Stosberg
-
Masahiro Chiba
-
Masahiro Nagano
-
Michael G. Schwern
-
Michal Josef Špaček
-
mickey
-
Narsimham Chelluri
-
Nick Wellnhofer
-
Nobuo Danjou
-
Olaf Alders
-
Oliver Gorwits
-
Oliver Paukstadt
-
Oliver Trosien
-
Olivier Mengué
-
osfameron
-
Panu Ervamaa
-
Paul Driver
-
Pedro Melo
-
Perlover
-
Peter Flanigan
-
Peter Makholm
-
Piotr Roszatycki
-
punytan
-
Rafael Kitover
-
Randy Stauner
-
Ray Miller
-
Richard Simões
-
Ricky Morse
-
Robert Rothenberg
-
Rob Hoelz
-
runarb
-
Ryo Miyake
-
Sawyer X
-
Scott S. McCoy
-
Shawn M Moore
-
Shoichi Kaji
-
smcmurray
-
Stephen Clouse
-
Stevan Little
-
Stuart A Johnston
-
Takeshi OKURA
-
The Dumb Terminal
-
Thomas Klausner
-
Thomas Sibley
-
Tim Bunce
-
Tokuhiro Matsuno
-
Tomas Doran
-
Tom Heady
-
vti
-
Wallace Reis
-
xaicron
-
Yann Kerherve
-
yappo
-
Yury Zavarin
-
Yuval Kogman
-
唐鳳
- Dependencies
- Apache::LogFormat::Compiler
- Cookie::Baker
- Devel::StackTrace
- Devel::StackTrace::AsHTML
- File::ShareDir
- Filesys::Notify::Simple
- HTTP::Entity::Parser
- HTTP::Headers::Fast
- HTTP::Message
- HTTP::Tiny
- Hash::MultiValue
- Pod::Usage
- Stream::Buffered
- Test::TCP
- Try::Tiny
- URI
- WWW::Form::UrlEncoded
- parent
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Plack::App::URLMap - Map multiple apps in different paths
SYNOPSIS
use Plack::App::URLMap; my $app1 = sub { ... }; my $app2 = sub { ... }; my $app3 = sub { ... }; my $urlmap = Plack::App::URLMap->new; $urlmap->map("/" => $app1); $urlmap->map("/foo" => $app2); $urlmap->map("http://bar.example.com/" => $app3); my $app = $urlmap->to_app;
DESCRIPTION
Plack::App::URLMap 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
andPATH_INFO
(See "HOW THIS WORKS" for details). This module is inspired by Ruby's Rack::URLMap.METHODS
- map
-
$urlmap->map("/foo" => $app); $urlmap->map("http://bar.example.com/" => $another_app);
Maps URL path or an absolute URL to a PSGI application. The match order is sorted by host name length and then path length (longest strings first).
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
.Mapping URLs with host names is also possible, and in that case the URL mapping works like a virtual host.
Mappings will nest. If $app is already mapped to
/baz
it will match a request for/foo/baz
but not/foo
. See "HOW THIS WORKS" for more details. - mount
-
Alias for
map
. - to_app
-
my $handler = $urlmap->to_app;
Returns the PSGI application code reference. Note that the Plack::App::URLMap object is callable (by overloading the code dereference), so returning the object itself as a PSGI application should also work.
PERFORMANCE
If you
map
(ormount
with Plack::Builder) N applications, Plack::App::URLMap will need to at most iterate through N paths to match incoming requests.It is a good idea to use
map
only for a known, limited amount of applications, since mounting hundreds of applications could affect runtime request performance.DEBUGGING
You can set the environment variable
PLACK_URLMAP_DEBUG
to see how this application matches with the incoming request host names and paths.HOW THIS WORKS
This application works by fixing
SCRIPT_NAME
andPATH_INFO
before dispatching the incoming request to the relocated applications.Say you have a Wiki application that takes
/index
and/page/*
and makes a PSGI application$wiki_app
out of it, using one of supported web frameworks, you can put the whole application under/wiki
by:# MyWikiApp looks at PATH_INFO and handles /index and /page/* my $wiki_app = sub { MyWikiApp->run(@_) }; use Plack::App::URLMap; my $app = Plack::App::URLMap->new; $app->mount("/wiki" => $wiki_app);
When a request comes in with
PATH_INFO
set to/wiki/page/foo
, the URLMap application$app
strips the/wiki
part fromPATH_INFO
and appends that toSCRIPT_NAME
.That way, if the
$app
is mounted under the root (i.e.SCRIPT_NAME
is""
) with standalone web servers like Starman,SCRIPT_NAME
is now locally set to/wiki
andPATH_INFO
is changed to/page/foo
when$wiki_app
gets called.AUTHOR
Tatsuhiko Miyagawa
SEE ALSO
Module Install Instructions
To install Plack, copy and paste the appropriate command in to your terminal.
cpanm Plack
perl -MCPAN -e shell install Plack
For more information on module installation, please visit the detailed CPAN module installation guide.