Dancer::Plugin::KossyValidator - 根据 Kossy 中的 Validator 移植过来的模块
use Dancer ':syntax'; use Dancer::Plugin::KossyValidator; any ['post', 'put'] => '/isp' => sub { my $result = validator([ 'name' => { rule => [ ['NOT_NULL', '运营商名不能为空'], ], }, 'description' => { default => '无', rule => [], }, ]); return { result => 'false', messages => $result->errors } if $result->has_error; $result->has_error:Flag $result->messages:ArrayRef[`Str] my $val = $result->valid('name'); # 注意取请求过来的参数时原函数 param 替换为 valid 了 my @val = $result->valid('description'); my $hash = $result->valid:Hash::MultiValue; # ... }; dancer;
Kossy 是 Perl 中另一个迷你框架,这个模块根据 Kossy 中的 Validator 移植过来支持 Dancer 的模块。
['CHOICE',qw/dog cat/]
int
unsigned int
natural number
['@SELECTED_NUM',min,max]
all selected values are unique
my $result = validator([ 'q' => [ [sub{ my ($req,$val) = @_; },'invalid'] ], ]); my $result = validator([ 'q' => [ [[sub{ my ($req,$val,@args) = @_; },0,1],'invalid'] ], ]);
原模块作者 Masahiro Nagano <kazeburo {at} gmail.com> 移植人: 扶凯 iakuf {at} 163.com
Kossy::Validator
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in '根据'. Assuming UTF-8
To install Dancer::Plugin::KossyValidator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::KossyValidator
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::KossyValidator
For more information on module installation, please visit the detailed CPAN module installation guide.