Mason::Plugin::RouterSimple - Specify routes for page components
version 0.02
In a top-level component '/archives.m':
%% route ":section/{year:[0-9]{4}}/{month:[0-9]{2}}"; Archives for <b><% $.section %></b> For the month of <% $.month %>/<% $.year %>
then /archives/news/2010/02 outputs
/archives/news/2010/02
Archives for <b>news</b> For the month of 2010/02
See Mason::Manual::RequestDispatch for background on how request paths get mapped to page components.
This plugin allows you to parse $m->path_info (the remainder of the top-level path) using Router::Simple routes.
$m->path_info
It can be used whenever $m->path_info is set, i.e. with a dhandler or with a partial path.
Use the route keyword to declare routes, either in a <%class> block or on a %%-line. Like Router::Simple::connect, route takes a string/regex pattern and a destination hashref; the latter defaults to {} if omitted. e.g.
route
{}
%% route "wiki/:page", { action => "wiki" }; <%class> 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.
allow_path_info
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.
splat
If you specify more than one route in a component, they will be tried in turn, with the first matching route taking precedence.
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.m',
The URL /site/wiki/HomePage will set $.action = "wiki" and $.page = "HomePage".
/site/wiki/HomePage
$.action = "wiki"
$.page = "HomePage"
The URL /site/download/ping.mp3 will set $.action = "download" and $.splat = ['ping', 'mp3'].
/site/download/ping.mp3
$.action = "download"
$.splat = ['ping', 'mp3']
The URL /site/blog/2010/02 will set $.year = "2010" and $.month = "02".
/site/blog/2010/02
$.year = "2010"
$.month = "02"
The URLs /site/other and /site/blog/10/02 will result in a decline/404.
/site/other
/site/blog/10/02
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.
#mason
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
Mason, Router::Simple
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.
To install Mason::Plugin::RouterSimple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mason::Plugin::RouterSimple
CPAN shell
perl -MCPAN -e shell install Mason::Plugin::RouterSimple
For more information on module installation, please visit the detailed CPAN module installation guide.