line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Tiny::Plugin::Filtered; |
2
|
|
|
|
|
|
|
$Form::Tiny::Plugin::Filtered::VERSION = '2.19'; |
3
|
9
|
|
|
9
|
|
948
|
use v5.10; |
|
9
|
|
|
|
|
36
|
|
4
|
9
|
|
|
9
|
|
48
|
use strict; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
199
|
|
5
|
9
|
|
|
9
|
|
54
|
use warnings; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
319
|
|
6
|
9
|
|
|
9
|
|
54
|
use Types::Standard qw(ArrayRef InstanceOf Str); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
117
|
|
7
|
9
|
|
|
9
|
|
25500
|
use Scalar::Util qw(blessed); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
486
|
|
8
|
9
|
|
|
9
|
|
54
|
use Carp qw(carp); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
386
|
|
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
3452
|
use Form::Tiny::Hook; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
338
|
|
11
|
9
|
|
|
9
|
|
4601
|
use Form::Tiny::Plugin::Filtered::Filter; |
|
9
|
|
|
|
|
32
|
|
|
9
|
|
|
|
|
354
|
|
12
|
9
|
|
|
9
|
|
75
|
use Form::Tiny::Utils qw(trim); |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
473
|
|
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
64
|
use parent 'Form::Tiny::Plugin'; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
68
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub plugin |
17
|
|
|
|
|
|
|
{ |
18
|
10
|
|
|
10
|
1
|
45
|
my ($self, $caller, $context) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return { |
21
|
|
|
|
|
|
|
subs => { |
22
|
|
|
|
|
|
|
form_filter => sub { |
23
|
4
|
|
|
4
|
|
69
|
$$context = undef; |
24
|
4
|
|
|
|
|
36
|
$caller->form_meta->add_filter(@_); |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
field_filter => sub { |
27
|
5
|
|
|
5
|
|
267
|
$caller->form_meta->add_field_filter($self->use_context($context), @_); |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
field_validator => sub { |
30
|
1
|
|
|
1
|
|
20
|
$caller->form_meta->add_field_validator($self->use_context($context), @_); |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
form_trim_strings => sub { |
33
|
4
|
|
|
4
|
|
312
|
$$context = undef; |
34
|
4
|
|
|
|
|
33
|
$caller->form_meta->add_global_trim_filter; |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
|
|
202
|
meta_roles => [__PACKAGE__], |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
9
|
|
|
9
|
|
2124
|
use Moo::Role; |
|
9
|
|
|
|
|
25
|
|
|
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
|
|
53
|
my ($self, $filter, $code) = @_; |
58
|
|
|
|
|
|
|
|
59
|
17
|
100
|
66
|
|
|
136
|
return $filter |
60
|
|
|
|
|
|
|
if defined blessed $filter && $filter->isa('Form::Tiny::Plugin::Filtered::Filter'); |
61
|
|
|
|
|
|
|
|
62
|
15
|
|
|
|
|
464
|
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
|
41
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
7
|
|
|
23
|
|
47
|
return $self->add_filter(Str, sub { trim $_[1] }); |
|
23
|
|
|
|
|
98
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub add_filter |
76
|
|
|
|
|
|
|
{ |
77
|
12
|
|
|
12
|
0
|
129
|
my ($self, $filter, $code) = @_; |
78
|
|
|
|
|
|
|
|
79
|
12
|
|
|
|
|
29
|
push @{$self->filters}, $self->_create_filter($filter, $code); |
|
12
|
|
|
|
|
180
|
|
80
|
12
|
|
|
|
|
15733
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub add_field_filter |
84
|
|
|
|
|
|
|
{ |
85
|
5
|
|
|
5
|
0
|
18
|
my ($self, $field, $filter, $code) = @_; |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
8
|
push @{$field->addons->{filters}}, $self->_create_filter($filter, $code); |
|
5
|
|
|
|
|
23
|
|
88
|
5
|
|
|
|
|
2322
|
return $self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _apply_filters |
92
|
|
|
|
|
|
|
{ |
93
|
32
|
|
|
32
|
|
87
|
my ($self, $obj, $def, $value) = @_; |
94
|
|
|
|
|
|
|
|
95
|
32
|
|
|
|
|
51
|
for my $filter (@{$self->filters}) { |
|
32
|
|
|
|
|
100
|
|
96
|
40
|
|
|
|
|
142
|
$value = $filter->filter($obj, $value); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
32
|
|
|
|
|
2336
|
for my $filter (@{$def->addons->{filters}}) { |
|
32
|
|
|
|
|
109
|
|
100
|
9
|
|
|
|
|
39
|
$value = $filter->filter($obj, $value); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
32
|
|
|
|
|
1841
|
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
|
|
|
|
|
|
|
|