Mojolicious::Plugin::AutoRoute - Mojolicious Plugin to create routes automatically
# Mojolicious $self->plugin('AutoRoute'); # Mojolicious::Lite plugin 'AutoRoute'; # With option plugin 'AutoRoute', route => $r;
Mojolicious::Plugin::AutoRoute is a Mojolicious plugin to create routes automatically.
Routes corresponding to URL is created .
TEMPLATES ROUTES templates/auto/index.html.ep # / /foo.html.ep # /foo /foo/bar.html.ep # /foo/bar /foo/bar/baz.html.ep # /foo/bar/baz
If you like PHP, this plugin is very good. You only put file into auto directory.
PHP
auto
use Mojolicious::Lite; use Mojolicious::Plugin::AutoRoute::Util 'template'; # AutoRoute plugin 'AutoRoute'; # Custom routes get '/create/:id' => template '/create'; @@ auto/index.html.ep / @@ auto/foo.html.ep /foo @@ auto/bar.html.ep /bar @@ auto/foo/bar/baz.html.ep /foo/bar/baz @@ auto/json.html.ep <% $self->render(json => {foo => 1}); return; %> @@ create.html.ep /create/<%= $id %>
route => $route;
You can set parent route if you need. This is Mojolicious::Routes object. Default is $app-routes>.
$app-
top_dir => 'myauto'
Top directory. default is auto.
If you want to create custom route, use template function.
template
use Mojolicious::Plugin::AutoRoute::Util 'template'; # Mojolicious Lite any '/foo' => template '/foo'; # Mojolicious $r->any('/foo' => template '/foo');
template is return callback to call render_maybe.
render_maybe
$plugin->register($app);
Register plugin in Mojolicious application.
This plugin depend on Mojolicious internal structure. I try to keep this module work well and backword compatible, but I don't guarantee it.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious::Plugin::AutoRoute, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::AutoRoute
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::AutoRoute
For more information on module installation, please visit the detailed CPAN module installation guide.