++ed by:
ADAMJS ARPI CKRAS

3 PAUSE users
1 non-PAUSE user.

Yuki Kimoto
and 1 contributors

NAME

Mojolicious::Plugin::AutoRoute - Mojolicious plugin to create routes automatically

SYNOPSIS

  # Mojolicious
  $self->plugin('AutoRoute');

  # Mojolicious::Lite
  plugin 'AutoRoute';

  # With option
  plugin 'AutoRoute', route => $r;

DESCRIPTION

Mojolicious::Plugin::AutoRoute is a Mojolicious plugin to create routes automatically.

If you put templates into auto directory, the corresponding routes is created automatically.

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.

EXAMPLE

  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 %>

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.

TIPS

If you want to create custom route, use render_maybe method.

  # 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.

  use Mojolicious::Plugin::AutoRoute::Util 'template';
  
  # Mojolicious Lite
  any '/foo' => template '/foo';

  # Mojolicious
  $r->any('/foo' => template '/foo');

METHOD

register

  $plugin->register($app);

Register plugin in Mojolicious application.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.