line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Tiny::FieldDefinitionBuilder; |
2
|
|
|
|
|
|
|
$Form::Tiny::FieldDefinitionBuilder::VERSION = '2.21'; |
3
|
52
|
|
|
52
|
|
671
|
use v5.10; |
|
52
|
|
|
|
|
209
|
|
4
|
52
|
|
|
52
|
|
305
|
use strict; |
|
52
|
|
|
|
|
130
|
|
|
52
|
|
|
|
|
1041
|
|
5
|
52
|
|
|
52
|
|
269
|
use warnings; |
|
52
|
|
|
|
|
123
|
|
|
52
|
|
|
|
|
1318
|
|
6
|
52
|
|
|
52
|
|
270
|
use Moo; |
|
52
|
|
|
|
|
123
|
|
|
52
|
|
|
|
|
373
|
|
7
|
52
|
|
|
52
|
|
17908
|
use Carp qw(croak); |
|
52
|
|
|
|
|
146
|
|
|
52
|
|
|
|
|
2827
|
|
8
|
52
|
|
|
52
|
|
436
|
use Scalar::Util qw(blessed); |
|
52
|
|
|
|
|
137
|
|
|
52
|
|
|
|
|
2453
|
|
9
|
52
|
|
|
52
|
|
382
|
use Types::Standard qw(HashRef); |
|
52
|
|
|
|
|
151
|
|
|
52
|
|
|
|
|
372
|
|
10
|
|
|
|
|
|
|
|
11
|
52
|
|
|
52
|
|
95434
|
use Form::Tiny::FieldDefinition; |
|
52
|
|
|
|
|
560
|
|
|
52
|
|
|
|
|
2329
|
|
12
|
52
|
|
|
52
|
|
478
|
use Form::Tiny::Utils qw(has_form_meta); |
|
52
|
|
|
|
|
124
|
|
|
52
|
|
|
|
|
16189
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'build_data' => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'addons' => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => HashRef, |
22
|
|
|
|
|
|
|
default => sub { {} }, |
23
|
|
|
|
|
|
|
init_arg => undef, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub build |
27
|
|
|
|
|
|
|
{ |
28
|
301
|
|
|
301
|
0
|
7253
|
my ($self, $context) = @_; |
29
|
|
|
|
|
|
|
|
30
|
301
|
|
|
|
|
791
|
my $data = $self->build_data; |
31
|
301
|
|
|
|
|
780
|
my $dynamic = ref $data eq 'CODE'; |
32
|
301
|
100
|
100
|
|
|
923
|
if ($dynamic && defined blessed $context) { |
33
|
6
|
50
|
|
|
|
21
|
croak 'building a dynamic field definition requires Form::Tiny form' |
34
|
|
|
|
|
|
|
unless has_form_meta($context); |
35
|
6
|
|
|
|
|
41
|
$data = $data->($context); |
36
|
6
|
|
|
|
|
47
|
$dynamic = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
301
|
100
|
|
|
|
662
|
return $self if $dynamic; |
40
|
|
|
|
|
|
|
|
41
|
296
|
|
|
|
|
450
|
my $definition; |
42
|
296
|
100
|
66
|
|
|
1356
|
if (defined blessed $data && $data->isa('Form::Tiny::FieldDefinition')) { |
|
|
50
|
|
|
|
|
|
43
|
2
|
|
|
|
|
5
|
$definition = $data; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (ref $data eq 'HASH') { |
46
|
294
|
|
|
|
|
4824
|
$definition = Form::Tiny::FieldDefinition->new($data); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
0
|
croak sprintf q{Invalid form field '%s' data: must be hashref or instance of Form::Tiny::FieldDefinition}, |
50
|
|
|
|
|
|
|
$self->name; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
289
|
|
|
|
|
5678
|
$definition->set_addons($self->addons); |
54
|
|
|
|
|
|
|
|
55
|
289
|
|
|
|
|
7335
|
return $definition; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|