NAME
Mojolicious::Plugin::AutoRoute - Mojolicious Plugin to create routes automatically
CAUTION
This is beta release and very experimental. Implementation will be changed without warnings.
SYNOPSIS
# Mojolicious
$self->plugin('AutoRoute');
# Mojolicious::Lite
plugin 'AutoRoute';
DESCRIPTION
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.
EXAMPLE
use Mojolicious::Lite;
# 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});
$self->finish_rendering;
return;
%>
@@ create.html.ep
/create/<%= $id %>
OPTIONS
route
route => $route;
You can set parent route if you need. This is Mojolicious::Routes object. Default is $app-
routes>.
top_dir
top_dir => 'myauto'
Top directory. default is auto
.
HELPER
finish_rendering
You can render data, json, not found and exeption from template using finish_rendering
helper.
@@ index.html.ep
$self->render(data => 'foo');
$self->finish_rendering;
return;
@@ index.html.ep
$self->render(json => {foo => 1});
$self->finish_rendering;
return;
@@ index.html.ep
$self->render_not_found;
$self->finish_rendering;
return;
@@ index.html.ep
$self->render_exception;
$self->finish_rendering;
return;
FUNCTIONS
template(Mojolicious::Plugin::AutoRoute::Util)
If you want to create custom route, use template
function.
use Mojolicious::Plugin::AutoRoute::Util 'template';
# Mojolicious Lite
get '/foo' => template '/foo';
# Mojolicious
$r->get('/foo' => template '/foo');
template
is return callback to call render_maybe
.
register
$plugin->register($app);
Register plugin in Mojolicious application.