line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Tiny::Plugin::Strict; |
2
|
|
|
|
|
|
|
$Form::Tiny::Plugin::Strict::VERSION = '2.21'; |
3
|
18
|
|
|
18
|
|
218
|
use v5.10; |
|
18
|
|
|
|
|
63
|
|
4
|
18
|
|
|
18
|
|
100
|
use strict; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
350
|
|
5
|
18
|
|
|
18
|
|
105
|
use warnings; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
486
|
|
6
|
|
|
|
|
|
|
|
7
|
18
|
|
|
18
|
|
107
|
use Form::Tiny::Error; |
|
18
|
|
|
|
|
84
|
|
|
18
|
|
|
|
|
497
|
|
8
|
|
|
|
|
|
|
|
9
|
18
|
|
|
18
|
|
115
|
use parent 'Form::Tiny::Plugin'; |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
103
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub plugin |
12
|
|
|
|
|
|
|
{ |
13
|
29
|
|
|
29
|
1
|
97
|
my ($self, $caller, $context) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
return { |
16
|
29
|
|
|
|
|
164
|
meta_roles => [__PACKAGE__], |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
18
|
|
|
18
|
|
2018
|
use Moo::Role; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
148
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
requires qw(setup); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# cache for the blueprint (if non-dynamic) |
25
|
|
|
|
|
|
|
has '_strict_blueprint' => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _check_recursive |
30
|
|
|
|
|
|
|
{ |
31
|
374
|
|
|
374
|
|
686
|
my ($self, $data, $blueprint) = @_; |
32
|
374
|
100
|
|
|
|
754
|
return 0 unless defined $blueprint; |
33
|
|
|
|
|
|
|
|
34
|
356
|
|
|
|
|
631
|
my $ref = ref $blueprint; |
35
|
|
|
|
|
|
|
|
36
|
356
|
100
|
|
|
|
808
|
if ($ref eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
37
|
51
|
100
|
|
|
|
112
|
return 0 unless ref $data eq 'ARRAY'; |
38
|
|
|
|
|
|
|
|
39
|
45
|
|
|
|
|
81
|
foreach my $value (@$data) { |
40
|
83
|
100
|
|
|
|
156
|
return 0 |
41
|
|
|
|
|
|
|
unless $self->_check_recursive($value, $blueprint->[0]); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ($ref eq 'HASH') { |
45
|
178
|
100
|
|
|
|
406
|
return 0 unless ref $data eq 'HASH'; |
46
|
|
|
|
|
|
|
|
47
|
169
|
|
|
|
|
438
|
for my $key (keys %$data) { |
48
|
|
|
|
|
|
|
return 0 |
49
|
180
|
100
|
|
|
|
499
|
unless $self->_check_recursive($data->{$key}, $blueprint->{$key}); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
# we're at leaf and no error occured - we're good. |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
287
|
|
|
|
|
699
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _check_strict |
60
|
|
|
|
|
|
|
{ |
61
|
111
|
|
|
111
|
|
230
|
my ($self, $obj, $input) = @_; |
62
|
|
|
|
|
|
|
|
63
|
111
|
|
|
|
|
293
|
my $blueprint = $self->_strict_blueprint; |
64
|
111
|
100
|
|
|
|
267
|
if (!$blueprint) { |
65
|
17
|
|
|
|
|
126
|
$blueprint = $self->blueprint($obj, recurse => 0); |
66
|
17
|
100
|
|
|
|
163
|
$self->_strict_blueprint($blueprint) |
67
|
|
|
|
|
|
|
unless $self->is_dynamic; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
111
|
|
|
|
|
328
|
my $strict = $self->_check_recursive($input, $blueprint); |
71
|
111
|
100
|
|
|
|
270
|
if (!$strict) { |
72
|
33
|
|
|
|
|
140
|
$obj->add_error($self->build_error(IsntStrict =>)); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
111
|
|
|
|
|
296
|
return $input; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
after 'setup' => sub { |
79
|
|
|
|
|
|
|
my ($self) = @_; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->add_hook( |
82
|
|
|
|
|
|
|
Form::Tiny::Hook->new( |
83
|
|
|
|
|
|
|
hook => 'before_validate', |
84
|
|
|
|
|
|
|
code => sub { $self->_check_strict(@_) }, |
85
|
|
|
|
|
|
|
inherited => 0, |
86
|
|
|
|
|
|
|
) |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|