line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Role::Element::FieldMethods; |
2
|
|
|
|
|
|
|
|
3
|
322
|
|
|
322
|
|
176577
|
use strict; |
|
322
|
|
|
|
|
509
|
|
|
322
|
|
|
|
|
14021
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
322
|
|
|
322
|
|
1213
|
use Moose::Role; |
|
322
|
|
|
|
|
445
|
|
|
322
|
|
|
|
|
1973
|
|
7
|
|
|
|
|
|
|
|
8
|
322
|
|
|
322
|
|
1094174
|
use Carp qw( croak ); |
|
322
|
|
|
|
|
529
|
|
|
322
|
|
|
|
|
213551
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub nested_name { |
11
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
12
|
|
|
|
|
|
|
|
13
|
0
|
0
|
|
|
|
0
|
croak 'cannot set nested_name' if @_ > 1; |
14
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
0
|
return if !defined $self->name; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
my @names = $self->nested_names; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
0
|
if ( $self->form->nested_subscript ) { |
20
|
0
|
|
|
|
|
0
|
my $name = shift @names; |
21
|
0
|
|
|
|
|
0
|
map { $name .= "[$_]" } @names; |
|
0
|
|
|
|
|
0
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# TODO - Mario Minati 19.05.2009 |
24
|
|
|
|
|
|
|
# Does this (name formatted as '[name]') collide with FF::Model::HashRef as |
25
|
|
|
|
|
|
|
# it uses /_\d/ to parse repeatable names? |
26
|
0
|
|
|
|
|
0
|
return $name; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
0
|
|
|
|
|
0
|
return join ".", @names; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub add_error { |
34
|
193
|
|
|
193
|
0
|
642
|
my ( $self, @errors ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
193
|
|
|
|
|
252
|
push @{ $self->_errors }, @errors; |
|
193
|
|
|
|
|
5090
|
|
37
|
|
|
|
|
|
|
|
38
|
193
|
|
|
|
|
524
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub deflator { |
42
|
13
|
|
|
13
|
0
|
20
|
my ( $self, $arg ) = @_; |
43
|
13
|
|
|
|
|
18
|
my @return; |
44
|
|
|
|
|
|
|
|
45
|
13
|
100
|
|
|
|
43
|
if ( ref $arg eq 'ARRAY' ) { |
46
|
4
|
|
|
|
|
9
|
push @return, map { _single_deflator( $self, $_ ) } @$arg; |
|
4
|
|
|
|
|
14
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
9
|
|
|
|
|
28
|
push @return, _single_deflator( $self, $arg ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
13
|
50
|
|
|
|
76
|
return @return == 1 ? $return[0] : @return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub filter { |
56
|
29
|
|
|
29
|
0
|
51
|
my ( $self, $arg ) = @_; |
57
|
29
|
|
|
|
|
42
|
my @return; |
58
|
|
|
|
|
|
|
|
59
|
29
|
100
|
|
|
|
98
|
if ( ref $arg eq 'ARRAY' ) { |
60
|
12
|
|
|
|
|
25
|
push @return, map { _single_filter( $self, $_ ) } @$arg; |
|
12
|
|
|
|
|
49
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
17
|
|
|
|
|
66
|
push @return, _single_filter( $self, $arg ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
29
|
50
|
|
|
|
265
|
return @return == 1 ? $return[0] : @return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub constraint { |
70
|
134
|
|
|
134
|
0
|
276
|
my ( $self, $arg ) = @_; |
71
|
134
|
|
|
|
|
205
|
my @return; |
72
|
|
|
|
|
|
|
|
73
|
134
|
100
|
|
|
|
445
|
if ( ref $arg eq 'ARRAY' ) { |
74
|
54
|
|
|
|
|
111
|
push @return, map { _single_constraint( $self, $_ ) } @$arg; |
|
62
|
|
|
|
|
193
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
80
|
|
|
|
|
298
|
push @return, _single_constraint( $self, $arg ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
134
|
100
|
|
|
|
1523
|
return @return == 1 ? $return[0] : @return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub inflator { |
84
|
14
|
|
|
14
|
0
|
30
|
my ( $self, $arg ) = @_; |
85
|
14
|
|
|
|
|
27
|
my @return; |
86
|
|
|
|
|
|
|
|
87
|
14
|
100
|
|
|
|
47
|
if ( ref $arg eq 'ARRAY' ) { |
88
|
3
|
|
|
|
|
8
|
push @return, map { _single_inflator( $self, $_ ) } @$arg; |
|
3
|
|
|
|
|
12
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
11
|
|
|
|
|
37
|
push @return, _single_inflator( $self, $arg ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
14
|
50
|
|
|
|
134
|
return @return == 1 ? $return[0] : @return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub validator { |
98
|
3
|
|
|
3
|
0
|
5
|
my ( $self, $arg ) = @_; |
99
|
3
|
|
|
|
|
4
|
my @return; |
100
|
|
|
|
|
|
|
|
101
|
3
|
50
|
|
|
|
10
|
if ( ref $arg eq 'ARRAY' ) { |
102
|
0
|
|
|
|
|
0
|
push @return, map { _single_validator( $self, $_ ) } @$arg; |
|
0
|
|
|
|
|
0
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
3
|
|
|
|
|
12
|
push @return, _single_validator( $self, $arg ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
3
|
50
|
|
|
|
101
|
return @return == 1 ? $return[0] : @return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub transformer { |
112
|
5
|
|
|
5
|
0
|
6
|
my ( $self, $arg ) = @_; |
113
|
5
|
|
|
|
|
7
|
my @return; |
114
|
|
|
|
|
|
|
|
115
|
5
|
50
|
|
|
|
15
|
if ( ref $arg eq 'ARRAY' ) { |
116
|
0
|
|
|
|
|
0
|
push @return, map { _single_transformer( $self, $_ ) } @$arg; |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
5
|
|
|
|
|
16
|
push @return, _single_transformer( $self, $arg ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
5
|
50
|
|
|
|
144
|
return @return == 1 ? $return[0] : @return; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub plugin { |
126
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $arg ) = @_; |
127
|
1
|
|
|
|
|
1
|
my @return; |
128
|
|
|
|
|
|
|
|
129
|
1
|
50
|
|
|
|
3
|
if ( ref $arg eq 'ARRAY' ) { |
130
|
0
|
|
|
|
|
0
|
push @return, map { _single_plugin( $self, $_ ) } @$arg; |
|
0
|
|
|
|
|
0
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
1
|
|
|
|
|
4
|
push @return, _single_plugin( $self, $arg ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
1
|
50
|
|
|
|
6
|
return @return == 1 ? $return[0] : @return; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
BEGIN { |
140
|
322
|
|
|
322
|
|
979
|
*constraints = \&constraint; |
141
|
322
|
|
|
|
|
627
|
*filters = \&filter; |
142
|
322
|
|
|
|
|
495
|
*deflators = \&deflator; |
143
|
322
|
|
|
|
|
478
|
*inflators = \&inflator; |
144
|
322
|
|
|
|
|
479
|
*validators = \&validator; |
145
|
322
|
|
|
|
|
487
|
*transformers = \&transformer; |
146
|
322
|
|
|
|
|
167676
|
*plugins = \&plugin; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _single_deflator { |
150
|
13
|
|
|
13
|
|
17
|
my ( $self, $arg ) = @_; |
151
|
|
|
|
|
|
|
|
152
|
13
|
100
|
|
|
|
51
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
153
|
1
|
|
|
|
|
3
|
$arg = { type => $arg }; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
156
|
12
|
|
|
|
|
52
|
$arg = {%$arg}; # shallow clone |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else { |
159
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
13
|
|
|
|
|
17
|
my @return; |
163
|
|
|
|
|
|
|
|
164
|
13
|
|
|
|
|
29
|
my $type = delete $arg->{type}; |
165
|
|
|
|
|
|
|
|
166
|
13
|
|
|
|
|
90
|
my $new = $self->_require_deflator( $type, $arg ); |
167
|
|
|
|
|
|
|
|
168
|
13
|
|
|
|
|
20
|
push @{ $self->_deflators }, $new; |
|
13
|
|
|
|
|
369
|
|
169
|
|
|
|
|
|
|
|
170
|
13
|
|
|
|
|
42
|
return $new; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub _single_filter { |
174
|
29
|
|
|
29
|
|
49
|
my ( $self, $arg ) = @_; |
175
|
|
|
|
|
|
|
|
176
|
29
|
100
|
|
|
|
109
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
177
|
19
|
|
|
|
|
44
|
$arg = { type => $arg }; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
180
|
10
|
|
|
|
|
50
|
$arg = {%$arg}; # shallow clone |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
else { |
183
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
29
|
|
|
|
|
49
|
my @return; |
187
|
|
|
|
|
|
|
|
188
|
29
|
|
|
|
|
55
|
my $type = delete $arg->{type}; |
189
|
|
|
|
|
|
|
|
190
|
29
|
|
|
|
|
210
|
my $new = $self->_require_filter( $type, $arg ); |
191
|
|
|
|
|
|
|
|
192
|
29
|
|
|
|
|
43
|
push @{ $self->_filters }, $new; |
|
29
|
|
|
|
|
767
|
|
193
|
|
|
|
|
|
|
|
194
|
29
|
|
|
|
|
91
|
return $new; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub _single_constraint { |
198
|
142
|
|
|
142
|
|
243
|
my ( $self, $arg ) = @_; |
199
|
|
|
|
|
|
|
|
200
|
142
|
100
|
|
|
|
457
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
201
|
88
|
|
|
|
|
266
|
$arg = { type => $arg }; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
204
|
54
|
|
|
|
|
237
|
$arg = {%$arg}; # shallow clone |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
else { |
207
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
142
|
|
|
|
|
215
|
my @return; |
211
|
|
|
|
|
|
|
|
212
|
142
|
|
|
|
|
304
|
my $type = delete $arg->{type}; |
213
|
|
|
|
|
|
|
|
214
|
142
|
|
|
|
|
706
|
my $new = $self->_require_constraint( $type, $arg ); |
215
|
|
|
|
|
|
|
|
216
|
142
|
|
|
|
|
226
|
push @{ $self->_constraints }, $new; |
|
142
|
|
|
|
|
4076
|
|
217
|
|
|
|
|
|
|
|
218
|
142
|
|
|
|
|
478
|
return $new; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _single_inflator { |
222
|
14
|
|
|
14
|
|
20
|
my ( $self, $arg ) = @_; |
223
|
|
|
|
|
|
|
|
224
|
14
|
100
|
|
|
|
61
|
if ( !ref $arg ) { |
|
|
50
|
|
|
|
|
|
225
|
9
|
|
|
|
|
37
|
$arg = { type => $arg }; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
228
|
5
|
|
|
|
|
23
|
$arg = {%$arg}; # shallow clone |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
else { |
231
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
14
|
|
|
|
|
20
|
my @return; |
235
|
|
|
|
|
|
|
|
236
|
14
|
|
|
|
|
32
|
my $type = delete $arg->{type}; |
237
|
|
|
|
|
|
|
|
238
|
14
|
|
|
|
|
110
|
my $new = $self->_require_inflator( $type, $arg ); |
239
|
|
|
|
|
|
|
|
240
|
14
|
|
|
|
|
26
|
push @{ $self->_inflators }, $new; |
|
14
|
|
|
|
|
442
|
|
241
|
|
|
|
|
|
|
|
242
|
14
|
|
|
|
|
54
|
return $new; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub _single_validator { |
246
|
3
|
|
|
3
|
|
4
|
my ( $self, $arg ) = @_; |
247
|
|
|
|
|
|
|
|
248
|
3
|
50
|
|
|
|
6
|
if ( !ref $arg ) { |
|
|
0
|
|
|
|
|
|
249
|
3
|
|
|
|
|
8
|
$arg = { type => $arg }; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
252
|
0
|
|
|
|
|
0
|
$arg = {%$arg}; # shallow clone |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
else { |
255
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
3
|
|
|
|
|
4
|
my @return; |
259
|
|
|
|
|
|
|
|
260
|
3
|
|
|
|
|
5
|
my $type = delete $arg->{type}; |
261
|
|
|
|
|
|
|
|
262
|
3
|
|
|
|
|
18
|
my $new = $self->_require_validator( $type, $arg ); |
263
|
|
|
|
|
|
|
|
264
|
3
|
|
|
|
|
3
|
push @{ $self->_validators }, $new; |
|
3
|
|
|
|
|
85
|
|
265
|
|
|
|
|
|
|
|
266
|
3
|
|
|
|
|
8
|
return $new; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub _single_transformer { |
270
|
5
|
|
|
5
|
|
5
|
my ( $self, $arg ) = @_; |
271
|
|
|
|
|
|
|
|
272
|
5
|
50
|
|
|
|
11
|
if ( !ref $arg ) { |
|
|
0
|
|
|
|
|
|
273
|
5
|
|
|
|
|
11
|
$arg = { type => $arg }; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
276
|
0
|
|
|
|
|
0
|
$arg = {%$arg}; # shallow clone |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
else { |
279
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
5
|
|
|
|
|
7
|
my @return; |
283
|
|
|
|
|
|
|
|
284
|
5
|
|
|
|
|
9
|
my $type = delete $arg->{type}; |
285
|
|
|
|
|
|
|
|
286
|
5
|
|
|
|
|
23
|
my $new = $self->_require_transformer( $type, $arg ); |
287
|
|
|
|
|
|
|
|
288
|
5
|
|
|
|
|
7
|
push @{ $self->_transformers }, $new; |
|
5
|
|
|
|
|
150
|
|
289
|
|
|
|
|
|
|
|
290
|
5
|
|
|
|
|
13
|
return $new; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub _single_plugin { |
294
|
1
|
|
|
1
|
|
1
|
my ( $self, $arg ) = @_; |
295
|
|
|
|
|
|
|
|
296
|
1
|
50
|
|
|
|
5
|
if ( !ref $arg ) { |
|
|
0
|
|
|
|
|
|
297
|
1
|
|
|
|
|
3
|
$arg = { type => $arg }; |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
elsif ( ref $arg eq 'HASH' ) { |
300
|
0
|
|
|
|
|
0
|
$arg = {%$arg}; # shallow clone |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
else { |
303
|
0
|
|
|
|
|
0
|
croak 'invalid args'; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
1
|
|
|
|
|
1
|
my @return; |
307
|
|
|
|
|
|
|
|
308
|
1
|
|
|
|
|
2
|
my $type = delete $arg->{type}; |
309
|
|
|
|
|
|
|
|
310
|
1
|
|
|
|
|
16
|
my $new = $self->_require_plugin( $type, $arg ); |
311
|
|
|
|
|
|
|
|
312
|
1
|
|
|
|
|
2
|
push @{ $self->_plugins }, $new; |
|
1
|
|
|
|
|
29
|
|
313
|
|
|
|
|
|
|
|
314
|
1
|
|
|
|
|
3
|
return $new; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
1; |