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
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.
$request->form("name")
The $validator is one of:
$validator
An object with validate method accepting one \%hashref argument (the raw form data).
validate
\%hashref
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.
engine
Neaf
LIVR
Wildcard
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.
new()
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 }; }; neaf->run
And by running this one gets
bash$ curl http://localhost:5000/check?bar=xxx {"error":{"bar":"BAD_FORMAT"}} bash$ curl http://localhost:5000/check?bar=y {"ok":{"bar":"y"}} bash$ curl http://localhost:5000/check?bar=yy {"error":{"bar":"BAD_FORMAT"}} bash$ curl http://localhost:5000/check?foo=137\&bar=n {"ok":{"bar":"n","foo":"137"}} bash$ curl http://localhost:5000/check?foo=leet {"error":{"foo":"BAD_FORMAT"}}
$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".
Add more default values.
Install hooks. Currently no preprocessing is done.
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-2018 Konstantin S. Uvarin khedin@cpan.org.
khedin@cpan.org
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 http://dev.perl.org/licenses/ for more information.
To install MVC::Neaf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MVC::Neaf
CPAN shell
perl -MCPAN -e shell install MVC::Neaf
For more information on module installation, please visit the detailed CPAN module installation guide.