| 1 | package HTML::FormHandler::Field::Compound; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: field consisting of subfields | ||||||||||||||||||||||||||||
| 3 | 56 | $HTML::FormHandler::Field::Compound::VERSION = '0.410002'; | |||||||||||||||||||||||||||
| 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 | 20 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 21 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | 20 | ▶ | return $self->form->field_name_space | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->form and $self->form->field_name_space
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
| |||||||||||||||||||||||||||||
| 23 | if $self->form && $self->form->field_name_space; | ||||||||||||||||||||||||||||
| 24 | 5 | return []; | |||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | 56 | ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 149 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 149 | my $self = shift; | |||||||||||||||||||||||||||
| 30 | 149 | $self->_build_fields; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # this is for testing compound fields outside | ||||||||||||||||||||||||||||
| 34 | # of a form | ||||||||||||||||||||||||||||
| 35 | 3 | ▶ | sub test_validate_field { | ||||||||||||||||||||||||||
|
Subroutine
test_validate_field: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 3 | ▶ | unless( $self->form ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 3 | ▶ | if( $self->has_input ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | 50 | ▶ | around '_result_from_object' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 54 | 50 | my $orig = shift; | |||||||||||||||||||||||||||
| 55 | 50 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 50 | my ( $self_result, $item ) = @_; | |||||||||||||||||||||||||||
| 57 | 50 | ▶ | $self->item($item) if $item; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 50 | $self->$orig(@_); | |||||||||||||||||||||||||||
| 59 | 56 | }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 93 | ▶ | after 'clear_data' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 93 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 93 | $self->clear_item; | |||||||||||||||||||||||||||
| 64 | 56 | }; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 104 | ▶ | around '_result_from_input' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 67 | 104 | my $orig = shift; | |||||||||||||||||||||||||||
| 68 | 104 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 104 | my ( $self_result, $input, $exists ) = @_; | |||||||||||||||||||||||||||
| 70 | 104 | ▶ | if ( !$input && !$exists ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$input || $exists
MC/DC50%1/2
$input || $exists
$input
$exists
Truth table66%2/3
A || B
A= $inputB= $exists
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||