MuForm/Fields.pm

filter: Statementstmt 98.6% 365 / 370 Branchbran 85.6% 149 / 174 Conditioncond 81.5% 115 / 141 MC/DCmcdc 63.1% 48 / 76 Subroutinesub 100% 55 / 55 Podpod 0.0% 0 / 38 totaltotal 85.7% 732 / 854 SCAR 51.2
CC
154
Cov
92%
_update_or_create
18.2
fill_from_object
17.3
_get_value
17.1
CRAP 167.0
« MuForm/Field.pm ↑ Summary MuForm/Renderer/Base.pm »
1 package Data::MuForm::Fields;
2 # ABSTRACT: Common attributes and methods for forms and compound fields
3 82 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 82 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 82 ▶use Type::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 82 ▶use Data::Clone ('data_clone');
Subroutine BEGIN: called CC=1 SCAR=0.0
8 82 ▶use Class::Load ('load_optional_class');
Subroutine BEGIN: called CC=1 SCAR=0.0
9 82 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 82 with 'Data::MuForm::Common';
11  
12  
13 133 ▶has 'value' => ( is => 'rw', predicate => 'has_value', default => sub {{}} );
Subroutine __ANON__: called CC=1 SCAR=0.0
14 133 ▶sub clear_value { $_[0]->{value} = {} }
Subroutine clear_value: called CC=1 SCAR=0.0
Pod undocumented
15 7 ▶sub values { $_[0]->value }
Subroutine values: called CC=1 SCAR=0.0
Pod undocumented
16 82 has 'init_value' => ( is => 'rw', clearer => 'clear_init_value' );
17 82 has 'input' => ( is => 'rw', clearer => 'clear_input' );
18 82 has 'skip_fields_without_input' => ( is => 'rw' ); # except 'input_without_param'
19 82 has 'filled_from' => ( is => 'rw', clearer => 'clear_filled_from' );
20 82 has 'meta_fields' => ( is => 'rw' );
21 82 has 'field_list' => ( is => 'rw', isa => ArrayRef, lazy => 1, builder => 'build_field_list' );
22 223 ▶sub build_field_list {[]}
Subroutine build_field_list: called CC=1 SCAR=0.0
Pod undocumented
23 229 ▶has 'fields' => ( is => 'rw', isa => ArrayRef, default => sub {[]});
Subroutine __ANON__: called CC=1 SCAR=0.0
24 1050 ▶sub push_field { my ( $self, @fields ) = @_; push @{$self->{fields}}, @fields; }
Subroutine push_field: called CC=1 SCAR=0.0
Pod undocumented
25 85 ▶sub clear_fields { my $self = shift; $self->{fields} = undef; }
Subroutine clear_fields: called CC=1 SCAR=0.0
Pod undocumented
26 2080 ▶sub all_fields { my $self = shift; return @{$self->{fields}}; }
Subroutine all_fields: called CC=1 SCAR=0.0
Pod undocumented
27 5 ▶sub set_field_at { my ( $self, $index, $field ) = @_; @{$self->{fields}}[$index] = $field; }
Subroutine set_field_at: called CC=1 SCAR=0.0
Pod undocumented
28 60 ▶sub num_fields { my $self = shift; return scalar (@{$self->{fields}}); }
Subroutine num_fields: called CC=1 SCAR=0.0
Pod undocumented
29 776 ▶sub has_fields { my $self = shift; return scalar (@{$self->{fields}}); }
Subroutine has_fields: called CC=1 SCAR=0.0
Pod undocumented
30 229 ▶has 'error_fields' => ( is => 'rw', isa => ArrayRef, default => sub {[]} );
Subroutine __ANON__: called CC=1 SCAR=0.0
31 308 ▶sub clear_error_fields { $_[0]->{error_fields} = [] }
Subroutine clear_error_fields: called CC=1 SCAR=0.0
Pod undocumented
32 375 ▶sub has_error_fields { my $self = shift; return scalar @{$self->error_fields}; }
Subroutine has_error_fields: called CC=1 SCAR=0.0
Pod undocumented
33 9 ▶sub num_error_fields { my $self = shift; return scalar @{$self->error_fields}; }
Subroutine num_error_fields: called CC=1 SCAR=0.0
Pod undocumented
34 81 ▶sub add_error_field { my ($self, $field) = @_; push @{$self->error_fields}, $field; }
Subroutine add_error_field: called CC=1 SCAR=0.0
Pod undocumented
35 8 ▶sub all_error_fields { my $self = shift; return @{$self->error_fields}; }
Subroutine all_error_fields: called CC=1 SCAR=0.0
Pod undocumented
36 has 'field_namespace' => (
37 is => 'rw',
38 isa => ArrayRef,
39 builder => 'build_field_namespace',
40 coerce => sub {
41 229 ▶ my $ns = shift;
Subroutine __ANON__: called CC=4 SCAR=14.6
42 229 ▶ return [] unless defined $ns;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ns 0 229 229
43 229 ▶ return $ns if ref $ns eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $ns eq "ARRAY" 227 2 229
44 2 ▶ return [$ns] if length($ns);
Branch: 1 branch
BranchTrueFalseTotal
if length $ns 2 0 2
45 0 return [];
46 },
47 82 );
48 129 ▶sub build_field_namespace { [] }
Subroutine build_field_namespace: called CC=1 SCAR=0.0
Pod undocumented
49  
50 sub subfield {
51 8 ▶ my ( $self, $name ) = @_;
Subroutine subfield: called CC=1 SCAR=0.0
Pod undocumented
52 8 return $self->field($name, $self);
53 }
54  
55 sub field {
56 515 ▶ my ( $self, $name, $f ) = @_;
Subroutine field: called CC=12 SCAR=25.3
Pod undocumented
57  
58 515 my $index;
59 # if this is a full_name for a compound field
60 # walk through the fields to get to it
61 515 ▶ return undef unless ( defined $name );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 515 515
62 515 ▶ if( $self->form && $self == $self->form &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self == $self->form and exists $self->index->{$name}) 436 79 515
Condition83%5/6
$self->form and $self == $self->form and exists $self->index->{$name}
!ll&&!rl&&r
6712436
$self->form and $self == $self->form
!ll&&!rl&&r
067448
MC/DC66%2/3
$self->form and $self == $self->form and exists $self->index->{$name}
$self->form $self == $self->form exists $self->index->{$name}
Truth table75%3/4
A and B and C
A= $self->formB= $self == $self->formC= exists $self->index->{$name}
ABCresult
0XX0
10X0
1100
1111
63 exists $self->index->{$name} ) {
64 436 return $self->index->{$name};
65 }
66 79 ▶ if ( $name =~ /\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\./) { } 12 67 79
67 12 my @names = split /\./, $name;
68 12 ▶ $f ||= $self->form || $self;
Condition50%3/6
$f ||= $self->form || $self
l!l&&r!l&&!r
2100
$self->form || $self
l!l&&r!l&&!r
1000
MC/DC0%0/3
$f ||= $self->form || $self
$f $self->form $self
Truth table0%0/4
A ||= B || C
A= $fB= $self->formC= $self
ABCresult
1XX1
01X1
0011
0000
69 12 foreach my $fname (@names) {
70 30 $f = $f->field($fname);
71 30 ▶ return unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 30 30
72 }
73 12 return $f;
74 }
75 else # not a compound name
76 {
77 67 for my $field ( $self->all_fields ) {
78 96 ▶ return $field if ( $field->name eq $name );
Branch: 1 branch
BranchTrueFalseTotal
if $field->name eq $name 65 31 96
79 }
80 }
81 2 return;
82 }
83  
84 sub all_sorted_fields {
85 762 ▶ my $self = shift;
Subroutine all_sorted_fields: called CC=1 SCAR=0.0
Pod undocumented
86 2059 my @fields = sort { $a->order <=> $b->order }
87 762 grep { $_->is_active } $self->all_fields;
88 762 return @fields;
89 }
90  
91 sub sorted_fields {
92 8 ▶ my $self = shift;
Subroutine sorted_fields: called CC=1 SCAR=0.0
Pod undocumented
93 8 my @fields = $self->all_sorted_fields;
94 8 return \@fields;
95 }
96  
97 sub field_index {
98 586 ▶ my ( $self, $name ) = @_;
Subroutine field_index: called CC=3 SCAR=11.0
Pod undocumented
99 586 my $index = 0;
100 586 for my $field ( $self->all_fields ) {
101 908 ▶ return $index if $field->name eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $field->name eq $name 7 901 908
102 901 $index++;
103 }
104 579 return;
105 }
106  
107 # Repeatable overrides this
108 sub fields_validate {
109 152 ▶ my $self = shift;
Subroutine fields_validate: called CC=10 SCAR=23.1
Pod undocumented
110  
111 152 ▶ return unless $self->has_fields;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_fields 0 152 152
112 # validate all fields
113 152 my %value_hash;
114 152 foreach my $field ( $self->all_sorted_fields ) {
115 438 ▶ next if ( !$field->is_active || $field->disabled );
Branch: 1 branch
BranchTrueFalseTotal
if not $field->is_active or $field->disabled 2 436 438
Condition66%2/3
not $field->is_active or $field->disabled
l!l&&r!l&&!r
02436
MC/DC50%1/2
not $field->is_active or $field->disabled
not $field->is_active $field->disabled
Truth table66%2/3
not(A) or B
A= not $field->is_activeB= $field->disabled
ABresult
1X1
011
000
116 436 ▶ next if ( $self->skip_fields_without_input && ! $field->has_input && ! $field->has_input_without_param );
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_fields_without_input and not $field->has_input and not $field->has_input_without_param 7 429 436
Condition83%5/6
$self->skip_fields_without_input and not $field->has_input and not $field->has_input_without_param
!ll&&!rl&&r
42907
$self->skip_fields_without_input and not $field->has_input
!ll&&!rl&&r
398317
MC/DC66%2/3
$self->skip_fields_without_input and not $field->has_input and not $field->has_input_without_param
$self->skip_fields_without_input not $field->has_input not $field->has_input_without_param
Truth table75%3/4
A and not(B) and not(C)
A= $self->skip_fields_without_inputB= not $field->has_inputC= not $field->has_input_without_param
ABCresult
0XX0
10X0
1100
1111
117 # Validate each field and "inflate" input -> value.
118 429 $field->field_validate; # this calls all the various validation routines
119 429 ▶ $value_hash{ $field->accessor } = $field->value
Branch: 1 branch
BranchTrueFalseTotal
if $field->has_value and not $field->no_update 388 41 429
Condition100%3/3
$field->has_value and not $field->no_update
!ll&&!rl&&r
374388
MC/DC100%2/2
$field->has_value and not $field->no_update
$field->has_value not $field->no_update
Truth table100%3/3
A and not(B)
A= $field->has_valueB= not $field->no_update
ABresult
0X0
100
111
120 if ( $field->has_value && !$field->no_update );
121 }
122 152 $self->value( \%value_hash );
123 }
124  
125 sub fields_fif {
126 111 ▶ my ( $self, $prefix ) = @_;
Subroutine fields_fif: called CC=14 SCAR=26.7
Pod undocumented
127  
128 111 ▶ $prefix ||= '';
Condition100%2/2
$prefix ||= ""
l!l
5358
MC/DC100%1/1
$prefix ||= ""
$prefix
Truth table100%2/2
A
A= $prefix
Aresult
11
00
129 111 ▶ $prefix = $self->field_prefix . "."
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa("Data::MuForm") and $self->field_prefix 1 110 111
Condition100%3/3
$self->isa("Data::MuForm") and $self->field_prefix
!ll&&!rl&&r
53571
MC/DC100%2/2
$self->isa("Data::MuForm") and $self->field_prefix
$self->isa("Data::MuForm") $self->field_prefix
Truth table100%3/3
A and B
A= $self->isa("Data::MuForm")B= $self->field_prefix
ABresult
0X0
100
111
130 if ( $self->isa('Data::MuForm') && $self->field_prefix );
131  
132 111 my %params;
133 111 foreach my $field ( $self->all_sorted_fields ) {
134 296 ▶ next if ( ! $field->is_active || $field->password || $field->no_fif );
Branch: 1 branch
BranchTrueFalseTotal
if not $field->is_active or $field->password or $field->no_fif 7 289 296
Condition50%3/6
not $field->is_active or $field->password or $field->no_fif
l!l&&r!l&&!r
07289
not $field->is_active or $field->password
l!l&&r!l&&!r
00296
MC/DC33%1/3
not $field->is_active or $field->password or $field->no_fif
not $field->is_active $field->password $field->no_fif
Truth table50%2/4
not(A) or B or C
A= not $field->is_activeB= $field->passwordC= $field->no_fif
ABCresult
1XX1
01X1
0011
0000
135 289 my $fif = $field->fif;
136 289 ▶ next if ( !defined $fif || (ref $fif eq 'ARRAY' && ! scalar @{$fif} ) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $fif or ref $fif eq "ARRAY" and not scalar @{$fif;} 1 288 289
Condition83%5/6
not defined $fif or ref $fif eq "ARRAY" and not scalar @{$fif;}
l!l&&r!l&&!r
03286
ref $fif eq "ARRAY" and not scalar @{$fif;}
!ll&&!rl&&r
270181
MC/DC66%2/3
not defined $fif or ref $fif eq "ARRAY" and not scalar @{$fif;}
not defined $fif ref $fif eq "ARRAY" not scalar @{$fif;}
Truth table75%3/4
not(A) or B and not(C)
A= not defined $fifB= ref $fif eq "ARRAY"C= not scalar @{$fif;}
ABCresult
1XX1
0111
00X0
0100
137 288 ▶ if ( $field->has_fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->has_fields) { } 53 235 288
138 # this builds up foo.0.bar.name
139 53 my $next_params = $field->fields_fif( $prefix . $field->name . '.' );
140 53 ▶ next unless $next_params;
Branch: 1 branch
BranchTrueFalseTotal
unless $next_params 0 53 53
141 53 %params = ( %params, %{$next_params} );
142 }
143 else {
144 235 $params{ $prefix . $field->name } = $fif;
145 }
146 }
147 111 ▶ return if !%params;
Branch: 1 branch
BranchTrueFalseTotal
unless %params 0 111 111
148 111 return \%params;
149  
150 }
151  
152 sub fields_get_results {
153 1 ▶ my $self = shift;
Subroutine fields_get_results: called CC=3 SCAR=11.0
Pod undocumented
154  
155 1 my $result = $self->get_result;
156 1 my @field_results;
157 1 foreach my $field ( $self->all_sorted_fields ) {
158 2 ▶ next if ! $field->is_active;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_active 0 2 2
159 2 my $result = $field->get_result;
160 2 push @field_results, $result;
161 }
162 1 $result->{fields} = \@field_results;
163 1 return $result;
164 }
165  
166 #====================================================================
167 # Build Fields
168 #====================================================================
169  
170 sub build_fields {
171 229 ▶ my $self = shift;
Subroutine build_fields: called CC=4 SCAR=13.9
Pod undocumented
172  
173 # process meta fields
174 229 my @meta_fields = $self->_meta_fields;
175 229 $self->meta_fields(\@meta_fields);
176 229 my $meta_fields = data_clone(\@meta_fields);
177 229 $self->process_field_array( $meta_fields );
178  
179 # process field_list
180 228 my $field_list = $self->field_list;
181 228 ▶ $field_list = $self->convert_field_list_to_hashes($field_list)
Branch: 1 branch
BranchTrueFalseTotal
if $field_list->[0] and ref $field_list->[0] ne "HASH" 3 225 228
Condition100%3/3
$field_list->[0] and ref $field_list->[0] ne "HASH"
!ll&&!rl&&r
22323
MC/DC100%2/2
$field_list->[0] and ref $field_list->[0] ne "HASH"
$field_list->[0] ref $field_list->[0] ne "HASH"
Truth table100%3/3
A and B
A= $field_list->[0]B= ref $field_list->[0] ne "HASH"
ABresult
0X0
100
111
182 if $field_list->[0] && ref($field_list->[0]) ne 'HASH';
183 228 $self->process_field_array ( $field_list );
184  
185 228 ▶ return unless $self->has_fields;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_fields 80 148 228
186 148 $self->order_fields;
187 }
188  
189 sub convert_field_list_to_hashes {
190 3 ▶ my ( $self, $field_list ) = @_;
Subroutine convert_field_list_to_hashes: called CC=3 SCAR=11.0
Pod undocumented
191  
192 3 my @new_fields;
193 3 ▶ while (@$field_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$field_list) 8 3 11
194 8 my $name = shift @$field_list;
195 8 my $attr = shift @$field_list;
196 8 ▶ unless ( ref $attr eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $attr eq "HASH") 4 4 8
197 4 $attr = { type => $attr };
198 }
199 8 push @new_fields, { name => $name, %$attr };
200 }
201 3 return \@new_fields;
202 }
203  
204 sub process_field_array {
205 457 ▶ my ( $self, $fields ) = @_;
Subroutine process_field_array: called CC=4 SCAR=13.9
Pod undocumented
206  
207 457 $fields = $self->clean_fields($fields);
208  
209 # TODO: there's got to be a better way of doing this
210 457 my $num_fields = scalar @$fields;
211 457 my $num_dots = 0;
212 457 my $count_fields = 0;
213 457 ▶ while ( $count_fields < $num_fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count_fields < $num_fields) 195 456 651
214 195 foreach my $field (@$fields) {
215 887 my $count = ( $field->{name} =~ tr/\.// );
216 887 ▶ next unless $count == $num_dots;
Branch: 1 branch
BranchTrueFalseTotal
unless $count == $num_dots 302 585 887
217 585 $self->_make_field($field);
218 584 $count_fields++;
219 }
220 194 $num_dots++;
221 }
222 }
223  
224 82 has 'include' => ( is => 'rw', builder => 'build_include', lazy => 1 );
225 226 ▶sub build_include { [] }
Subroutine build_include: called CC=1 SCAR=0.0
Pod undocumented
226 sub has_include {
227 457 ▶ my $self = shift;
Subroutine has_include: called CC=2 SCAR=7.0
Pod undocumented
228 457 ▶ my $include = $self->include || [];
Condition50%1/2
$self->include || []
l!l
4570
MC/DC0%0/1
$self->include || []
$self->include
Truth table50%1/2
A
A= $self->include
Aresult
11
00
229 457 return scalar @{$include};
230 }
231  
232 sub clean_fields {
233 457 ▶ my ( $self, $fields ) = @_;
Subroutine clean_fields: called CC=4 SCAR=13.9
Pod undocumented
234 457 ▶ if( $self->has_include ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_include) 6 451 457
235 6 my @fields;
236 6 my %include = map { $_ => 1 } @{ $self->include };
237 6 foreach my $fld ( @$fields ) {
238 16 ▶ push @fields, data_clone($fld) if exists $include{$fld->{name}};
Branch: 1 branch
BranchTrueFalseTotal
if exists $include{$fld->{"name"}} 7 9 16
239 }
240 6 return \@fields;
241 }
242 451 return data_clone( $fields );
243 };
244  
245 sub _make_field {
246 587 ▶ my ( $self, $field_attr ) = @_;
Subroutine _make_field: called CC=4 SCAR=13.9
247  
248 587 ▶ my $type = $field_attr->{type} ||= 'Text';
Condition100%2/2
$field_attr->{"type"} ||= "Text"
l!l
256331
MC/DC100%1/1
$field_attr->{"type"} ||= "Text"
$field_attr->{"type"}
Truth table100%2/2
A
A= $field_attr->{"type"}
Aresult
11
00
249 587 my $name = $field_attr->{name};
250  
251 # check for a field prefixed with '+', that overrides
252 587 my $do_update;
253 587 ▶ if ( $name =~ /^\+(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\+(.*)/) 4 583 587
254 4 $field_attr->{name} = $name = $1;
255 4 $do_update = 1;
256 }
257  
258 587 my $class = $self->_find_field_class( $type, $name );
259  
260 587 my $parent = $self->_find_parent( $field_attr );
261  
262 586 my $field = $self->_update_or_create( $parent, $field_attr, $class, $do_update );
263  
264 586 ▶ $self->form->add_to_index( $field->full_name => $field ) if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 571 15 586
265  
266 586 return $field;
267 }
268  
269 sub _find_field_class {
270 587 ▶ my ( $self, $type, $name ) = @_;
Subroutine _find_field_class: called CC=7 SCAR=19.5
271  
272 587 my $field_ns = $self->field_namespace;
273 587 my @classes;
274 # '+'-prefixed fields could be full namespaces
275 587 ▶ if ( $type =~ s/^\+// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ s/^\+//) 13 574 587
276 13 push @classes, $type;
277 }
278 587 foreach my $ns ( @$field_ns, 'Data::MuForm::Field' ) {
279 598 push @classes, $ns . "::" . $type;
280 }
281 # look for Field in possible namespaces
282 587 my $class;
283 587 foreach my $try ( @classes ) {
284 595 ▶ last if $class = load_optional_class($try) ? $try : undef;
Branch: 2 branches
BranchTrueFalseTotal
if $class = load_optional_class($try) ? $try : undef 587 8 595
load_optional_class($try) ? : 587 8 595
285 }
286 587 ▶ die "Could not load field class '$type' for field '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 587 587
287 unless $class;
288  
289 587 return $class;
290 }
291  
292  
293 sub _find_parent {
294 587 ▶ my ( $self, $field_attr ) = @_;
Subroutine _find_parent: called CC=7 SCAR=19.5
295  
296 # parent and name correction for names with dots
297 587 my $parent;
298 587 ▶ if ( $field_attr->{name} =~ /\./ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field_attr->{'name'} =~ /\./) { } 121 466 587
elsif (not $self->form && $self == $self->form) { } 61 405 466
299 121 my @names = split /\./, $field_attr->{name};
300 121 my $simple_name = pop @names;
301 121 my $parent_name = join '.', @names;
302 # use special 'field' method call that starts from
303 # $self, because names aren't always starting from
304 # the form
305 121 $parent = $self->field($parent_name, $self);
306 121 ▶ if ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) { } 120 1 121
307 120 ▶ die "The parent of field " . $field_attr->{name} . " is not a Compound Field"
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->isa("Data::MuForm::Field::Compound") 0 120 120
308 unless $parent->isa('Data::MuForm::Field::Compound');
309 120 $field_attr->{name} = $simple_name;
310 }
311 else {
312 1 die "did not find parent for field " . $field_attr->{name};
313 }
314 }
315 ▶ elsif ( !( $self->form && $self == $self->form ) ) {
Condition100%3/3
$self->form && $self == $self->form
!ll&&!rl&&r
1546405
MC/DC100%2/2
$self->form && $self == $self->form
$self->form $self == $self->form
Truth table100%3/3
A && B
A= $self->formB= $self == $self->form
ABresult
0X0
100
111
316 # set parent
317 61 $parent = $self;
318 }
319  
320 # get full_name
321 586 my $full_name = $field_attr->{name};
322 $full_name = $parent->full_name . "." . $field_attr->{name}
323 586 ▶ if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 181 405 586
324 586 $field_attr->{full_name} = $full_name;
325 586 return $parent;
326  
327 }
328  
329 sub _update_or_create {
330 586 ▶ my ( $self, $parent, $field_attr, $class, $do_update ) = @_;
Subroutine _update_or_create: called CC=18 SCAR=29.0
331  
332 586 ▶ $parent ||= $self->form;
Condition66%2/3
$parent ||= $self->form
l!l&&r!l&&!r
1814050
MC/DC0%0/2
$parent ||= $self->form
$parent $self->form
Truth table66%2/3
A ||= B
A= $parentB= $self->form
ABresult
1X1
011
000
333 586 $field_attr->{parent} = $parent;
334 586 $field_attr->{localizer} = $parent->localizer;
335 586 $field_attr->{renderer} = $parent->renderer;
336 586 ▶ $field_attr->{form} = $self->form if $self->form;
Branch: 1 branch
BranchTrueFalseTotal
if $self->form 571 15 586
337 $field_attr->{skip_fields_without_input} = $parent->skip_fields_without_input
338 586 ▶ if ! $self->is_form && $self->is_compound && ! exists $field_attr->{skip_fields_without_input};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->is_form and $self->is_compound and not exists $field_attr->{"skip_fields_without_input"} 66 520 586
Condition66%4/6
not $self->is_form and $self->is_compound and not exists $field_attr->{"skip_fields_without_input"}
!ll&&!rl&&r
520066
not $self->is_form and $self->is_compound
!ll&&!rl&&r
520066
MC/DC33%1/3
not $self->is_form and $self->is_compound and not exists $field_attr->{"skip_fields_without_input"}
not $self->is_form $self->is_compound not exists $field_attr->{"skip_fields_without_input"}
Truth table50%2/4
not(A) and B and not(C)
A= not $self->is_formB= $self->is_compoundC= not exists $field_attr->{"skip_fields_without_input"}
ABCresult
0XX0
10X0
1100
1111
339 586 my $index = $parent->field_index( $field_attr->{name} );
340 586 my $field;
341 586 ▶ if ( defined $index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) { } 7 579 586
342 7 ▶ if ($do_update) { # this field started with '+'. Update.
Branch: 1 branch
BranchTrueFalseTotal
if ($do_update) { } 2 5 7
343 2 $field = $parent->field( $field_attr->{name} );
344 2 ▶ die "Field to update for " . $field_attr->{name} . " not found"
Branch: 1 branch
BranchTrueFalseTotal
unless $field 0 2 2
345 unless $field;
346 2 munge_field_attr($field_attr);
347 2 foreach my $key ( keys %{$field_attr} ) {
348 18 ▶ next if $key eq 'name' || $key eq 'form' || $key eq 'parent' ||
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "name" or $key eq "form" or $key eq "parent" or $key eq "full_name" or $key eq "type" 4 8 12
Condition100%12/12
$key eq "name" or $key eq "form" or $key eq "parent" or $key eq "full_name" or $key eq "type"
l!l&&r!l&&!r
828
$key eq "name" or $key eq "form" or $key eq "parent" or $key eq "full_name"
l!l&&r!l&&!r
6210
$key eq "name" or $key eq "form" or $key eq "parent"
l!l&&r!l&&!r
4212
$key eq "name" or $key eq "form"
l!l&&r!l&&!r
2214
MC/DC100%5/5
$key eq "name" or $key eq "form" or $key eq "parent" or $key eq "full_name" or $key eq "type"
$key eq "name" $key eq "form" $key eq "parent" $key eq "full_name" $key eq "type"
Truth table100%6/6
A or B or C or D or E
A= $key eq "name"B= $key eq "form"C= $key eq "parent"D= $key eq "full_name"E= $key eq "type"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
349 $key eq 'full_name' || $key eq 'type';
350 8 ▶ $field->$key( $field_attr->{$key} )
Branch: 1 branch
BranchTrueFalseTotal
if $field->can($key) 8 0 8
351 if $field->can($key);
352 }
353 }
354 else { # replace existing field
355 5 $field = $self->new_field( $class, $field_attr);
356 5 $parent->set_field_at( $index, $field );
357 }
358 }
359 else { # new field
360 579 $field = $self->new_field( $class, $field_attr);
361 579 $parent->push_field($field);
362 }
363 586 ▶ $field->form->add_repeatable_field($field)
Branch: 1 branch
BranchTrueFalseTotal
if $field->form and $field->is_repeatable 35 551 586
Condition100%3/3
$field->form and $field->is_repeatable
!ll&&!rl&&r
1553635
MC/DC100%2/2
$field->form and $field->is_repeatable
$field->form $field->is_repeatable
Truth table100%3/3
A and B
A= $field->formB= $field->is_repeatable
ABresult
0X0
100
111
364 if ( $field->form && $field->is_repeatable);
365  
366 586 return $field;
367 }
368  
369 sub new_field {
370 608 ▶ my ( $self, $class, $field_attr ) = @_;
Subroutine new_field: called CC=1 SCAR=0.0
Pod undocumented
371 # not handling roles
372 608 my $field = $class->new(%$field_attr);
373 608 return $field;
374 }
375  
376 sub order_fields {
377 218 ▶ my $self = shift;
Subroutine order_fields: called CC=4 SCAR=13.9
Pod undocumented
378  
379 # number all unordered fields by 5
380 218 my $order = 5;
381 218 foreach my $field ( $self->all_fields ) {
382 625 ▶ if ( $field->has_fields ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->has_fields) 71 554 625
383 71 $field->order_fields;
384 }
385 # fields will default to 0, so we
386 # rewrite order if 0
387 625 ▶ $field->order($order) unless $field->order;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->order 566 59 625
388 625 $order += 5;
389 }
390 }
391  
392 sub _get_highest_field_order {
393 1 ▶ my $self = shift;
Subroutine _get_highest_field_order: called CC=3 SCAR=11.0
394 1 my $order = 0;
395 1 foreach my $field ( $self->all_fields ) {
396 3 ▶ $order = $field->order if $field->order > $order;
Branch: 1 branch
BranchTrueFalseTotal
if $field->order > $order 2 1 3
397 }
398 1 return $order;
399 }
400  
401 # This is a special make field that's used in the Repeatable field to
402 # create repeatable instances. It skips some of the overhead of _make_field
403 # because some of the info can be hardcoded and we don't want to index it.
404 sub _make_adhoc_field {
405 24 ▶ my ( $self, $class, $field_attr ) = @_;
Subroutine _make_adhoc_field: called CC=1 SCAR=0.0
406 24 my $field = $self->new_field( $class, $field_attr );
407 24 return $field;
408 }
409  
410  
411 #====================================================================
412 # Initialize input/value (InitResult)
413 #====================================================================
414  
415 # $input here is from the $params passed in on ->process
416 sub fill_from_params {
417 160 ▶ my ( $self, $input, $exists ) = @_;
Subroutine fill_from_params: called CC=16 SCAR=28.3
Pod undocumented
418  
419 160 $self->filled_from('params');
420 160 ▶ return unless ( defined $input || $exists || $self->has_fields );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input or $exists or $self->has_fields 0 160 160
Condition33%2/6
defined $input or $exists or $self->has_fields
l!l&&r!l&&!r
16000
defined $input or $exists
l!l&&r!l&&!r
16000
MC/DC0%0/3
defined $input or $exists or $self->has_fields
defined $input $exists $self->has_fields
Truth table25%1/4
A or B or C
A= defined $inputB= $existsC= $self->has_fields
ABCresult
1XX1
01X1
0011
0000
421 # TODO - this will get replaced by setting the actual processed input 14 lines down.
422 # Do we need this? Maybe could be used to transform input before processing?
423 160 $self->transform_and_set_input($input);
424 160 my $my_input = {};
425 160 ▶ if ( ref $input eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input eq "HASH") 160 0 160
426 160 foreach my $field ( $self->all_sorted_fields ) {
427 454 ▶ next if ! $field->is_active;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_active 0 454 454
428 454 ▶ my $fname = $field->input_param || $field->name;
Condition66%2/3
$field->input_param || $field->name
l!l&&r!l&&!r
34510
MC/DC0%0/2
$field->input_param || $field->name
$field->input_param $field->name
Truth table66%2/3
A || B
A= $field->input_paramB= $field->name
ABresult
1X1
011
000
429 454 my $exists = exists $input->{$fname};
430 454 ▶ next if ( $self->skip_fields_without_input && ! $exists && ! $field->has_input_without_param );
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_fields_without_input and not $exists and not $field->has_input_without_param 7 447 454
Condition100%6/6
$self->skip_fields_without_input and not $exists and not $field->has_input_without_param
!ll&&!rl&&r
43897
$self->skip_fields_without_input and not $exists
!ll&&!rl&&r
4162216
MC/DC100%3/3
$self->skip_fields_without_input and not $exists and not $field->has_input_without_param
$self->skip_fields_without_input not $exists not $field->has_input_without_param
Truth table100%4/4
A and not(B) and not(C)
A= $self->skip_fields_without_inputB= not $existsC= not $field->has_input_without_param
ABCresult
0XX0
10X0
1100
1111
431 447 ▶ if ( ! $exists && $field->disabled && ! $field->has_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $exists and $field->disabled and not $field->has_value) { } 1 446 447
Condition100%6/6
not $exists and $field->disabled and not $field->has_value
!ll&&!rl&&r
44511
not $exists and $field->disabled
!ll&&!rl&&r
368772
MC/DC100%3/3
not $exists and $field->disabled and not $field->has_value
not $exists $field->disabled not $field->has_value
Truth table100%4/4
not(A) and B and not(C)
A= not $existsB= $field->disabledC= not $field->has_value
ABCresult
0XX0
10X0
1100
1111
432 1 $field->fill_from_fields;
433 }
434 else {
435 446 $field->fill_from_params($input->{$fname}, $exists );
436 }
437 447 ▶ $my_input->{$fname} = $field->input if $field->has_input;
Branch: 1 branch
BranchTrueFalseTotal
if $field->has_input 390 57 447
438 }
439 }
440 # save input for this form or compound field. Used to determine whether really 'submitted'
441 # in form. This should not be used for errors or fif or anything like that.
442 160 ▶ $self->input( scalar keys %$my_input ? $my_input : {});
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %$my_input ? : 158 2 160
443 160 return;
444 }
445  
446 sub fill_from_object {
447 95 ▶ my ( $self, $obj ) = @_;
Subroutine fill_from_object: called CC=17 SCAR=28.5
Pod undocumented
448  
449 95 ▶ return unless ( $obj || $self->has_fields ); # empty fields for compounds
Branch: 1 branch
BranchTrueFalseTotal
unless $obj or $self->has_fields 0 95 95
Condition33%1/3
$obj or $self->has_fields
l!l&&r!l&&!r
9500
MC/DC0%0/2
$obj or $self->has_fields
$obj $self->has_fields
Truth table33%1/3
A or B
A= $objB= $self->has_fields
ABresult
1X1
011
000
450 95 $self->filled_from('object');
451 95 my $my_value;
452 my $init_obj;
453 95 ▶ if ( $self->form &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->form and $self->form->fill_from_object_source and $self->form->fill_from_object_source eq "model" and $self->form->has_init_values) 6 89 95
Condition88%8/9
$self->form and $self->form->fill_from_object_source and $self->form->fill_from_object_source eq "model" and $self->form->has_init_values
!ll&&!rl&&r
73166
$self->form and $self->form->fill_from_object_source and $self->form->fill_from_object_source eq "model"
!ll&&!rl&&r
126122
$self->form and $self->form->fill_from_object_source
!ll&&!rl&&r
01283
MC/DC75%3/4
$self->form and $self->form->fill_from_object_source and $self->form->fill_from_object_source eq "model" and $self->form->has_init_values
$self->form $self->form->fill_from_object_source $self->form->fill_from_object_source eq "model" $self->form->has_init_values
Truth table80%4/5
A and B and C and D
A= $self->formB= $self->form->fill_from_object_sourceC= $self->form->fill_from_object_source eq "model"D= $self->form->has_init_values
ABCDresult
0XXX0
10XX0
110X0
11100
11111
454 $self->form->fill_from_object_source &&
455 $self->form->fill_from_object_source eq 'model' &&
456 $self->form->has_init_values ) {
457 6 $init_obj = $self->form->init_values;
458 }
459 95 for my $field ( $self->all_sorted_fields ) {
460 257 ▶ next if ! $field->is_active;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_active 0 257 257
461 257 ▶ if ( (ref $obj eq 'HASH' && !exists $obj->{ $field->accessor } ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq 'HASH' and not exists $$obj{$field->accessor} or builtin::blessed($obj) and not $obj->can($field->accessor)) { } 35 222 257
Condition100%9/9
ref $obj eq "HASH" and not exists $$obj{$field->accessor} or builtin::blessed($obj) and not $obj->can($field->accessor)
l!l&&r!l&&!r
323222
ref $obj eq "HASH" and not exists $$obj{$field->accessor}
!ll&&!rl&&r
1421132
builtin::blessed($obj) and not $obj->can($field->accessor)
!ll&&!rl&&r
211113
MC/DC75%3/4
ref $obj eq "HASH" and not exists $$obj{$field->accessor} or builtin::blessed($obj) and not $obj->can($field->accessor)
ref $obj eq "HASH" not exists $$obj{$field->accessor} builtin::blessed($obj) not $obj->can($field->accessor)
Truth table57%4/7
A and not(B) or C and not(D)
A= ref $obj eq "HASH"B= not exists $$obj{$field->accessor}C= builtin::blessed($obj)D= not $obj->can($field->accessor)
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
462 ( blessed($obj) && !$obj->can($field->accessor) ) ) {
463 35 my $found = 0;
464  
465 35 ▶ if ($init_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($init_obj) 9 26 35
466 # if we're using a model, look for accessor not found in obj
467 # in the init_values
468 9 my @names = split( /\./, $field->full_name );
469 9 my $init_obj_value = $self->find_sub_obj( $init_obj, \@names );
470 9 ▶ if ( defined $init_obj_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $init_obj_value) 7 2 9
471 7 $found = 1;
472 7 $field->fill_from_object( $init_obj_value );
473 }
474 }
475  
476 35 ▶ $field->fill_from_fields() unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 28 7 35
477 }
478 else {
479 222 ▶ my $value = $self->_get_value( $field, $obj ) unless $field->writeonly;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->writeonly 222 0 222
480 222 $field->fill_from_object( $value );
481 }
482 # TODO: the following doesn't work for 'input_without_param' fields like checkboxes
483 # $my_value->{ $field->name } = $field->value if $field->has_value;
484 257 $my_value->{ $field->name } = $field->value;
485 }
486 95 $self->value($my_value);
487 95 return;
488 }
489  
490 # for when there are no params and no init_values
491 sub fill_from_fields {
492 238 ▶ my ( $self ) = @_;
Subroutine fill_from_fields: called CC=10 SCAR=24.9
Pod undocumented
493  
494 238 $self->filled_from('fields');
495 # defaults for compounds, etc.
496 238 ▶ if ( my @values = $self->get_default_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@values) = $self->get_default_value) 6 232 238
497 6 ▶ my $value = @values > 1 ? \@values : shift @values;
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 0 6 6
498 6 ▶ if( ref $value eq 'HASH' || blessed $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH" or builtin::blessed($value)) 6 0 6
Condition66%2/3
ref $value eq "HASH" or builtin::blessed($value)
l!l&&r!l&&!r
510
MC/DC0%0/2
ref $value eq "HASH" or builtin::blessed($value)
ref $value eq "HASH" builtin::blessed($value)
Truth table66%2/3
A or B
A= ref $value eq "HASH"B= builtin::blessed($value)
ABresult
1X1
011
000
499 6 return $self->fill_from_object( $value );
500 }
501 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
502 0 $self->init_value($value);
503 0 $self->value($value);
504 }
505 }
506 232 my $my_value;
507 232 for my $field ( $self->all_sorted_fields ) {
508 642 ▶ next if (!$field->is_active);
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_active 0 642 642
509 642 $field->fill_from_fields();
510 642 ▶ $my_value->{ $field->name } = $field->value if $field->has_value;
Branch: 1 branch
BranchTrueFalseTotal
if $field->has_value 65 577 642
511 }
512 # setting value here to handle disabled compound fields, where we want to
513 # preserve the 'value' because the fields aren't submitted...except for the
514 # form. Not sure it's the best idea to skip for form, but it maintains previous behavior
515 232 ▶ $self->value($my_value) if ( keys %$my_value );
Branch: 1 branch
BranchTrueFalseTotal
if keys %$my_value 43 189 232
516 232 return;
517 }
518  
519 sub find_sub_obj {
520 10 ▶ my ( $self, $obj, $field_name_array ) = @_;
Subroutine find_sub_obj: called CC=2 SCAR=7.1
Pod undocumented
521 10 my $this_fname = shift @$field_name_array;;
522 10 my $field = $self->field($this_fname);
523 10 my $new_obj = $self->_get_value( $field, $obj );
524 10 ▶ if ( scalar @$field_name_array ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$field_name_array) 0 10 10
525 0 $new_obj = $field->find_sub_obj( $new_obj, $field_name_array );
526 }
527 10 return $new_obj;
528 }
529  
530  
531  
532 sub _get_value {
533 232 ▶ my ( $self, $field, $obj ) = @_;
Subroutine _get_value: called CC=17 SCAR=28.4
534  
535 232 my $accessor = $field->accessor;
536 232 my @values;
537 232 ▶ if ( blessed($obj) && $obj->can($accessor) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($obj) and $obj->can($accessor)) { } 11 221 232
elsif (exists $obj->{$accessor}) { } 216 5 221
elsif (@values = $field->get_default_value) { } 3 2 5
Condition66%2/3
builtin::blessed($obj) and $obj->can($accessor)
!ll&&!rl&&r
221011
MC/DC50%1/2
builtin::blessed($obj) and $obj->can($accessor)
builtin::blessed($obj) $obj->can($accessor)
Truth table66%2/3
A and B
A= builtin::blessed($obj)B= $obj->can($accessor)
ABresult
0X0
100
111
538 # this must be an array, so that DBIx::Class relations are arrays not resultsets
539 11 @values = $obj->$accessor;
540 # for non-DBIC blessed object where access returns arrayref
541 11 ▶ if ( scalar @values == 1 && ref $values[0] eq 'ARRAY' && $field->multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @values == 1 and ref $values[0] eq "ARRAY" and $field->multiple) 1 10 11
Condition66%4/6
scalar @values == 1 and ref $values[0] eq "ARRAY" and $field->multiple
!ll&&!rl&&r
1001
scalar @values == 1 and ref $values[0] eq "ARRAY"
!ll&&!rl&&r
0101
MC/DC33%1/3
scalar @values == 1 and ref $values[0] eq "ARRAY" and $field->multiple
scalar @values == 1 ref $values[0] eq "ARRAY" $field->multiple
Truth table50%2/4
A and B and C
A= scalar @values == 1B= ref $values[0] eq "ARRAY"C= $field->multiple
ABCresult
0XX0
10X0
1100
1111
542 1 @values = @{$values[0]};
543 }
544 }
545 elsif ( exists $obj->{$accessor} ) {
546 216 my $v = $obj->{$accessor};
547 216 ▶ if($field->multiple && ref($v) eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if ($field->multiple and ref $v eq 'ARRAY') { } 2 214 216
Condition100%3/3
$field->multiple and ref $v eq "ARRAY"
!ll&&!rl&&r
21312
MC/DC100%2/2
$field->multiple and ref $v eq "ARRAY"
$field->multiple ref $v eq "ARRAY"
Truth table100%3/3
A and B
A= $field->multipleB= ref $v eq "ARRAY"
ABresult
0X0
100
111
548 2 @values = @$v;
549 } else {
550 214 @values = $v;
551 }
552 }
553 elsif ( @values = $field->get_default_value ) {
554 }
555 else {
556 2 return;
557 }
558 230 ▶ if( $field->has_transform_default_to_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->has_transform_default_to_value) 8 222 230
559 8 @values = $field->transform_default_to_value->($field, @values);
560 }
561 230 my $value;
562 230 ▶ if( $field->multiple ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->multiple) { } 5 225 230
563 5 ▶ if ( scalar @values == 1 && ! defined $values[0] ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @values == 1 and not defined $values[0]) { } 1 4 5
elsif (scalar @values == 1 and ref $values[0] eq 'ARRAY') { } 1 3 4
Condition100%3/3
scalar @values == 1 and not defined $values[0]
!ll&&!rl&&r
131
MC/DC100%2/2
scalar @values == 1 and not defined $values[0]
scalar @values == 1 not defined $values[0]
Truth table100%3/3
A and not(B)
A= scalar @values == 1B= not defined $values[0]
ABresult
0X0
100
111
564 1 $value = [];
565 }
566 ▶ elsif ( scalar @values == 1 && ref $values[0] eq 'ARRAY' ) {
Condition100%3/3
scalar @values == 1 and ref $values[0] eq "ARRAY"
!ll&&!rl&&r
121
MC/DC100%2/2
scalar @values == 1 and ref $values[0] eq "ARRAY"
scalar @values == 1 ref $values[0] eq "ARRAY"
Truth table100%3/3
A and B
A= scalar @values == 1B= ref $values[0] eq "ARRAY"
ABresult
0X0
100
111
567 1 $value = shift @values;
568 }
569 else {
570 3 $value = \@values;
571 }
572 }
573 else {
574 225 ▶ $value = @values > 1 ? \@values : shift @values;
Branch: 1 branch
BranchTrueFalseTotal
@values > 1 ? : 0 225 225
575 }
576 230 return $value;
577 }
578  
579  
580 sub fields_set_value {
581 103 ▶ my $self = shift;
Subroutine fields_set_value: called CC=5 SCAR=16.1
Pod undocumented
582 103 my %value_hash;
583 103 foreach my $field ( $self->all_fields ) {
584 305 ▶ next if ! $field->is_active;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_active 3 302 305
585 302 ▶ $value_hash{ $field->accessor } = $field->value
Branch: 1 branch
BranchTrueFalseTotal
if $field->has_value and not $field->no_update 267 35 302
Condition100%3/3
$field->has_value and not $field->no_update
!ll&&!rl&&r
314267
MC/DC100%2/2
$field->has_value and not $field->no_update
$field->has_value not $field->no_update
Truth table100%3/3
A and not(B)
A= $field->has_valueB= not $field->no_update
ABresult
0X0
100
111
586 if ( $field->has_value && !$field->no_update );
587 }
588 103 $self->value( \%value_hash );
589 }
590  
591  
592 sub clear_data {
593 133 ▶ my $self = shift;
Subroutine clear_data: called CC=3 SCAR=11.0
Pod undocumented
594 133 $self->clear_input;
595 133 $self->clear_value;
596 # TODO - better way?
597 133 ▶ $self->_clear_active unless $self->is_form;;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_form 62 71 133
598 133 $self->clear_error_fields;
599 133 $self->clear_filled_from;
600 133 foreach my $field ( $self->all_fields ) {
601 349 $field->clear_data;
602 }
603 }
604  
605 # References to fields with errors are propagated up the tree.
606 # All fields with errors should end up being in the form's
607 # error_results. Once.
608 sub propagate_error {
609 81 ▶ my ( $self, $field ) = @_;
Subroutine propagate_error: called CC=2 SCAR=6.9
Pod undocumented
610  
611 81 $self->add_error_field($field);
612 81 ▶ if ( $self->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent) 16 65 81
613 16 $self->parent->propagate_error( $field );
614 }
615 }
616  
617 82 1;
618  
619 __END__
620  
621 =pod
622  
623 =encoding UTF-8
624  
625 =head1 NAME
626  
627 Data::MuForm::Fields - Common attributes and methods for forms and compound fields
628  
629 =head1 VERSION
630  
631 version 0.04
632  
633 =head2 NAME
634  
635 Data::MuForm::Fields
636  
637 =head2 DESCRIPTION
638  
639 This role holds things that are common to Data::MuForm and compound fields.
640  
641 Includes code that was split up into multiple roles in FormHandler: Fields,
642 BuildFields, InitResult.
643  
644 =head1 AUTHOR
645  
646 Gerda Shank
647  
648 =head1 COPYRIGHT AND LICENSE
649  
650 This software is copyright (c) 2017 by Gerda Shank.
651  
652 This is free software; you can redistribute it and/or modify it under
653 the same terms as the Perl 5 programming language system itself.
654  
655 =cut
« MuForm/Field.pm ↑ Summary MuForm/Renderer/Base.pm »