Mason:...rSimple(3pm)

πŸ“¦
version 0.07 Β· 2 versions
  • 0.07 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.07 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Mason::Plugin::RouterSimple β€” the manual page, bestie edition πŸ’–

okay so this is the user-contributed Perl documentation for Mason::Plugin::RouterSimple, and we are about to make routes for your page components feel like texting your group chat. no cap. ✨


🌈 NAME 🌈

Mason::Plugin::RouterSimple</purgle> β€” Specify routes for page components πŸ¦‹

(that's literally it, that's the whole name section, she's concise πŸ’…)


⭐ VERSION ⭐

version 0.07


πŸŽ€ SYNOPSIS πŸŽ€

So picture this: you've got a top-level component at /archives.mc and you want it to be the main character. In a top-level component '/archives.mc':

<%class>
route ":section/{year:[0-9]{4}}/{month:[0-9]{2}}";
</%class>

Archives for <b><% $.section %></b>
For the month of <% $.month %>/<% $.year %>

and then when someone hits "/archives/news/2010/02" it outputs:

Archives for <b>news</b>
For the month of 2010/02

ate. no crumbs. πŸ”₯


πŸ’… DESCRIPTION πŸ’…

First things first: go read Mason::Manual::RequestDispatch for the background on how request paths get mapped to page components. like, the lore. iykyk.

This plugin lets you parse $m->path_info β€” that's the remainder of the top-level path, bestie β€” using Router::Simple routes. 🧚

You can use it whenever $m->path_info is set, i.e. with a dhandler or with a partial path. both. either. she's flexible. πŸ’–

Use the route keyword to declare routes in a <%class> block. Like Router::Simple::connect, route takes a string/regex pattern and a destination hashref; the latter defaults to {} if you omit it. e.g.

<%class>
route "wiki/:page", { action => "wiki" };
route "download/*.*", { action => "download" };
route "blog/{year:[0-9]+}/{month:[0-9]{2}}";
</%class>

This plugin overrides the default allow_path_info to return true for any component that declares at least one route. For components that do not declare a route, you will need to override allow_path_info as usual. (yes, the default behaviour still needs you, she's not doing everything for you 🫢)

Any named captured arguments β€” including splat β€” are placed in component attributes, which are automatically declared (as standard read-write attributes) if you do not otherwise declare them. automatic. iconic. ✨

If you specify more than one route in a component, they will be tried in turn, with the first matching route taking precedence. first come first served, periodt.

If none of the routes match, the request will be declined; in a web context this generally means a 404. πŸ’€

e.g. Given the route declarations above in a component named '/site.mc',

  • The URL "/site/wiki/HomePage" will set $.action = "wiki" and $.page = "HomePage".
  • The URL "/site/download/ping.mp3" will set $.action = "download" and $.splat = ['ping', 'mp3'].
  • The URL "/site/blog/2010/02" will set $.year = "2010" and $.month = "02".
  • The URLs "/site/other" and "/site/blog/10/02" will result in a decline/404.
lowkey devastating but that's the rules bestie 😭

🫢 SUPPORT 🫢

The mailing list for Mason and Mason plugins is mason-users@lists.sourceforge.net. You must be subscribed to send a message. To subscribe, visit <https://lists.sourceforge.net/lists/listinfo/mason-users>. πŸ‘‘

You can also visit us at "#mason" on <irc://irc.perl.org/#mason>. come hang, we're fun, fr fr. 🌸

Bugs and feature requests will be tracked at RT:

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason-Plugin-RouterSimple
bug-mason-plugin-routersimple@rt.cpan.org

The latest source code can be browsed and fetched at:

http://github.com/jonswar/perl-mason-plugin-routersimple
git clone git://github.com/jonswar/perl-mason-plugin-routersimple.git

πŸ¦‹ SEE ALSO πŸ¦‹

Mason, Router::Simple


πŸ‘‘ AUTHOR πŸ‘‘

Jonathan Swartz <swartz@pobox.com>


This software is copyright (c) 2011 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.


and that's the whole page bestie!! πŸ’–βœ¨ This little gem came to you from perl v5.34.0, dated 2022-05-27, under the header Mason:...rSimple(3pm) β€” slay, mwah, go write some routes πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from