MVC::Neaf::Route - Route (path+method) class for Not Even A Framework


This module contains information about a handler defined using MVC::Neaf: method, path, handling code, connected hooks, default values etc.

It is useless in and off itself.



Route has the following read-only attributes:

  • parent (required)

  • path (required)

  • method (required)

  • code (required)

  • default

  • cache_ttl

  • path_info_regex

  • param_regex

  • description

  • public

  • caller

  • where

  • tentative

  • override TODO

  • hooks

  • helpers


Create a copy of existing route, possibly overriding some of the fields.


Prohibit any further modifications to this route.


Check that route is locked.


    add_form( name => $validator )

Create a named form for future query data validation via $request->form("name"). See "form" in MVC::Neaf::Request.

The $validator is one of:

  • An object with validate method accepting one \%hashref argument (the raw form data).

  • A CODEREF accepting the same argument.

Whatever is returned by validator is forwarded into the controller.

Neaf comes with a set of predefined validator classes that return a convenient object that contains collected valid data, errors (if any), and an is_valid flag.

The engine parameter of the functional form has predefined values Neaf (the default), LIVR, and Wildcard (all case-insensitive) pointing towards MVC::Neaf::X::Form, MVC::Neaf::X::Form::LIVR, and MVC::Neaf::X::Form::Wildcard, respectively.

You are encouraged to use LIVR (See Validator::LIVR and LIVR grammar) for anything except super-basic regex checks.

If an arbitrary class name is given instead, new() will be called on that class with \%spec ref as first parameter.

Consider the following script:

    use MVC::Neaf;
    neaf form => my => { foo => '\d+', bar => '[yn]' };
    get '/check' => sub {
        my $req = shift;
        my $in = $req->form("my");
        return $in->is_valid ? { ok => $in->data } : { error => $in->error };

And by running this one gets

    bash$ curl http://localhost:5000/check?bar=xxx
    bash$ curl http://localhost:5000/check?bar=y
    bash$ curl http://localhost:5000/check?bar=yy
    bash$ curl http://localhost:5000/check?foo=137\&bar=n
    bash$ curl http://localhost:5000/check?foo=leet


    $neaf->get_form( "name" )

Fetch form named "name" previously added via add_form to this route or one of its parent routes.

See "form" in MVC::Neaf::Request. See also "add_form".


Calculate hooks and path-based defaults.

Locks route, dies if already locked.


The following methods are part of NEAF's core and should not be called unless you want something very special.


    dispatch_logic( $req, $stem, $suffix )

May die. May spoil request.

Apply controller code to given request object, path stem, and path suffix.

Upon success, return a Neaf response hash (see "THE-RESPONSE" in MVC::Neaf).


This module is part of MVC::Neaf suite.

Copyright 2016-2019 Konstantin S. Uvarin

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.