line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Data::Validate::WithYAML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: validate form input with Data::Validate::WithYAML |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1392
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
82
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1597
|
use parent 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
713
|
|
|
2
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
117
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
148
|
|
11
|
2
|
|
|
2
|
|
1884
|
use Data::Validate::WithYAML; |
|
2
|
|
|
|
|
26338
|
|
|
2
|
|
|
|
|
86
|
|
12
|
2
|
|
|
2
|
|
29
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1243
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.04; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register { |
17
|
2
|
|
|
2
|
1
|
1545
|
my ($self, $app, $config) = @_; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
33
|
|
|
14
|
$config->{conf_path} ||= $self->home; |
20
|
2
|
|
50
|
|
|
17
|
$config->{no_steps} //= 1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$app->helper( 'validate' => sub { |
23
|
4
|
|
|
4
|
|
118153
|
my ($c, $file) = @_; |
24
|
|
|
|
|
|
|
|
25
|
4
|
100
|
|
|
|
31
|
if ( !$file ) { |
26
|
2
|
|
|
|
|
40
|
my @caller = caller(2); |
27
|
2
|
|
|
|
|
20
|
$file = (split /::/, $caller[3])[-1]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
260
|
my $path = File::Spec->rel2abs( File::Spec->catfile( $config->{conf_path}, $file . '.yml' ) ); |
31
|
|
|
|
|
|
|
|
32
|
4
|
50
|
|
|
|
272
|
if ( !-e $path ) { |
33
|
0
|
|
|
|
|
0
|
croak "$path does not exist"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
4
|
50
|
|
|
|
76
|
my $validator = Data::Validate::WithYAML->new( |
37
|
|
|
|
|
|
|
$path, |
38
|
4
|
50
|
|
|
|
9
|
%{ $config || { no_steps => 1 } }, |
39
|
|
|
|
|
|
|
) or croak $Data::Validate::WithYAML::errstr; |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
14299
|
my $params = $c->req->params->to_hash; |
42
|
4
|
50
|
|
|
|
3134
|
my %errors = $validator->validate( %{ $params || {} } ); |
|
4
|
|
|
|
|
48
|
|
43
|
|
|
|
|
|
|
|
44
|
4
|
50
|
|
|
|
7484
|
my $prefix = exists $config->{error_prefix} ? $config->{error_prefix} : 'ERROR_'; |
45
|
4
|
|
|
|
|
13
|
my %prefixed_errors = map{ ( "$prefix$_" => $errors{$_} ) } keys %errors; |
|
4
|
|
|
|
|
18
|
|
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
143
|
return %prefixed_errors; |
48
|
2
|
|
|
|
|
26
|
}); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$app->helper( 'fieldinfo' => sub { |
51
|
2
|
|
|
2
|
|
61391
|
my ($c, $file, $field, $subinfo) = @_; |
52
|
|
|
|
|
|
|
|
53
|
2
|
50
|
|
|
|
10
|
if ( !$file ) { |
54
|
0
|
|
|
|
|
0
|
my @caller = caller(2); |
55
|
0
|
|
|
|
|
0
|
$file = (split /::/, $caller[3])[-1]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
112
|
my $path = File::Spec->rel2abs( File::Spec->catfile( $config->{conf_path}, $file . '.yml' ) ); |
59
|
|
|
|
|
|
|
|
60
|
2
|
50
|
|
|
|
88
|
if ( !-e $path ) { |
61
|
0
|
|
|
|
|
0
|
croak "$path does not exist"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
2
|
50
|
|
|
|
31
|
my $validator = Data::Validate::WithYAML->new( |
65
|
|
|
|
|
|
|
$path, |
66
|
2
|
50
|
|
|
|
4
|
%{ $config || { no_steps => 1 } }, |
67
|
|
|
|
|
|
|
) or croak $Data::Validate::WithYAML::errstr; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
9610
|
my $info = $validator->fieldinfo( $field ); |
70
|
|
|
|
|
|
|
|
71
|
2
|
50
|
|
|
|
27
|
return if !$info; |
72
|
|
|
|
|
|
|
|
73
|
2
|
100
|
|
|
|
43
|
return $info if !$subinfo; |
74
|
1
|
|
|
|
|
14
|
return $info->{$subinfo}; |
75
|
2
|
|
|
|
|
251
|
}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |