line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
405
|
|
|
405
|
|
285380
|
use strict; |
|
405
|
|
|
|
|
1031
|
|
|
405
|
|
|
|
|
22725
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Role::Populate; |
4
|
|
|
|
|
|
|
# ABSTRACT: Populate role |
5
|
|
|
|
|
|
|
$HTML::FormFu::Role::Populate::VERSION = '2.07'; |
6
|
405
|
|
|
405
|
|
2562
|
use Moose::Role; |
|
405
|
|
|
|
|
857
|
|
|
405
|
|
|
|
|
3723
|
|
7
|
|
|
|
|
|
|
|
8
|
405
|
|
|
405
|
|
2243584
|
use Scalar::Util qw( reftype ); |
|
405
|
|
|
|
|
1019
|
|
|
405
|
|
|
|
|
22395
|
|
9
|
405
|
|
|
405
|
|
15947
|
use Carp qw( croak ); |
|
405
|
|
|
|
|
1143
|
|
|
405
|
|
|
|
|
192214
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
after BUILD => sub { |
12
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$args ||= {}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# get args handled by Moose so they aren't set twice |
17
|
|
|
|
|
|
|
my %init_args = map { $_->{init_arg} => 1 } |
18
|
|
|
|
|
|
|
grep { defined $_->{init_arg} } $self->meta->get_all_attributes; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# remove defaults set in HTML::FormFu::BUILD because they need to be set for a third time |
21
|
|
|
|
|
|
|
delete @init_args{ keys %{$HTML::FormFu::build_defaults} }; |
22
|
|
|
|
|
|
|
my %args |
23
|
|
|
|
|
|
|
= map { $_ => $args->{$_} } grep { !exists $init_args{$_} } keys %$args; |
24
|
|
|
|
|
|
|
$self->populate( \%args ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
return; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub populate { |
30
|
6866
|
|
|
6866
|
0
|
16015
|
my ( $self, $arg_ref ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
6866
|
50
|
|
|
|
29101
|
croak "argument to populate() must be a hash-ref" |
33
|
|
|
|
|
|
|
if reftype($arg_ref) ne 'HASH'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# shallow clone the args so we don't stomp on them |
36
|
6866
|
|
|
|
|
22636
|
my %args = %$arg_ref; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# we have to handle element_defaults seperately, as it is no longer a |
39
|
|
|
|
|
|
|
# simple hash key |
40
|
|
|
|
|
|
|
|
41
|
6866
|
50
|
|
|
|
18386
|
if ( exists $args{element_defaults} ) { |
42
|
0
|
|
|
|
|
0
|
$self->element_defaults( delete $args{element_defaults} ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# handle any 'roles' first |
46
|
6866
|
|
|
|
|
13435
|
my $roles = delete $args{roles}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# notes for @defer_keys... |
49
|
|
|
|
|
|
|
# 'options', 'values', 'value_range' is for _Group elements, |
50
|
|
|
|
|
|
|
# to ensure any 'empty_first' value gets set first |
51
|
|
|
|
|
|
|
|
52
|
6866
|
|
|
|
|
33593
|
my @defer_keys = qw( |
53
|
|
|
|
|
|
|
default_args |
54
|
|
|
|
|
|
|
auto_fieldset |
55
|
|
|
|
|
|
|
load_config_file |
56
|
|
|
|
|
|
|
element elements |
57
|
|
|
|
|
|
|
default_values |
58
|
|
|
|
|
|
|
constraints_from_dbic |
59
|
|
|
|
|
|
|
filter filters |
60
|
|
|
|
|
|
|
constraint constraints |
61
|
|
|
|
|
|
|
inflator inflators |
62
|
|
|
|
|
|
|
deflator deflators |
63
|
|
|
|
|
|
|
query |
64
|
|
|
|
|
|
|
validator validators |
65
|
|
|
|
|
|
|
transformer transformers |
66
|
|
|
|
|
|
|
plugins |
67
|
|
|
|
|
|
|
options |
68
|
|
|
|
|
|
|
values |
69
|
|
|
|
|
|
|
value_range |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
6866
|
|
|
|
|
11713
|
my %defer; |
73
|
6866
|
|
|
|
|
15081
|
for (@defer_keys) { |
74
|
164784
|
100
|
|
|
|
286465
|
$defer{$_} = delete $args{$_} if exists $args{$_}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
6866
|
|
|
|
|
12573
|
eval { |
78
|
6866
|
100
|
|
|
|
15517
|
if ($roles) { |
79
|
3
|
|
|
|
|
26
|
$self->roles($roles); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
6866
|
|
|
|
|
14625
|
map { $self->$_( delete $args{$_} ) } keys %args; |
|
6382
|
|
|
|
|
88137
|
|
83
|
|
|
|
|
|
|
|
84
|
614
|
|
|
|
|
4537
|
map { $self->$_( $defer{$_} ) } |
85
|
6865
|
|
|
|
|
14224
|
grep { exists $defer{$_} } @defer_keys; |
|
164760
|
|
|
|
|
252143
|
|
86
|
|
|
|
|
|
|
}; |
87
|
6866
|
100
|
|
|
|
17560
|
croak $@ if $@; |
88
|
|
|
|
|
|
|
|
89
|
6865
|
|
|
|
|
23980
|
return $self; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=pod |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=encoding UTF-8 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
HTML::FormFu::Role::Populate - Populate role |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 VERSION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
version 2.07 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
117
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |