View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jonathan Swartz > Mason-Plugin-RouterSimple-0.07 > Mason::Plugin::RouterSimple



Annotate this POD

View/Report Bugs
Module Version: 0.07   Source  


Mason::Plugin::RouterSimple - Specify routes for page components


version 0.07


In a top-level component '/':

    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 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.

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 in a <%class> block. Like Router::Simple::connect, route takes a string/regex pattern and a destination hashref; the latter defaults to {} if omitted. e.g.

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

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.

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.

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 '/',


The mailing list for Mason and Mason plugins is You must be subscribed to send a message. To subscribe, visit

You can also visit us at #mason on irc://

Bugs and feature requests will be tracked at RT:

The latest source code can be browsed and fetched at:
    git clone git://


Mason, Router::Simple


Jonathan Swartz <>


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.

syntax highlighting: