line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Form::Tiny::FieldDefinitionBuilder; |
2
|
|
|
|
|
|
|
$Form::Tiny::FieldDefinitionBuilder::VERSION = '2.19'; |
3
|
51
|
|
|
51
|
|
700
|
use v5.10; |
|
51
|
|
|
|
|
238
|
|
4
|
51
|
|
|
51
|
|
307
|
use strict; |
|
51
|
|
|
|
|
142
|
|
|
51
|
|
|
|
|
1110
|
|
5
|
51
|
|
|
51
|
|
272
|
use warnings; |
|
51
|
|
|
|
|
105
|
|
|
51
|
|
|
|
|
1377
|
|
6
|
51
|
|
|
51
|
|
283
|
use Moo; |
|
51
|
|
|
|
|
123
|
|
|
51
|
|
|
|
|
350
|
|
7
|
51
|
|
|
51
|
|
17661
|
use Carp qw(croak); |
|
51
|
|
|
|
|
226
|
|
|
51
|
|
|
|
|
2745
|
|
8
|
51
|
|
|
51
|
|
438
|
use Scalar::Util qw(blessed); |
|
51
|
|
|
|
|
169
|
|
|
51
|
|
|
|
|
2574
|
|
9
|
51
|
|
|
51
|
|
396
|
use Types::Standard qw(HashRef); |
|
51
|
|
|
|
|
137
|
|
|
51
|
|
|
|
|
353
|
|
10
|
|
|
|
|
|
|
|
11
|
51
|
|
|
51
|
|
96573
|
use Form::Tiny::FieldDefinition; |
|
51
|
|
|
|
|
212
|
|
|
51
|
|
|
|
|
2369
|
|
12
|
51
|
|
|
51
|
|
485
|
use Form::Tiny::Utils qw(has_form_meta); |
|
51
|
|
|
|
|
127
|
|
|
51
|
|
|
|
|
16676
|
|
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
|
7273
|
my ($self, $context) = @_; |
29
|
|
|
|
|
|
|
|
30
|
298
|
|
|
|
|
799
|
my $data = $self->build_data; |
31
|
298
|
|
|
|
|
732
|
my $dynamic = ref $data eq 'CODE'; |
32
|
298
|
100
|
100
|
|
|
921
|
if ($dynamic && defined blessed $context) { |
33
|
6
|
50
|
|
|
|
35
|
croak 'building a dynamic field definition requires Form::Tiny form' |
34
|
|
|
|
|
|
|
unless has_form_meta($context); |
35
|
6
|
|
|
|
|
61
|
$data = $data->($context); |
36
|
6
|
|
|
|
|
54
|
$dynamic = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
298
|
100
|
|
|
|
670
|
return $self if $dynamic; |
40
|
|
|
|
|
|
|
|
41
|
293
|
|
|
|
|
453
|
my $definition; |
42
|
293
|
100
|
66
|
|
|
1450
|
if (defined blessed $data && $data->isa('Form::Tiny::FieldDefinition')) { |
|
|
50
|
|
|
|
|
|
43
|
2
|
|
|
|
|
5
|
$definition = $data; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (ref $data eq 'HASH') { |
46
|
291
|
|
|
|
|
4857
|
$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
|
|
|
|
|
5640
|
$definition->set_addons($self->addons); |
54
|
|
|
|
|
|
|
|
55
|
286
|
|
|
|
|
7470
|
return $definition; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|