line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::FormValidator; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1153
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1362
|
use Data::FormValidator; |
|
1
|
|
|
|
|
36979
|
|
|
1
|
|
|
|
|
725
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $results; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub dfv_verify { |
12
|
0
|
|
|
0
|
0
|
0
|
my ($route, $c, $captures, $profile) = @_; |
13
|
0
|
0
|
|
|
|
0
|
return undef unless $profile; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
0
|
my $input_hash = $c->req->params->to_hash; |
16
|
0
|
|
|
|
|
0
|
_dfv_verify($c, $input_hash, $profile); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
return 1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub register { |
22
|
1
|
|
|
1
|
1
|
72
|
my ($self, $app) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$app->helper(_dfv_error => sub { |
25
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
my $field = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
0
|
return 0 if !defined $results; |
29
|
0
|
0
|
|
|
|
0
|
return 0 if $results->valid($field); |
30
|
0
|
0
|
|
|
|
0
|
return 1 if $results->invalid($field); |
31
|
0
|
0
|
|
|
|
0
|
return 1 if $results->missing($field); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
return 0; |
34
|
1
|
|
|
|
|
17
|
}); |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
151
|
return $app->routes->add_condition(dfv_verify => \&dfv_verify); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _dfv_verify { |
40
|
0
|
|
|
0
|
|
|
my $c = shift; |
41
|
0
|
|
|
|
|
|
my $input_hash = shift; |
42
|
0
|
|
|
|
|
|
my $dfv_profile = shift; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $r = Data::FormValidator->check($input_hash, $dfv_profile); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my @fields = (); |
47
|
0
|
|
|
|
|
|
my $required = $r->{profile}{required}; |
48
|
0
|
|
|
|
|
|
my $optional = $r->{profile}{optional}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
push(@fields, @$required); |
51
|
0
|
|
|
|
|
|
push(@fields, @$optional); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
for my $field (@fields) { |
54
|
0
|
|
0
|
|
|
|
$c->stash->{$field} = $c->req->param($field) // ""; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
return if 0 == keys %$input_hash; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$results = $r; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |