Yuki Kimoto > Mojolicious-Plugin-AutoRoute-0.14 > Mojolicious::Plugin::AutoRoute

Download:
Mojolicious-Plugin-AutoRoute-0.14.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.14   Source  

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.

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

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.

FUNCTIONS ^

template(Mojolicious::Plugin::AutoRoute::Util)

If you want to create custom route, use template function.

  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.

METHOD ^

register

  $plugin->register($app);

Register plugin in Mojolicious application.

CAUTION ^

This plugin depend on Mojolicious internal structure. I try to keep this module work well and backword compatible, but I don't guarantee it.

SEE ALSO ^

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

syntax highlighting: