Mason:...spatch(3pm)
π Mason::Manual::RequestDispatch π
okay so bestie, this is the Mason::Manual::RequestDispatch page from the User Contributed Perl Documentation (section 3pm, iykyk) β and it's literally the map of how a request path turns into a page component. buckle up π
β¨ NAME β¨
Mason::Manual::RequestDispatch β the whole ~how request paths get mapped to page components~ situation π
πΈ DESCRIPTION πΈ
okay so imagine the request path is this:
/news/sports/hockey
Mason is gonna go hunting for components in this exact order, and it sets $m->path_info like I noted next to each one:
/news/sports/hockey.{mp,mc}
/news/sports/hockey/index.{mp,mc}
/news/sports/hockey/dhandler.{mp,mc}
/news/sports/dhandler.{mp,mc} # $m->path_info = hockey
/news/sports.{mp,mc} # $m->path_info = hockey (but see next section)
/news/dhandler.{mp,mc} # $m->path_info = sports/hockey
/news.{mp,mc} # $m->path_info = sports/hockey (but see next section)
/dhandler.{mp,mc} # $m->path_info = news/sports/hockey
and where you see ".{mp,mc}", that's just shorthand meaning either ".mp" (which means a pure-perl component) or ".mc" (which means a top-level component). slay π
the sections below break all these elements down in more detail, no cap.
π¦ Autoextended path π¦
the request path gets ".mp" and ".mc" stuck on the end of it, which is how it gets translated into a component path.
/news/sports/hockey.{mp,mc}
π Index π
an index matches its exact directory β nothing underneath it, periodt.
/news/sports/hockey/index.{mp,mc}
π Dhandlers π
a dhandler matches its directory and anything underneath it too, and it sets "$m->path_info" to whatever's left over (the remainder).
/news/sports/hockey/dhandler.{mp,mc}
/news/sports/dhandler.{mp,mc} # $m->path_info = hockey
/news/dhandler.{mp,mc} # $m->path_info = sports/hockey
/dhandler.{mp,mc} # $m->path_info = news/sports/hockey
π§ Partial paths π§
a component can match just an initial part of the URL, setting "$m->path_info" to the remainder:
/news/sports.{mp,mc} # $m->path_info = hockey
/news.{mp,mc} # $m->path_info = sports/hockey
but lowkey, since this isn't always the behavior you want, it has to be explicitly enabled for the component. Mason will call the method "allow_path_info" on the component class, and it'll only allow the match if that method returns true:
<%class>
method allow_path_info { 1 }
</%class>
the default "allow_path_info" returns false. π«Ά
also important: "allow_path_info" is not checked on dhandlers, because honestly the entire point of a dhandler is to match partial paths. it's giving main character energy.
π Trailing slash π
if the request URL has a trailing slash (like, it ends with "/"), Mason removes it before the match process even starts, and adds it onto the "$m->path_info". any component that should match in that case has to have "allow_path_info" return true.
for example:
## request URL /news/
/news/index.{mp,mc} # $m->path_info = / if index.{mp,mc} has
# allow_path_info => true
/news/dhandler.{mp,mc} # $m->path_info = /
/news.{mp,mc} # $m->path_info = / if news.{mp,mc} has
# allow_path_info => true
## request URL /news/sports/
/news/sports/index.{mp,mc} # $m->path_info = / if index.{mp,mc} has
# allow_path_info => true
/news/sports/dhandler.{mp,mc} # $m->path_info = /
/news/sports.{mp,mc} # $m->path_info = / if sports.{mp,mc}
# has allow_path_info => true
/news/dhandler.{mp,mc} # $m->path_info = sports/
/news.{mp,mc} # $m->path_info = /sports/ if news.{mp,mc}
# has allow_path_info => true
β Routes β
you can use route syntax to more elegantly parse "$m->path_info" for dhandlers and partial paths, like:
<%class>
route "{year:[0-9]+}/{month:[0-9]{2}}";
</%class>
see Mason::Plugin::RouterSimple β she's iconic. π
π SEE ALSO π
Mason
π AUTHOR π
Jonathan Swartz <swartz@pobox.com>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2012 by Jonathan Swartz.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt π
and that's the whole page bestie!! π«Ά this was Mason:...spatch(3pm) β yes that's the truncated little header name, it's really Mason::Manual::RequestDispatch β generated with perl v5.34.0 on 2022-05-27. go forth and route, you're doing amazing πΈβ¨π
π¦ where this page comes from
- debian bookworm: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmason-perl 2.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms