Automatically generate routing by placing files --Mojolicious::Plugin::AutoRoute
Mojolicious::Plugin::AutoRoute is a plugin that automatically generates routes just by placing a file.
You can create a web application just by placing the template as a file and writing it.
It is perfect for those who think that it would be easier if it works just by placing a file like PHP.
How to use
#Mojolicious $self->plugin('AutoRoute'); #Mojolicious::Lite plugin'AutoRoute'; #Option plugin'AutoRoute', route => $r;
Create an "auto" directory inside the "templates" directory and place the templates in it.
The corresponding routing is automatically generated.
Template root templates / auto / index.html.ep # / /foo.html.ep # /foo /foo/bar.html.ep # /foo/bar /foo/bar/baz.html.ep # /foo/bar/baz
Options
route
route => $route;
You can specify the parent route if desired. This is a Mojolicious::Routes object. The default is $app->routes.
top_dir
top_dir =>'myauto'
The name of the top directory. The default is the auto directory.
Sample
use Mojolicious::Lite; #AutoRoute plugin'AutoRoute'; @@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; %>