File Coverage

blib/lib/Mason/Plugin/RouterSimple.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1             package Mason::Plugin::RouterSimple;
2             BEGIN {
3 1     1   582 $Mason::Plugin::RouterSimple::VERSION = '0.07';
4             }
5 1     1   274 use Moose;
  0            
  0            
6             with 'Mason::Plugin';
7              
8             __PACKAGE__->meta->make_immutable();
9              
10             1;
11              
12              
13              
14             =pod
15              
16             =head1 NAME
17              
18             Mason::Plugin::RouterSimple - Specify routes for page components
19              
20             =head1 VERSION
21              
22             version 0.07
23              
24             =head1 SYNOPSIS
25              
26             In a top-level component '/archives.mc':
27              
28             <%class>
29             route ":section/{year:[0-9]{4}}/{month:[0-9]{2}}";
30             </%class>
31              
32             Archives for <b><% $.section %></b>
33             For the month of <% $.month %>/<% $.year %>
34              
35             then C</archives/news/2010/02> outputs
36              
37             Archives for <b>news</b>
38             For the month of 2010/02
39              
40             =head1 DESCRIPTION
41              
42             See L<Mason::Manual::RequestDispatch> for background on how request paths get
43             mapped to page components.
44              
45             This plugin allows you to parse C<< $m->path_info >> (the remainder of the
46             top-level path) using L<Router::Simple> routes.
47              
48             It can be used whenever C<< $m->path_info >> is set, i.e. with a
49             L<dhandler|Mason::Manual::RequestDispatch/Dhandlers> or with a L<partial
50             path|Mason::Manual::RequestDispatch/Partial paths>.
51              
52             Use the C<route> keyword to declare routes in a
53             L<E<lt>%classE<gt>|Mason::Manual::Syntax/E<lt>%classE<gt>> block. Like
54             L<Router::Simple::connect|Router::Simple/METHODS>, C<route> takes a
55             string/regex pattern and a destination hashref; the latter defaults to C<{}> if
56             omitted. e.g.
57              
58             <%class>
59             route "wiki/:page", { action => "wiki" };
60             route "download/*.*", { action => "download" };
61             route "blog/{year:[0-9]+}/{month:[0-9]{2}}";
62             </%class>
63              
64             This plugin overrides the default
65             L<allow_path_info|Mason::Manual::RequestDispatch/Partial paths> to return true
66             for any component that declares at least one route. For components that do not
67             declare a route, you will need to override C<allow_path_info> as usual.
68              
69             Any named captured arguments, including C<splat>, are placed in component
70             attributes, which are automatically declared (as standard read-write
71             attributes) if you do not otherwise declare them.
72              
73             If you specify more than one route in a component, they will be tried in turn,
74             with the first matching route taking precedence.
75              
76             If none of the routes match, the request will be
77             L<declined|Mason::Request/decline>; in a web context this generally means a
78             404.
79              
80             e.g. Given the route declarations above in a component named '/site.mc',
81              
82             =over
83              
84             =item *
85              
86             The URL C</site/wiki/HomePage> will set C<$.action = "wiki"> and C<$.page =
87             "HomePage">.
88              
89             =item *
90              
91             The URL C</site/download/ping.mp3> will set C<$.action = "download"> and
92             C<$.splat = ['ping', 'mp3']>.
93              
94             =item *
95              
96             The URL C</site/blog/2010/02> will set C<$.year = "2010"> and C<$.month =
97             "02">.
98              
99             =item *
100              
101             The URLs C</site/other> and C</site/blog/10/02> will result in a decline/404.
102              
103             =back
104              
105             =head1 SUPPORT
106              
107             The mailing list for Mason and Mason plugins is
108             L<mason-users@lists.sourceforge.net>. You must be subscribed to send a message.
109             To subscribe, visit
110             L<https://lists.sourceforge.net/lists/listinfo/mason-users>.
111              
112             You can also visit us at C<#mason> on L<irc://irc.perl.org/#mason>.
113              
114             Bugs and feature requests will be tracked at RT:
115              
116             http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason-Plugin-RouterSimple
117             bug-mason-plugin-routersimple@rt.cpan.org
118              
119             The latest source code can be browsed and fetched at:
120              
121             http://github.com/jonswar/perl-mason-plugin-routersimple
122             git clone git://github.com/jonswar/perl-mason-plugin-routersimple.git
123              
124             =head1 SEE ALSO
125              
126             L<Mason>, L<Router::Simple>
127              
128             =head1 AUTHOR
129              
130             Jonathan Swartz <swartz@pobox.com>
131              
132             =head1 COPYRIGHT AND LICENSE
133              
134             This software is copyright (c) 2011 by Jonathan Swartz.
135              
136             This is free software; you can redistribute it and/or modify it under
137             the same terms as the Perl 5 programming language system itself.
138              
139             =cut
140              
141              
142             __END__
143