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

NAME

Dancer::Plugin::KossyValidator - 根据 Kossy 中的 Validator 移植过来的模块

SYNOPSIS

    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;

DESCRIPTION

Kossy 是 Perl 中另一个迷你框架,这个模块根据 Kossy 中的 Validator 移植过来支持 Dancer 的模块。

VALIDATORS

NOT_NULL
CHOICE
  ['CHOICE',qw/dog cat/]
INT

int

UINT

unsigned int

NATURAL

natural number

@SELECTED_NUM
  ['@SELECTED_NUM',min,max]
@SELECTED_UNIQ

all selected values are unique

CODEref VALIDATOR

  my $result = validator([
      'q' => [
          [sub{
              my ($req,$val) = @_;
          },'invalid']
      ],
  ]);
  
  my $result = validator([
      'q' => [
          [[sub{
              my ($req,$val,@args) = @_;
          },0,1],'invalid']
      ],
  ]);

AUTHOR

原模块作者 Masahiro Nagano <kazeburo {at} gmail.com> 移植人: 扶凯 iakuf {at} 163.com

SEE ALSO

Kossy::Validator

LICENSE

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:

Around line 200:

Non-ASCII character seen before =encoding in '根据'. Assuming UTF-8