| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Mojolicious::Plugin::KossyValidator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Hash::MultiValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | my $NUM_RE = qr/^[-+]?[0-9]+(:?\.[0-9]+)?$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | our %VALIDATOR = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | NOT_NULL => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my ($req,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | return if not defined($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | return if $val eq ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | CHOICE => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($req, $val, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | for my $c (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($c eq $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | INT => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($req, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | return if not defined($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return $val =~ /^\-?[\d]+$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | UINT => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my ($req, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return if not defined($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $val =~ /^\d+$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | NATURAL => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my ($req,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return if not defined($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $val =~ /^\d+$/ && $val > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | ALPHA=> sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my ($req,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return if not defined($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $val =~ /^[A-Za-z]+$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | BETWEEN => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($req, $value, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my ($start, $end) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return unless defined($start) && $start =~ /$NUM_RE/ && defined($end) && $end =~ /$NUM_RE/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
defined $start and $start =~ /$NUM_RE/u and defined $end and $end =~ /$NUM_RE/u
defined $start and $start =~ /$NUM_RE/u and defined $end
defined $start and $start =~ /$NUM_RE/u
MC/DC0%0/4
defined $start and $start =~ /$NUM_RE/u and defined $end and $end =~ /$NUM_RE/u
defined $start
$start =~ /$NUM_RE/u
defined $end
$end =~ /$NUM_RE/u
Truth table0%0/5
A and B and C and D
A= defined $startB= $start =~ /$NUM_RE/uC= defined $endD= $end =~ /$NUM_RE/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return unless defined $value && $value =~ /$NUM_RE/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value =~ /$NUM_RE/u
MC/DC0%0/2
defined $value and $value =~ /$NUM_RE/u
defined $value
$value =~ /$NUM_RE/u
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /$NUM_RE/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return $value >= $start && $value <= $end ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$value >= $start and $value <= $end
MC/DC0%0/2
$value >= $start and $value <= $end
$value >= $start
$value <= $end
Truth table0%0/3
A and B
A= $value >= $startB= $value <= $end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | LENGTH => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my ($req, $value, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $min; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | my $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if(ref $args eq 'ARRAY') { ($min, $max) = @$args } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | elsif (ref $args eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $min = $args->{min}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $max = $args->{max}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | else { $min = $max = $args } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return 0 unless defined $min || defined $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $min or defined $max
MC/DC0%0/2
defined $min or defined $max
defined $min
defined $max
Truth table0%0/3
A or B
A= defined $minB= defined $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $length = length $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $is_valid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (defined $min && defined $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
defined $min and defined $max
MC/DC0%0/2
defined $min and defined $max
defined $min
defined $max
Truth table0%0/3
A and B
A= defined $minB= defined $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $is_valid = $length >= $min && $length <= $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$length >= $min && $length <= $max
MC/DC0%0/2
$length >= $min && $length <= $max
$length >= $min
$length <= $max
Truth table0%0/3
A && B
A= $length >= $minB= $length <= $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | elsif (defined $min) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $is_valid = $length >= $min; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif (defined $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $is_valid = $length <= $max; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return $is_valid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | '@SELECTED_NUM' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($req,$vals,@args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($min,$max) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | scalar(@$vals) >= $min && scalar(@$vals) <= $max | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | '@SELECTED_UNIQ' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($req,$vals) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my %vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $vals{$_} = 1 for @$vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | scalar(@$vals) == scalar keys %vals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my ($self, $app, $conf) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | $app->helper( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | validator => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=28 SCAR=67.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($self, $rule) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $valid = Hash::MultiValue->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $req = $self->req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | for ( my $i=0; $i < @$rule; $i = $i+2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $param = $rule->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $constraints; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $param_name = $param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $param_name =~ s!^@!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @vals = $self->param($param_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $vals = ( $param =~ m!^@! ) ? \@vals : [$vals[-1]]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ( ref($rule->[$i+1]) && ref($rule->[$i+1]) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $$rule[$i + 1] and ref $$rule[$i + 1] eq "HASH"
MC/DC0%0/2
ref $$rule[$i + 1] and ref $$rule[$i + 1] eq "HASH"
ref $$rule[$i + 1]
ref $$rule[$i + 1] eq "HASH"
Truth table0%0/3
A and B
A= ref $$rule[$i + 1]B= ref $$rule[$i + 1] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ( $param !~ m!^@! && !$VALIDATOR{NOT_NULL}->($req, $vals->[0]) && exists $rule->[$i+1]->{default} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $param =~ /^@/u || $Mojolicious::Plugin::KossyValidator::VALIDATOR{"NOT_NULL"}->($req, $vals->[0]) and exists $$rule[$i + 1]{"default"}
$param =~ /^@/u || $Mojolicious::Plugin::KossyValidator::VALIDATOR{'NOT_NULL'}->($req, $vals->[0])
MC/DC0%0/3
not $param =~ /^@/u || $Mojolicious::Plugin::KossyValidator::VALIDATOR{"NOT_NULL"}->($req, $vals->[0]) and exists $$rule[$i + 1]{"default"}
$param =~ /^@/u
$Mojolicious::Plugin::KossyValidator::VALIDATOR{'NOT_NULL'}->($req, $vals->[0])
exists $$rule[$i + 1]{"default"}
Truth table0%0/4
not(A || B) and C
A= $param =~ /^@/uB= $Mojolicious::Plugin::KossyValidator::VALIDATOR{'NOT_NULL'}->($req, $vals->[0])C= exists $$rule[$i + 1]{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $default = $rule->[$i+1]->{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $vals = [$default]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $constraints = $rule->[$i+1]->{rule}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $constraints = $rule->[$i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | PARAM_CONSTRAINT: for my $constraint ( @$constraints ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ( ref($constraint->[0]) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my @constraint = @{$constraint->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $constraint_name = shift @constraint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ( ref($constraint_name) && ref($constraint_name) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $constraint_name and ref $constraint_name eq "CODE"
MC/DC0%0/2
ref $constraint_name and ref $constraint_name eq "CODE"
ref $constraint_name
ref $constraint_name eq "CODE"
Truth table0%0/3
A and B
A= ref $constraint_nameB= ref $constraint_name eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | for my $val ( @$vals ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( !$constraint_name->($req, $val, @constraint) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | push @errors, { param => $param_name, message => $constraint->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $error=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | last PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | next PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | die "constraint:$constraint_name not found" if ! exists $VALIDATOR{$constraint_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ( $constraint_name =~ m!^@! ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ( !$VALIDATOR{$constraint_name}->($req,$vals,@constraint) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | push @errors, { param => $param_name, message => $constraint->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $error=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | last PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | for my $val ( @$vals ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ( !$VALIDATOR{$constraint_name}->($req,$val,@constraint) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | push @errors, { param => $param_name, message => $constraint->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $error=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | last PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif ( ref($constraint->[0]) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | for my $val ( @$vals ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( !$constraint->[0]->($req, $val) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | push @errors, { param => $param_name, message => $constraint->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $error=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | last PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | die "constraint:".$constraint->[0]." not found" if ! exists $VALIDATOR{$constraint->[0]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( $constraint->[0] =~ m!^@! ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ( !$VALIDATOR{$constraint->[0]}->($req,$vals) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | push @errors, { param => $param_name, message => $constraint->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $error=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | last PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | for my $val ( @$vals ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( !$VALIDATOR{$constraint->[0]}->($req, $val) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | push @errors, { param => $param_name, message => $constraint->[1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $error=1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | last PARAM_CONSTRAINT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $valid->add($param_name,@$vals) unless $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | KossyValidator::Result->new(\@errors,$valid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | package KossyValidator::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $errors = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $valid = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | bless {errors=>$errors,valid=>$valid}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub has_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_error: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return 1 if @{$self->{errors}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | sub messages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
messages: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my @errors = map { $_->{message} } @{$self->{errors}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | \@errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub errors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my %errors = map { $_->{param} => $_->{message} } @{$self->{errors}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | \%errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub valid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ( @_ == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->{valid}->add(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | elsif ( @_ == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return $self->{valid}->get($_[0]) if ! wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | return $self->{valid}->get_all($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->{valid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub to_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_hash: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return %{ $self->valid() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | Mojolicious::Plugin::KossyValidator - 根据 Kossy 中的 Validator 移植过来的模块 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | use Mojolicious::Plugin::KossyValidator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | sub show { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | my $c = shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | my $result = $c->validator([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 'name' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | rule => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ['NOT_NULL', '不能为空'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | #['ALPHA', '需要是数字'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | #[['LENGTH',(10, 20)], '长度为 10-20 之间'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | #[['BETWEEN',(1, 2)], '参数只能为数字'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 'description' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | default => '无', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | rule => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $c->render( json => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | result => 'false', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | messages => $result->errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | }) if $result->has_error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | $result->has_error:Flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | $result->messages:ArrayRef[`Str] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | my $val = $result->valid('name'); # 注意取请求过来的参数时原函数 param 替换为 valid 了 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | my @val = $result->valid('description'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | my %hash = $result->to_hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | dancer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | Kossy 是 Perl 中另一个迷你框架,这个模块根据 Kossy 中的 Validator 移植过来支持 Mojolicious 的模块。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | =head1 VALIDATORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | =item NOT_NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =item CHOICE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | ['CHOICE',qw/dog cat/] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | =item INT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | =item UINT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | unsigned int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | =item NATURAL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | natural number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | =item ALPHA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | English alphabet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | =item BETWEEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | between two number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | =item LENGTH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | param length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | =item @SELECTED_NUM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ['@SELECTED_NUM',min,max] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | =item @SELECTED_UNIQ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | all selected values are unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | =head1 CODEref VALIDATOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | my $result = $c->validator([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 'q' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | [sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | my ($req,$val) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | },'invalid'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | my $result = $c->validator([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 'q' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | [[sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | my ($req,$val,@args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | },0,1],'invalid'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 原模块作者 Masahiro Nagano E<lt>kazeburo {at} gmail.comE<gt> 移植人: 扶凯 iakuf {at} 163.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | L<Kossy::Validator> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||