line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Tiny::FieldDefinitionBuilder; |
2
|
|
|
|
|
|
|
$Form::Tiny::FieldDefinitionBuilder::VERSION = '2.20'; |
3
|
51
|
|
|
51
|
|
684
|
use v5.10; |
|
51
|
|
|
|
|
195
|
|
4
|
51
|
|
|
51
|
|
298
|
use strict; |
|
51
|
|
|
|
|
141
|
|
|
51
|
|
|
|
|
1107
|
|
5
|
51
|
|
|
51
|
|
260
|
use warnings; |
|
51
|
|
|
|
|
123
|
|
|
51
|
|
|
|
|
1471
|
|
6
|
51
|
|
|
51
|
|
284
|
use Moo; |
|
51
|
|
|
|
|
113
|
|
|
51
|
|
|
|
|
357
|
|
7
|
51
|
|
|
51
|
|
17977
|
use Carp qw(croak); |
|
51
|
|
|
|
|
149
|
|
|
51
|
|
|
|
|
2829
|
|
8
|
51
|
|
|
51
|
|
433
|
use Scalar::Util qw(blessed); |
|
51
|
|
|
|
|
183
|
|
|
51
|
|
|
|
|
2538
|
|
9
|
51
|
|
|
51
|
|
372
|
use Types::Standard qw(HashRef); |
|
51
|
|
|
|
|
145
|
|
|
51
|
|
|
|
|
363
|
|
10
|
|
|
|
|
|
|
|
11
|
51
|
|
|
51
|
|
96020
|
use Form::Tiny::FieldDefinition; |
|
51
|
|
|
|
|
222
|
|
|
51
|
|
|
|
|
2366
|
|
12
|
51
|
|
|
51
|
|
454
|
use Form::Tiny::Utils qw(has_form_meta); |
|
51
|
|
|
|
|
133
|
|
|
51
|
|
|
|
|
16706
|
|
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
|
298
|
|
|
298
|
0
|
7361
|
my ($self, $context) = @_; |
29
|
|
|
|
|
|
|
|
30
|
298
|
|
|
|
|
790
|
my $data = $self->build_data; |
31
|
298
|
|
|
|
|
724
|
my $dynamic = ref $data eq 'CODE'; |
32
|
298
|
100
|
100
|
|
|
1354
|
if ($dynamic && defined blessed $context) { |
33
|
6
|
50
|
|
|
|
43
|
croak 'building a dynamic field definition requires Form::Tiny form' |
34
|
|
|
|
|
|
|
unless has_form_meta($context); |
35
|
6
|
|
|
|
|
73
|
$data = $data->($context); |
36
|
6
|
|
|
|
|
55
|
$dynamic = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
298
|
100
|
|
|
|
717
|
return $self if $dynamic; |
40
|
|
|
|
|
|
|
|
41
|
293
|
|
|
|
|
457
|
my $definition; |
42
|
293
|
100
|
66
|
|
|
1439
|
if (defined blessed $data && $data->isa('Form::Tiny::FieldDefinition')) { |
|
|
50
|
|
|
|
|
|
43
|
2
|
|
|
|
|
5
|
$definition = $data; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (ref $data eq 'HASH') { |
46
|
291
|
|
|
|
|
4908
|
$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
|
286
|
|
|
|
|
5623
|
$definition->set_addons($self->addons); |
54
|
|
|
|
|
|
|
|
55
|
286
|
|
|
|
|
7403
|
return $definition; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|