line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Lite::Constraint::Default; |
2
|
30
|
|
|
30
|
|
141
|
use strict; |
|
30
|
|
|
|
|
48
|
|
|
30
|
|
|
|
|
601
|
|
3
|
30
|
|
|
30
|
|
104
|
use warnings; |
|
30
|
|
|
|
|
37
|
|
|
30
|
|
|
|
|
494
|
|
4
|
30
|
|
|
30
|
|
8623
|
use FormValidator::Lite::Constraint; |
|
30
|
|
|
|
|
60
|
|
|
30
|
|
|
|
|
154
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
rule 'NOT_NULL' => sub { |
7
|
|
|
|
|
|
|
return 0 if not defined($_); |
8
|
|
|
|
|
|
|
return 0 if $_ eq ""; |
9
|
|
|
|
|
|
|
return 0 if ref($_)eq'ARRAY' && @$_ == 0; |
10
|
|
|
|
|
|
|
return 1; |
11
|
|
|
|
|
|
|
}; |
12
|
|
|
|
|
|
|
rule 'INT' => sub { $_ =~ /\A[+\-]?[0-9]+\z/ }; |
13
|
|
|
|
|
|
|
rule 'UINT' => sub { $_ =~ /\A[0-9]+\z/ }; |
14
|
|
|
|
|
|
|
alias 'NOT_NULL' => 'NOT_BLANK'; |
15
|
|
|
|
|
|
|
alias 'NOT_NULL' => 'REQUIRED'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
rule 'ASCII' => sub { |
18
|
|
|
|
|
|
|
$_ =~ /^[\x21-\x7E]+$/ |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# {mails => [qw/mail1 mail2/]} => ['DUPLICATION'] |
22
|
|
|
|
|
|
|
rule 'DUPLICATION' => sub { |
23
|
|
|
|
|
|
|
defined($_->[0]) && defined($_->[1]) && $_->[0] eq $_->[1] |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
alias 'DUPLICATION' => 'DUP'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# 'name' => [qw/LENGTH 5 20/], |
28
|
|
|
|
|
|
|
rule 'LENGTH' => sub { |
29
|
|
|
|
|
|
|
my $length = length($_); |
30
|
|
|
|
|
|
|
my $min = shift; |
31
|
|
|
|
|
|
|
my $max = shift || $min; |
32
|
|
|
|
|
|
|
Carp::croak("missing \$min") unless defined($min); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
( $min <= $length and $length <= $max ) |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
rule 'EQUAL' => sub { |
38
|
|
|
|
|
|
|
Carp::croak("missing \$argument") if @_ == 0; |
39
|
|
|
|
|
|
|
$_ eq $_[0] |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
rule 'REGEX' => sub { |
43
|
|
|
|
|
|
|
my $regex = shift; |
44
|
|
|
|
|
|
|
Carp::croak("missing args at REGEX rule") unless defined $regex; |
45
|
|
|
|
|
|
|
$_ =~ /$regex/ |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
alias 'REGEX' => 'REGEXP'; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
rule 'CHOICE' => sub { |
50
|
|
|
|
|
|
|
Carp::croak("missing \$choices") if @_ == 0; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my @choices = @_==1 && ref$_[0]eq'ARRAY' ? @{$_[0]} : @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
for my $c (@choices) { |
55
|
|
|
|
|
|
|
if ($c eq $_) { |
56
|
|
|
|
|
|
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
return 0; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
alias 'CHOICE' => 'IN'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
rule 'NOT_IN' => sub { |
64
|
|
|
|
|
|
|
my @choices = @_==1 && ref$_[0]eq'ARRAY' ? @{$_[0]} : @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
for my $c (@choices) { |
67
|
|
|
|
|
|
|
if ($c eq $_) { |
68
|
|
|
|
|
|
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
return 1; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
rule 'MATCH' => sub { |
75
|
|
|
|
|
|
|
my $callback = shift; |
76
|
|
|
|
|
|
|
Carp::croak("missing \$callback") if ref $callback ne 'CODE'; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$callback->($_); |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
our $Filters = { |
82
|
|
|
|
|
|
|
trim => sub { |
83
|
|
|
|
|
|
|
my $value = shift; |
84
|
|
|
|
|
|
|
return $value unless $value; |
85
|
|
|
|
|
|
|
$value =~ s/^\s+|\s+$//g; |
86
|
|
|
|
|
|
|
$value; |
87
|
|
|
|
|
|
|
}, |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
rule 'FILTER' => sub { |
91
|
|
|
|
|
|
|
my $filter = shift; |
92
|
|
|
|
|
|
|
Carp::croak("missing \$filter") unless $filter; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if (not ref $filter) { |
95
|
|
|
|
|
|
|
$filter = $Filters->{$filter} |
96
|
|
|
|
|
|
|
or Carp::croak("$filter is not defined."); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Carp::croak("\$filter must be coderef.") if ref $filter ne 'CODE'; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$_ = $filter->($_); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; # always return true |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |