NAME

Mojolicious::Plugin::AutoRoutePm - Mojolicious plugin to create routes by *.pm modules which are a controller

GitHub last commit Travis tests

VERSION

version 0.19

SYNOPSIS

use Mojolicious::Lite;
plugin 'AutoRoutePm', {
    route   => [ app->routes ],
    top_dir => 'site',
};

DESCRIPTION

This module recursive passes through template_base_dir to find perl modules (*.pm) that are a subclass of Mojolicious::Controller and adds routes for them.

USAGE

For module X::Y::Z it adds the decamelize version

x/y/z
x/y/z/index
x/y/z/index/*query

all redirect to action route inside module.

If Z is default_index it adds also

x/y
x/y/*query

The last structure is useful for routing seach. But be careful to correct relative urls of other items in html page.

This can be done in many ways. One is, as an example, to add to the layout a base_url like this

% my $base_url = url_for(undef, {query => undef}); $base_url =~ s|/$||;
<base href="<%= $base_url %>" />

register

plugin->register($app);

Register plugin in Mojolicious application.

SEE ALSO

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

AUTHOR

Emiliano Bruni <info@ebruni.it>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Emiliano Bruni.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.