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.
If you put templates into auto directory, the corresponding routes is created automatically.
auto
For example:
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
I like PHP simplicity. All thing needed is that you put PHP files into some directory, and write program. You don't need to create routes manually.
This plugin gives PHP simplicity to Mojolicious.
use Mojolicious::Lite; # AutoRoute plugin 'AutoRoute'; # Custom routes get '/create/:id' => sub { shift->render_maybe('/create') }; app->start; __DATA__ @@ 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 render_maybe method.
render_maybe
# Mojolicious Lite any '/foo' => sub { shift->render_maybe('/foo') }; # Mojolicious $r->any('/foo' => sub { shift->render_maybe('/foo') };
For backwrod comaptible, you can use template function.
template
use Mojolicious::Plugin::AutoRoute::Util 'template'; # Mojolicious Lite any '/foo' => template '/foo'; # Mojolicious $r->any('/foo' => template '/foo');
$plugin->register($app);
Register plugin in Mojolicious application.
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.