NAME

Dancer2::Controllers

SYNOPSIS

Dancer2::Controllers is a Spring-Boot esq wrapper for defining Dancer2 routes, it allows you to define routes inside of modules using a routes method.

EXAMPLE

package MyApp::Controller;

use Moo;

use strict;
use warnings;

# Optionally use the Dancer2::Controllers::Controller role to explicitly display
# that this module is a controller.
with 'Dancer2::Controllers::Controller';

sub hello_world {
    "Hello World!";
}

sub routes {
    return [
        [ 'get' => '/' => 'hello_world' ],
        [ 'get' => '/foo' => sub { 'Foo!' } ] # or, use a subroutine!
    ];
}

1;

use Dancer2;
use Dancer2::Controllers;

controllers( ['MyApp::Controller'] );

dance;

API

controllers

controllers( [
    'MyApp::Controller::Foo',
    'MyApp::Controller::Bar'
] );

A subroutine that takes a list of controller module names, and registers their routes.