line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Plugin::DataTransposeValidator; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
685621
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
31
|
|
|
1
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
7
|
1
|
|
|
1
|
|
6
|
use Dancer2::Core::Types qw(Enum HashRef Maybe Str); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
1654
|
use Dancer2::Plugin::DataTransposeValidator::Validator; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
755
|
use Path::Tiny; |
|
1
|
|
|
|
|
8878
|
|
|
1
|
|
|
|
|
54
|
|
10
|
1
|
|
|
1
|
|
8
|
use Module::Runtime qw/use_module/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
512
|
use Dancer2::Plugin 0.205000; |
|
1
|
|
|
|
|
11445
|
|
|
1
|
|
|
|
|
12
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Dancer2::Plugin::DataTransposeValidator - Data::Transpose::Validator plugin for Dancer2 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Version 0.201 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.201'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has css_error_class => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => Str, |
29
|
|
|
|
|
|
|
from_config => sub { 'has-error' }, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has errors_hash => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
isa => Maybe [ Enum [qw/arrayref joined/] ], |
35
|
|
|
|
|
|
|
from_config => sub { undef }, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has rules => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
isa => HashRef, |
41
|
|
|
|
|
|
|
default => sub { +{} }, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has rules_class => ( |
45
|
|
|
|
|
|
|
is => 'ro', |
46
|
|
|
|
|
|
|
isa => Maybe [Str], |
47
|
|
|
|
|
|
|
from_config => sub { undef }, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has rules_dir => ( |
51
|
|
|
|
|
|
|
is => 'ro', |
52
|
|
|
|
|
|
|
isa => sub { |
53
|
|
|
|
|
|
|
eval { path( $_[0] )->is_dir; 1 } |
54
|
|
|
|
|
|
|
or do { croak "rules directory does not exist" }; |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
default => sub { |
57
|
|
|
|
|
|
|
my $plugin = shift; |
58
|
|
|
|
|
|
|
my $dir = |
59
|
|
|
|
|
|
|
$plugin->config->{rules_dir} |
60
|
|
|
|
|
|
|
? $plugin->config->{rules_dir} |
61
|
|
|
|
|
|
|
: 'validation'; |
62
|
|
|
|
|
|
|
path( $plugin->app->setting('appdir') )->child($dir)->stringify; |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
plugin_keywords 'validator'; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub BUILD { |
69
|
7
|
|
|
7
|
0
|
469
|
my $plugin = shift; |
70
|
|
|
|
|
|
|
croak __PACKAGE__ . " cannot use both of rules_class and rules_dir" |
71
|
|
|
|
|
|
|
if exists $plugin->config->{rules_class} |
72
|
7
|
50
|
66
|
|
|
90
|
&& exists $plugin->config->{rules_dir}; |
73
|
|
|
|
|
|
|
|
74
|
7
|
100
|
|
|
|
157
|
if ( exists $plugin->config->{rules_class} ) { |
75
|
1
|
|
|
|
|
20
|
use_module( $plugin->config->{rules_class} ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub validator { |
80
|
16
|
|
|
16
|
1
|
482762
|
my ( $plugin, $params, $name, @additional_args ) = @_; |
81
|
16
|
|
|
|
|
35
|
my $rules; |
82
|
|
|
|
|
|
|
|
83
|
16
|
50
|
|
|
|
61
|
croak "params must be a hash reference" unless ref($params) eq 'HASH'; |
84
|
|
|
|
|
|
|
|
85
|
16
|
100
|
|
|
|
56
|
if ( ref($name) eq '' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
86
|
13
|
100
|
|
|
|
61
|
if ( !$plugin->rules->{$name} ) { |
87
|
8
|
100
|
|
|
|
163
|
if ( my $class = $plugin->rules_class ) { |
88
|
1
|
50
|
|
|
|
173
|
if ( $class->can($name) ) { |
89
|
1
|
|
|
|
|
3
|
$plugin->rules->{$name} = \&{"${class}::$name"}; |
|
1
|
|
|
|
|
25
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
0
|
|
|
|
|
0
|
croak "Rules class \"$class\" has no rule sub named: $name"; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
|
|
|
|
|
|
# nasty old rules_dir |
97
|
7
|
|
|
|
|
225
|
my $path = path( $plugin->rules_dir )->child($name); |
98
|
7
|
100
|
|
|
|
556
|
croak "rules_file does not exist" unless $path->is_file; |
99
|
|
|
|
|
|
|
|
100
|
6
|
50
|
|
|
|
229
|
my $eval = do $path->absolute |
101
|
|
|
|
|
|
|
or croak "bad rules file: $path - $! $@"; |
102
|
|
|
|
|
|
|
|
103
|
6
|
100
|
|
|
|
2241
|
if ( ref($eval) eq 'CODE' ) { |
104
|
1
|
|
|
|
|
8
|
$plugin->rules->{$name} = $eval; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
5
|
|
|
7
|
|
59
|
$plugin->rules->{$name} = sub { $eval }; |
|
7
|
|
|
|
|
15
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
12
|
|
|
|
|
61
|
$rules = $plugin->rules->{$name}->(@additional_args); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif ( ref($name) eq 'HASH' ) { |
114
|
1
|
|
|
|
|
3
|
$rules = $name; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ( ref($name) eq 'CODE' ) { |
117
|
1
|
|
|
|
|
9
|
$rules = $name->(@additional_args); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
1
|
|
|
|
|
3
|
my $ref = ref($name); |
121
|
1
|
|
|
|
|
261
|
croak "rules option reference type $ref not allowed"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return Dancer2::Plugin::DataTransposeValidator::Validator->new( |
125
|
|
|
|
|
|
|
params => $params, |
126
|
|
|
|
|
|
|
rules => { |
127
|
|
|
|
|
|
|
options => $rules->{options} || {}, |
128
|
|
|
|
|
|
|
prepare => $rules->{prepare} || {}, |
129
|
|
|
|
|
|
|
}, |
130
|
14
|
|
50
|
|
|
418
|
css_error_class => $plugin->css_error_class, |
|
|
|
50
|
|
|
|
|
131
|
|
|
|
|
|
|
errors_hash => $plugin->errors_hash, |
132
|
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
__END__ |