FormHandler/Field/Compound.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 86.7% 72 / 83 CC 10 SCAR 11.4
CC
10
Cov
90%
test_validate_field
5.4
__ANON__
3.0
__ANON__
3.0
CRAP 3.1
« FormHandler/TraitFor/I18N.pm ↑ Summary FormHandler/Moose.pm »
1 package HTML::FormHandler::Field::Compound;
2 # ABSTRACT: field consisting of subfields
3 56 $HTML::FormHandler::Field::Compound::VERSION = '0.410000';
4 56 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 56 extends 'HTML::FormHandler::Field';
6 56 with 'HTML::FormHandler::Fields';
7 56 with 'HTML::FormHandler::BuildFields';
8 56 with 'HTML::FormHandler::InitResult';
9  
10  
11 56 has '+widget' => ( default => 'Compound' );
12 56 has 'is_compound' => ( is => 'ro', isa => 'Bool', default => 1 );
13 56 has 'item' => ( is => 'rw', clearer => 'clear_item' );
14 56 has '+do_wrapper' => ( default => 0 );
15 56 has '+do_label' => ( default => 0 );
16 56 has 'primary_key' => ( is => 'rw', isa => 'ArrayRef',
17 predicate => 'has_primary_key', );
18  
19 has '+field_name_space' => (
20 default => sub {
21 20 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
22 20 ▶ return $self->form->field_name_space
Branch: 1 branch
BranchTrueFalseTotal
if $self->form and $self->form->field_name_space 15 5 20
Condition66%2/3
$self->form and $self->form->field_name_space
!ll&&!rl&&r
5015
MC/DC50%1/2
$self->form and $self->form->field_name_space
$self->form $self->form->field_name_space
Truth table66%2/3
A and B
A= $self->formB= $self->form->field_name_space
ABresult
0X0
100
111
23 if $self->form && $self->form->field_name_space;
24 5 return [];
25 },
26 56 );
27  
28 sub BUILD {
29 149 ▶ my $self = shift;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
30 149 $self->_build_fields;
31 }
32  
33 # this is for testing compound fields outside
34 # of a form
35 sub test_validate_field {
36 3 ▶ my $self = shift;
Subroutine test_validate_field: called CC=5 SCAR=16.8
Pod undocumented
37 3 ▶ unless( $self->form ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->form) 3 0 3
38 3 ▶ if( $self->has_input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_input) { } 3 0 3
39 3 $self->_result_from_input( $self->result, $self->input );;
40 }
41 else {
42 0 $self->_result_from_fields( $self->result );
43 }
44 }
45 3 $self->validate_field;
46 3 ▶ unless( $self->form ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->form) 3 0 3
47 3 foreach my $err_res (@{$self->result->error_results}) {
48 1 $self->result->_push_errors($err_res->all_errors);
49 }
50 }
51 }
52  
53 around '_result_from_object' => sub {
54 50 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
55 50 my $self = shift;
56 50 my ( $self_result, $item ) = @_;
57 50 ▶ $self->item($item) if $item;
Branch: 1 branch
BranchTrueFalseTotal
if $item 50 0 50
58 50 $self->$orig(@_);
59 56 };
60  
61 after 'clear_data' => sub {
62 93 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
63 93 $self->clear_item;
64 56 };
65  
66 around '_result_from_input' => sub {
67 104 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
68 104 my $self = shift;
69 104 my ( $self_result, $input, $exists ) = @_;
70 104 ▶ if ( !$input && !$exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $input || $exists) { } 7 97 104
Condition66%2/3
$input || $exists
l!l&&r!l&&!r
9707
MC/DC50%1/2
$input || $exists
$input $exists
Truth table66%2/3
A || B
A= $inputB= $exists
ABresult
1X1
011
000
71 7 return $self->_result_from_fields($self_result);
72 }
73 else {
74 97 return $self->$orig(@_);
75 }
76 56 };
77  
78 56 __PACKAGE__->meta->make_immutable;
79 56 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 56 1;
81  
82 __END__
83  
84 =pod
85  
86 =encoding UTF-8
87  
88 =head1 NAME
89  
90 HTML::FormHandler::Field::Compound - field consisting of subfields
91  
92 =head1 VERSION
93  
94 version 0.410000
95  
96 =head1 SYNOPSIS
97  
98 This field class is designed as the base (parent) class for fields with
99 multiple subfields. Examples are L<HTML::FormHandler::Field::DateTime>
100 and L<HTML::FormHandler::Field::Duration>.
101  
102 A compound parent class requires the use of sub-fields prepended
103 with the parent class name plus a dot
104  
105 has_field 'birthdate' => ( type => 'DateTime' );
106 has_field 'birthdate.year' => ( type => 'Year' );
107 has_field 'birthdate.month' => ( type => 'Month' );
108 has_field 'birthdate.day' => ( type => 'MonthDay');
109  
110 If all validation is performed in the parent class so that no
111 validation is necessary in the child classes, then the field class
112 'Nested' may be used.
113  
114 The array of subfields is available in the 'fields' array in
115 the compound field:
116  
117 $form->field('birthdate')->fields
118  
119 Error messages will be available in the field on which the error
120 occurred. You can access 'error_fields' on the form or on Compound
121 fields (and subclasses, like Repeatable).
122  
123 The process method of this field runs the process methods on the child fields
124 and then builds a hash of these fields values. This hash is available for
125 further processing by L<HTML::FormHandler::Field/actions> and the validate method.
126  
127 =head2 widget
128  
129 Widget type is 'compound'
130  
131 =head2 build_update_subfields
132  
133 You can set 'defaults' or other settings in a 'build_update_subfields' method,
134 which contains attribute settings that will be merged with field definitions
135 when the fields are built. Use the 'by_flag' key with 'repeatable', 'compound',
136 and 'contains' subkeys, or use the 'all' key for settings which apply to all
137 subfields in the compound field.
138  
139 =head1 AUTHOR
140  
141 FormHandler Contributors - see HTML::FormHandler
142  
143 =head1 COPYRIGHT AND LICENSE
144  
145 This software is copyright (c) 2017 by Gerda Shank.
146  
147 This is free software; you can redistribute it and/or modify it under
148 the same terms as the Perl 5 programming language system itself.
149  
150 =cut
« FormHandler/TraitFor/I18N.pm ↑ Summary FormHandler/Moose.pm »