VERSION

version 0.07

SYNOPSIS

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

then \*(C`/archives/news/2010/02\*(C' outputs

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

DESCRIPTION

See Mason::Manual::RequestDispatch for background on how request paths get mapped to page components.

This plugin allows you to parse \*(C`$m->path_info\*(C' (the remainder of the top-level path) using Router::Simple routes.

It can be used whenever \*(C`$m->path_info\*(C' is set, i.e. with a dhandler or with a partial path.

Use the \*(C`route\*(C' keyword to declare routes in a <%class> block. Like Router::Simple::connect, \*(C`route\*(C' takes a string/regex pattern and a destination hashref; the latter defaults to \*(C`{}\*(C' if omitted. 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 \*(C`allow_path_info\*(C' as usual.

Any named captured arguments, including \*(C`splat\*(C', 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 '/site.mc',

  • The \s-1URL\s0 \*(C`/site/wiki/HomePage\*(C' will set \*(C`$.action = "wiki"\*(C' and \*(C`$.page = "HomePage"\*(C'.

  • The \s-1URL\s0 \*(C`/site/download/ping.mp3\*(C' will set \*(C`$.action = "download"\*(C' and \*(C`$.splat = ['ping', 'mp3']\*(C'.

  • The \s-1URL\s0 \*(C`/site/blog/2010/02\*(C' will set \*(C`$.year = "2010"\*(C' and \*(C`$.month = "02"\*(C'.

  • The URLs \*(C`/site/other\*(C' and \*(C`/site/blog/10/02\*(C' will result in a decline/404.

SUPPORT

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

You can also visit us at \*(C`#mason\*(C' on <irc://irc.perl.org/#mason>.

Bugs and feature requests will be tracked at \s-1RT:\s0

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason-Plugin-RouterSimple [email protected]

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

RELATED TO Mason::Plugin::RouterSimple…

Mason, Router::Simple

AUTHOR

Jonathan Swartz <[email protected]>

COPYRIGHT AND LICENSE

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.