line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
100
|
|
|
100
|
|
65055
|
use strict; |
|
100
|
|
|
|
|
274
|
|
|
100
|
|
|
|
|
5936
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Role::Element::SingleValueField; |
4
|
|
|
|
|
|
|
# ABSTRACT: role for single value fields |
5
|
|
|
|
|
|
|
$HTML::FormFu::Role::Element::SingleValueField::VERSION = '2.07'; |
6
|
100
|
|
|
100
|
|
637
|
use Moose::Role; |
|
100
|
|
|
|
|
237
|
|
|
100
|
|
|
|
|
777
|
|
7
|
|
|
|
|
|
|
|
8
|
100
|
|
|
100
|
|
527652
|
use Carp qw( croak ); |
|
100
|
|
|
|
|
283
|
|
|
100
|
|
|
|
|
82346
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub add_error { |
11
|
9
|
|
|
9
|
0
|
46
|
my ( $self, @errors ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
9
|
|
|
|
|
21
|
push @{ $self->_errors }, @errors; |
|
9
|
|
|
|
|
292
|
|
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
|
|
38
|
return; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub deflator { |
19
|
11
|
|
|
11
|
0
|
55
|
my ( $self, $arg ) = @_; |
20
|
11
|
|
|
|
|
29
|
my @return; |
21
|
|
|
|
|
|
|
|
22
|
11
|
100
|
|
|
|
55
|
if ( ref $arg eq 'ARRAY' ) { |
23
|
5
|
|
|
|
|
28
|
push @return, map { _single_deflator( $self, $_ ) } @$arg; |
|
5
|
|
|
|
|
25
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else { |
26
|
6
|
|
|
|
|
52
|
push @return, _single_deflator( $self, $arg ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
11
|
50
|
|
|
|
87
|
return @return == 1 ? $return[0] : @return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub filter { |
33
|
7
|
|
|
7
|
0
|
29
|
my ( $self, $arg ) = @_; |
34
|
7
|
|
|
|
|
16
|
my @return; |
35
|
|
|
|
|
|
|
|
36
|
7
|
100
|
|
|
|
46
|
if ( ref $arg eq 'ARRAY' ) { |
37
|
1
|
|
|
|
|
4
|
push @return, map { _single_filter( $self, $_ ) } @$arg; |
|
1
|
|
|
|
|
6
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
6
|
|
|
|
|
29
|
push @return, _single_filter( $self, $arg ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
7
|
50
|
|
|
|
54
|
return @return == 1 ? $return[0] : @return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub constraint { |
47
|
14
|
|
|
14
|
0
|
82
|
my ( $self, $arg ) = @_; |
48
|
14
|
|
|
|
|
38
|
my @return; |
49
|
|
|
|
|
|
|
|
50
|
14
|
100
|
|
|
|
78
|
if ( ref $arg eq 'ARRAY' ) { |
51
|
6
|
|
|
|
|
20
|
push @return, map { _single_constraint( $self, $_ ) } @$arg; |
|
7
|
|
|
|
|
25
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
8
|
|
|
|
|
44
|
push @return, _single_constraint( $self, $arg ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
14
|
100
|
|
|
|
98
|
return @return == 1 ? $return[0] : @return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub inflator { |
61
|
13
|
|
|
13
|
0
|
56
|
my ( $self, $arg ) = @_; |
62
|
13
|
|
|
|
|
36
|
my @return; |
63
|
|
|
|
|
|
|
|
64
|
13
|
100
|
|
|
|
82
|
if ( ref $arg eq 'ARRAY' ) { |
65
|
1
|
|
|
|
|
3
|
push @return, map { _single_inflator( $self, $_ ) } @$arg; |
|
1
|
|
|
|
|
6
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
12
|
|
|
|
|
68
|
push @return, _single_inflator( $self, $arg ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
13
|
50
|
|
|
|
97
|
return @return == 1 ? $return[0] : @return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub validator { |
75
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $arg ) = @_; |
76
|
0
|
|
|
|
|
0
|
my @return; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
if ( ref $arg eq 'ARRAY' ) { |
79
|
0
|
|
|
|
|
0
|
push @return, map { _single_validator( $self, $_ ) } @$arg; |
|
0
|
|
|
|
|
0
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
0
|
|
|
|
|
0
|
push @return, _single_validator( $self, $arg ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
0
|
return @return == 1 ? $return[0] : @return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub transformer { |
89
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $arg ) = @_; |
90
|
0
|
|
|
|
|
0
|
my @return; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
0
|
if ( ref $arg eq 'ARRAY' ) { |
93
|
0
|
|
|
|
|
0
|
push @return, map { _single_transformer( $self, $_ ) } @$arg; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
0
|
|
|
|
|
0
|
push @return, _single_transformer( $self, $arg ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
0
|
return @return == 1 ? $return[0] : @return; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub plugin { |
103
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $arg ) = @_; |
104
|
0
|
|
|
|
|
0
|
my @return; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
0
|
if ( ref $arg eq 'ARRAY' ) { |
107
|
0
|
|
|
|
|
0
|
push @return, map { _single_plugin( $self, $_ ) } @$arg; |
|
0
|
|
|
|
|
0
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
0
|
|
|
|
|
0
|
push @return, _single_plugin( $self, $arg ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
0
|
return @return == 1 ? $return[0] : @return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
BEGIN { |
117
|
100
|
|
|
100
|
|
635
|
*constraints = \&constraint; |
118
|
100
|
|
|
|
|
317
|
*filters = \&filter; |
119
|
100
|
|
|
|
|
325
|
*deflators = \&deflator; |
120
|
100
|
|
|
|
|
290
|
*inflators = \&inflator; |
121
|
100
|
|
|
|
|
293
|
*validators = \&validator; |
122
|
100
|
|
|
|
|
262
|
*transformers = \&transformer; |
123
|
100
|
|
|
|
|
73700
|
*plugins = \&plugin; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _single_deflator { |
127
|
11
|
|
|
11
|
|
45
|
my ( $self, $arg ) = @_; |
128
|
|
|
|
|
|
|
|
129
|
11
|
100
|
|
|
|
71
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
130
|
1
|
|
|
|
|
4
|
$arg = { type => $arg }; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
133
|
10
|
|
|
|
|
60
|
$arg = {%$arg}; # shallow clone |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
else { |
136
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
11
|
|
|
|
|
28
|
my @return; |
140
|
|
|
|
|
|
|
|
141
|
11
|
|
|
|
|
36
|
my $type = delete $arg->{type}; |
142
|
|
|
|
|
|
|
|
143
|
11
|
|
|
|
|
130
|
my $new = $self->_require_deflator( $type, $arg ); |
144
|
|
|
|
|
|
|
|
145
|
11
|
|
|
|
|
30
|
push @{ $self->_deflators }, $new; |
|
11
|
|
|
|
|
427
|
|
146
|
|
|
|
|
|
|
|
147
|
11
|
|
|
|
|
60
|
return $new; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _single_filter { |
151
|
7
|
|
|
7
|
|
25
|
my ( $self, $arg ) = @_; |
152
|
|
|
|
|
|
|
|
153
|
7
|
100
|
|
|
|
38
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
154
|
1
|
|
|
|
|
4
|
$arg = { type => $arg }; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
157
|
6
|
|
|
|
|
35
|
$arg = {%$arg}; # shallow clone |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
else { |
160
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
7
|
|
|
|
|
20
|
my @return; |
164
|
|
|
|
|
|
|
|
165
|
7
|
|
|
|
|
19
|
my $type = delete $arg->{type}; |
166
|
|
|
|
|
|
|
|
167
|
7
|
|
|
|
|
80
|
my $new = $self->_require_filter( $type, $arg ); |
168
|
|
|
|
|
|
|
|
169
|
7
|
|
|
|
|
17
|
push @{ $self->_filters }, $new; |
|
7
|
|
|
|
|
244
|
|
170
|
|
|
|
|
|
|
|
171
|
7
|
|
|
|
|
35
|
return $new; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub _single_constraint { |
175
|
15
|
|
|
15
|
|
63
|
my ( $self, $arg ) = @_; |
176
|
|
|
|
|
|
|
|
177
|
15
|
100
|
|
|
|
67
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
178
|
11
|
|
|
|
|
52
|
$arg = { type => $arg }; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
181
|
4
|
|
|
|
|
27
|
$arg = {%$arg}; # shallow clone |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
else { |
184
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
15
|
|
|
|
|
66
|
my @return; |
188
|
|
|
|
|
|
|
|
189
|
15
|
|
|
|
|
52
|
my $type = delete $arg->{type}; |
190
|
|
|
|
|
|
|
|
191
|
15
|
|
|
|
|
137
|
my $new = $self->_require_constraint( $type, $arg ); |
192
|
|
|
|
|
|
|
|
193
|
15
|
|
|
|
|
46
|
push @{ $self->_constraints }, $new; |
|
15
|
|
|
|
|
553
|
|
194
|
|
|
|
|
|
|
|
195
|
15
|
|
|
|
|
77
|
return $new; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _single_inflator { |
199
|
13
|
|
|
13
|
|
54
|
my ( $self, $arg ) = @_; |
200
|
|
|
|
|
|
|
|
201
|
13
|
50
|
|
|
|
142
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
202
|
0
|
|
|
|
|
0
|
$arg = { type => $arg }; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
205
|
13
|
|
|
|
|
72
|
$arg = {%$arg}; # shallow clone |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
13
|
|
|
|
|
51
|
my @return; |
212
|
|
|
|
|
|
|
|
213
|
13
|
|
|
|
|
49
|
my $type = delete $arg->{type}; |
214
|
|
|
|
|
|
|
|
215
|
13
|
|
|
|
|
206
|
my $new = $self->_require_inflator( $type, $arg ); |
216
|
|
|
|
|
|
|
|
217
|
13
|
|
|
|
|
38
|
push @{ $self->_inflators }, $new; |
|
13
|
|
|
|
|
539
|
|
218
|
|
|
|
|
|
|
|
219
|
13
|
|
|
|
|
73
|
return $new; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub _single_validator { |
223
|
0
|
|
|
0
|
|
|
my ( $self, $arg ) = @_; |
224
|
|
|
|
|
|
|
|
225
|
0
|
0
|
|
|
|
|
if ( !ref $arg ) { |
|
|
0
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
$arg = { type => $arg }; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
229
|
0
|
|
|
|
|
|
$arg = {%$arg}; # shallow clone |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
else { |
232
|
0
|
|
|
|
|
|
croak 'invalid args'; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
my @return; |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
my $type = delete $arg->{type}; |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
my $new = $self->_require_validator( $type, $arg ); |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
push @{ $self->_validators }, $new; |
|
0
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
return $new; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub _single_transformer { |
247
|
0
|
|
|
0
|
|
|
my ( $self, $arg ) = @_; |
248
|
|
|
|
|
|
|
|
249
|
0
|
0
|
|
|
|
|
if ( !ref $arg ) { |
|
|
0
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
$arg = { type => $arg }; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
253
|
0
|
|
|
|
|
|
$arg = {%$arg}; # shallow clone |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
else { |
256
|
0
|
|
|
|
|
|
croak 'invalid args'; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
my @return; |
260
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
|
my $type = delete $arg->{type}; |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
my $new = $self->_require_transformer( $type, $arg ); |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
push @{ $self->_transformers }, $new; |
|
0
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
return $new; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub _single_plugin { |
271
|
0
|
|
|
0
|
|
|
my ( $self, $arg ) = @_; |
272
|
|
|
|
|
|
|
|
273
|
0
|
0
|
|
|
|
|
if ( !ref $arg ) { |
|
|
0
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
$arg = { type => $arg }; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
277
|
0
|
|
|
|
|
|
$arg = {%$arg}; # shallow clone |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
else { |
280
|
0
|
|
|
|
|
|
croak 'invalid args'; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
my @return; |
284
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
|
my $type = delete $arg->{type}; |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
my $new = $self->_require_plugin( $type, $arg ); |
288
|
|
|
|
|
|
|
|
289
|
0
|
|
|
|
|
|
push @{ $self->_plugins }, $new; |
|
0
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
291
|
0
|
|
|
|
|
|
return $new; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
1; |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
__END__ |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=pod |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=encoding UTF-8 |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 NAME |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
HTML::FormFu::Role::Element::SingleValueField - role for single value fields |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 VERSION |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
version 2.07 |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 AUTHOR |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
319
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=cut |