| 1 | package HTML::FormHandler::InitResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: internal code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 147 | $HTML::FormHandler::InitResult::VERSION = '0.410002'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 147 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # _init is for building fields when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # there is no initial object and no params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # formerly _init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 461 | ▶ | sub _result_from_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_from_fields: called CC=14 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 461 | my ( $self, $self_result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # defaults for compounds, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 461 | ▶ | if ( my @values = $self->get_default_value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | my $value = @values > 1 ? \@values : shift @values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | if( ref $value eq 'HASH' || blessed $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value eq "HASH" or builtin::blessed($value)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | return $self->_result_from_object( $self_result, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $self->init_value($value) if defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | $self_result->_set_value($value) if defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 454 | my $my_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 454 | for my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1318 | ▶ | next if ($field->inactive && !$field->_active); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$field->inactive and not $field->_active
MC/DC0%0/2
$field->inactive and not $field->_active
$field->inactive
not $field->_active
Truth table66%2/3
A and not(B)
A= $field->inactiveB= not $field->_active
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1318 | my $result = HTML::FormHandler::Field::Result->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | name => $field->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | parent => $self_result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1318 | $result = $field->_result_from_fields($result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1318 | ▶ | $my_value->{ $field->name } = $result->value if $result->has_value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1318 | ▶ | $self_result->add_result($result) if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # setting value here to handle disabled compound fields, where we want to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # preserve the 'value' because the fields aren't submitted...except for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # form. Not sure it's the best idea to skip for form, but it maintains previous behavior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 454 | ▶ | $self_result->_set_value($my_value) if ( keys %$my_value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 454 | $self->_set_result($self_result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 454 | ▶ | $self_result->_set_field_def($self) if $self->DOES('HTML::FormHandler::Field'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 454 | return $self_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # building fields from input (params) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # formerly done in validate_field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 274 | ▶ | sub _result_from_input { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_from_input: called CC=12 SCAR=27.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 274 | my ( $self, $self_result, $input, $exists ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # transfer the input values to the input attributes of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # subfields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 274 | ▶ | return unless ( defined $input || $exists || $self->has_fields ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $input or $exists or $self->has_fields
defined $input or $exists
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 274 | $self_result->_set_input($input); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 274 | ▶ | if ( ref $input eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 274 | foreach my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 843 | ▶ | next if ($field->inactive && !$field->_active); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$field->inactive and not $field->_active
MC/DC0%0/2
$field->inactive and not $field->_active
$field->inactive
not $field->_active
Truth table66%2/3
A and not(B)
A= $field->inactiveB= not $field->_active
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 843 | my $field_name = $field->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 843 | my $result = HTML::FormHandler::Field::Result->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | name => $field_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | parent => $self_result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $result = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $field->_result_from_input( $result, $input->{$field->input_param || $field_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 843 | ▶ | exists $input->{$field->input_param || $field_name} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$field->input_param || $field_name
$field->input_param || $field_name
MC/DC0%0/2
$field->input_param || $field_name
$field->input_param
$field_name
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
Truth table66%2/3
A || B
A= $field->input_paramB= $field_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 843 | ▶ | $self_result->add_result($result) if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 274 | $self->_set_result($self_result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 274 | ▶ | $self_result->_set_field_def($self) if $self->DOES('HTML::FormHandler::Field'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 274 | return $self_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # building fields from model object or init_obj hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # formerly _init_from_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 115 | ▶ | sub _result_from_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_from_object: called CC=16 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 115 | my ( $self, $self_result, $item ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 115 | ▶ | return unless ( $item || $self->has_fields ); # empty fields for compounds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$item or $self->has_fields
MC/DC0%0/2
$item or $self->has_fields
$item
$self->has_fields
Truth table33%1/3
A or B
A= $itemB= $self->has_fields
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 115 | my $my_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 115 | my $init_obj = $self->form->init_object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 115 | for my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 333 | ▶ | next if ( $field->inactive && !$field->_active ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$field->inactive and not $field->_active
MC/DC0%0/2
$field->inactive and not $field->_active
$field->inactive
not $field->_active
Truth table33%1/3
A and not(B)
A= $field->inactiveB= not $field->_active
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 333 | my $result = HTML::FormHandler::Field::Result->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | name => $field->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | parent => $self_result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 333 | ▶ | if ( (ref $item eq 'HASH' && !exists $item->{ $field->accessor } ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
ref $item eq "HASH" and not exists $$item{$field->accessor} or builtin::blessed($item) and not $item->can($field->accessor)
ref $item eq "HASH" and not exists $$item{$field->accessor}
builtin::blessed($item) and not $item->can($field->accessor)
MC/DC75%3/4
ref $item eq "HASH" and not exists $$item{$field->accessor} or builtin::blessed($item) and not $item->can($field->accessor)
ref $item eq "HASH"
not exists $$item{$field->accessor}
builtin::blessed($item)
not $item->can($field->accessor)
Truth table57%4/7
A and not(B) or C and not(D)
A= ref $item eq "HASH"B= not exists $$item{$field->accessor}C= builtin::blessed($item)D= not $item->can($field->accessor)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ( blessed($item) && !$item->can($field->accessor) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 58 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 58 | ▶ | if ($field->form->use_init_obj_when_no_accessor_in_item) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # if we're using an item, look for accessor not found in item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # in the init_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | my @names = split( /\./, $field->full_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 6 | my $init_obj_value = $self->find_sub_item( $init_obj, \@names ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | ▶ | if ( defined $init_obj_value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | $result = $field->_result_from_object( $result, $init_obj_value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 58 | ▶ | $result = $field->_result_from_fields($result) unless $found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 275 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 275 | ▶ | $value = $self->_get_value( $field, $item ) unless $field->writeonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 275 | $result = $field->_result_from_object( $result, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 333 | ▶ | $self_result->add_result($result) if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 333 | $my_value->{ $field->name } = $field->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 115 | $self_result->_set_value($my_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 115 | $self->_set_result($self_result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 115 | ▶ | $self_result->_set_field_def($self) if $self->DOES('HTML::FormHandler::Field'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 115 | return $self_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # this is used for reloading repeatables form the database if they've changed and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # for finding field values in the init_object when we have an item and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # 'use_init_obj_when_no_accessor_in_item' flag is set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | ▶ | sub find_sub_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_sub_item: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | my ( $self, $item, $field_name_array ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | my $this_fname = shift @$field_name_array;; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 7 | my $field = $self->field($this_fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | my $new_item = $self->_get_value( $field, $item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 7 | ▶ | if ( scalar @$field_name_array ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $new_item = $field->find_sub_item( $new_item, $field_name_array ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | return $new_item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 282 | ▶ | sub _get_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_value: called CC=19 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 282 | my ( $self, $field, $item ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 282 | my $accessor = $field->accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 282 | my @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 282 | ▶ | if( defined $field->default_over_obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | @values = $field->default_over_obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ▶ | elsif( $field->form && $field->form->use_defaults_over_obj && ( @values = $field->get_default_value ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$field->form and $field->form->use_defaults_over_obj and @values = $field->get_default_value
$field->form and $field->form->use_defaults_over_obj
MC/DC66%2/3
$field->form and $field->form->use_defaults_over_obj and @values = $field->get_default_value
$field->form
$field->form->use_defaults_over_obj
@values = $field->get_default_value
Truth table75%3/4
A and B and C
A= $field->formB= $field->form->use_defaults_over_objC= @values = $field->get_default_value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ▶ | elsif ( blessed($item) && $item->can($accessor) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($item) and $item->can($accessor)
MC/DC50%1/2
builtin::blessed($item) and $item->can($accessor)
builtin::blessed($item)
$item->can($accessor)
Truth table66%2/3
A and B
A= builtin::blessed($item)B= $item->can($accessor)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # this must be an array, so that DBIx::Class relations are arrays not resultsets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 17 | @values = $item->$accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # for non-DBIC blessed object where access returns arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 17 | ▶ | if ( scalar @values == 1 && ref $values[0] eq 'ARRAY' && $field->has_flag('multiple') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
scalar @values == 1 and ref $values[0] eq "ARRAY" and $field->has_flag("multiple")
scalar @values == 1 and ref $values[0] eq "ARRAY"
MC/DC33%1/3
scalar @values == 1 and ref $values[0] eq "ARRAY" and $field->has_flag("multiple")
scalar @values == 1
ref $values[0] eq "ARRAY"
$field->has_flag("multiple")
Truth table50%2/4
A and B and C
A= scalar @values == 1B= ref $values[0] eq "ARRAY"C= $field->has_flag("multiple")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | @values = @{$values[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | elsif ( exists $item->{$accessor} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 258 | my $v = $item->{$accessor}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 258 | ▶ | if($field->has_flag('multiple') && ref($v) eq 'ARRAY'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$field->has_flag("multiple") and ref $v eq "ARRAY"
MC/DC100%2/2
$field->has_flag("multiple") and ref $v eq "ARRAY"
$field->has_flag("multiple")
ref $v eq "ARRAY"
Truth table100%3/3
A and B
A= $field->has_flag("multiple")B= ref $v eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | @values = @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 255 | @values = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | elsif ( @values = $field->get_default_value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 280 | ▶ | if( $field->has_inflate_default_method ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 9 | @values = $field->inflate_default(@values); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 280 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 280 | ▶ | if( $field->has_flag('multiple')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | ▶ | $value = scalar @values == 1 && ! defined $values[0] ? [] : \@values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @values == 1 and not defined $values[0]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 273 | ▶ | $value = @values > 1 ? \@values : shift @values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 280 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 147 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 147 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||