The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Kelp::Module::Routes - Default router module for Kelp

SYNOPSIS

    # config.pl
    {
        modules      => ['Routes'],    # included by default
        modules_init => {
            Routes => {
                base => 'MyApp'
            }
        }
    }

    # lib/MyApp.pm
    sub build {
        my $self = shift;
        mt $self->add_route( '/', 'home' );
    }

DESCRIPTION

This module and Kelp::Module::Config are automatically loaded into each Kelp application. It initializes the routing table for the web application.

REGISTERED METHODS

This module registers the following methods into the underlying app:

routes

An instance to Kelp::Routes, or whichever router was specified in the configuration.

    # lib/MyApp.pm
    sub build {
        my $self = shift;
        $self->routes->add( '/', 'home' );
    }

add_route

A shortcut to the "add" in Kelp::Routes method.

CONFIGURATION

The configuration for this module contains the following keys:

router

The router class to use. The default value is Kelp::Routes, but any other class can be specified. A normal string will be considered a subclass of Kelp::Routes, for example:

    router => 'Custom'

will look for Kelp::Routes::Custom. To specify a fully qualified class, prefix it with a plus sign.

    router => '+My::Special::Router

See Kelp::Routes::Controller for a router class that reblesses the application instance.

base

Specifies the base class of each route. This saves a lot of typing when writing the routes definitions.

    base => 'MyApp'

Now when defining a route you can only type myroute to denote MyApp::myroute.