line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Tiny::Plugin::Filtered; |
2
|
|
|
|
|
|
|
$Form::Tiny::Plugin::Filtered::VERSION = '2.21'; |
3
|
9
|
|
|
9
|
|
870
|
use v5.10; |
|
9
|
|
|
|
|
33
|
|
4
|
9
|
|
|
9
|
|
53
|
use strict; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
188
|
|
5
|
9
|
|
|
9
|
|
42
|
use warnings; |
|
9
|
|
|
|
|
29
|
|
|
9
|
|
|
|
|
306
|
|
6
|
9
|
|
|
9
|
|
50
|
use Types::Standard qw(ArrayRef InstanceOf Str); |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
107
|
|
7
|
9
|
|
|
9
|
|
24378
|
use Scalar::Util qw(blessed); |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
470
|
|
8
|
9
|
|
|
9
|
|
56
|
use Carp qw(carp); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
392
|
|
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
3196
|
use Form::Tiny::Hook; |
|
9
|
|
|
|
|
29
|
|
|
9
|
|
|
|
|
361
|
|
11
|
9
|
|
|
9
|
|
4519
|
use Form::Tiny::Plugin::Filtered::Filter; |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
321
|
|
12
|
9
|
|
|
9
|
|
81
|
use Form::Tiny::Utils qw(trim); |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
531
|
|
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
58
|
use parent 'Form::Tiny::Plugin'; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
73
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub plugin |
17
|
|
|
|
|
|
|
{ |
18
|
10
|
|
|
10
|
1
|
42
|
my ($self, $caller, $context) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return { |
21
|
|
|
|
|
|
|
subs => { |
22
|
|
|
|
|
|
|
form_filter => sub { |
23
|
4
|
|
|
4
|
|
81
|
$$context = undef; |
24
|
4
|
|
|
|
|
19
|
$caller->form_meta->add_filter(@_); |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
field_filter => sub { |
27
|
5
|
|
|
5
|
|
260
|
$caller->form_meta->add_field_filter($self->use_context($context), @_); |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
field_validator => sub { |
30
|
1
|
|
|
1
|
|
15
|
$caller->form_meta->add_field_validator($self->use_context($context), @_); |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
form_trim_strings => sub { |
33
|
4
|
|
|
4
|
|
286
|
$$context = undef; |
34
|
4
|
|
|
|
|
35
|
$caller->form_meta->add_global_trim_filter; |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
|
|
169
|
meta_roles => [__PACKAGE__], |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
9
|
|
|
9
|
|
2105
|
use Moo::Role; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
87
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
requires qw(inherit_from setup); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has 'filters' => ( |
47
|
|
|
|
|
|
|
is => 'ro', |
48
|
|
|
|
|
|
|
writer => 'set_filters', |
49
|
|
|
|
|
|
|
isa => ArrayRef [ |
50
|
|
|
|
|
|
|
InstanceOf ['Form::Tiny::Plugin::Filtered::Filter'] |
51
|
|
|
|
|
|
|
], |
52
|
|
|
|
|
|
|
default => sub { [] }, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _create_filter |
56
|
|
|
|
|
|
|
{ |
57
|
17
|
|
|
17
|
|
49
|
my ($self, $filter, $code) = @_; |
58
|
|
|
|
|
|
|
|
59
|
17
|
100
|
66
|
|
|
135
|
return $filter |
60
|
|
|
|
|
|
|
if defined blessed $filter && $filter->isa('Form::Tiny::Plugin::Filtered::Filter'); |
61
|
|
|
|
|
|
|
|
62
|
15
|
|
|
|
|
429
|
return Form::Tiny::Plugin::Filtered::Filter->new( |
63
|
|
|
|
|
|
|
type => $filter, |
64
|
|
|
|
|
|
|
code => $code |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_global_trim_filter |
69
|
|
|
|
|
|
|
{ |
70
|
7
|
|
|
7
|
0
|
25
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
7
|
|
|
23
|
|
35
|
return $self->add_filter(Str, sub { trim $_[1] }); |
|
23
|
|
|
|
|
72
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub add_filter |
76
|
|
|
|
|
|
|
{ |
77
|
12
|
|
|
12
|
0
|
99
|
my ($self, $filter, $code) = @_; |
78
|
|
|
|
|
|
|
|
79
|
12
|
|
|
|
|
25
|
push @{$self->filters}, $self->_create_filter($filter, $code); |
|
12
|
|
|
|
|
97
|
|
80
|
12
|
|
|
|
|
15115
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub add_field_filter |
84
|
|
|
|
|
|
|
{ |
85
|
5
|
|
|
5
|
0
|
13
|
my ($self, $field, $filter, $code) = @_; |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
8
|
push @{$field->addons->{filters}}, $self->_create_filter($filter, $code); |
|
5
|
|
|
|
|
26
|
|
88
|
5
|
|
|
|
|
2359
|
return $self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _apply_filters |
92
|
|
|
|
|
|
|
{ |
93
|
32
|
|
|
32
|
|
77
|
my ($self, $obj, $def, $value) = @_; |
94
|
|
|
|
|
|
|
|
95
|
32
|
|
|
|
|
49
|
for my $filter (@{$self->filters}) { |
|
32
|
|
|
|
|
80
|
|
96
|
40
|
|
|
|
|
128
|
$value = $filter->filter($obj, $value); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
32
|
|
|
|
|
3237
|
for my $filter (@{$def->addons->{filters}}) { |
|
32
|
|
|
|
|
103
|
|
100
|
9
|
|
|
|
|
48
|
$value = $filter->filter($obj, $value); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
32
|
|
|
|
|
2265
|
return $value; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
after 'inherit_from' => sub { |
107
|
|
|
|
|
|
|
my ($self, $parent) = @_; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if ($parent->DOES('Form::Tiny::Plugin::Filtered')) { |
110
|
|
|
|
|
|
|
$self->set_filters([@{$parent->filters}, @{$self->filters}]); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
after 'setup' => sub { |
115
|
|
|
|
|
|
|
my ($self) = @_; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$self->add_hook( |
118
|
|
|
|
|
|
|
Form::Tiny::Hook->new( |
119
|
|
|
|
|
|
|
hook => 'before_mangle', |
120
|
|
|
|
|
|
|
code => sub { $self->_apply_filters(@_) }, |
121
|
|
|
|
|
|
|
inherited => 0, |
122
|
|
|
|
|
|
|
) |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|