« FormHandler/Widget/Field/CheckboxGroup.pm
↑ Summary
FormHandler/Widget/Field/HorizCheckboxGroup.pm »
| 1 | package HTML::FormHandler::Field::Select; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: select fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 43 | $HTML::FormHandler::Field::Select::VERSION = '0.410002'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 43 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 43 | extends 'HTML::FormHandler::Field'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 43 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 43 | has 'options' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | isa => 'HFH::SelectOptions', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | auto_deref => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | all_options => 'elements', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | reset_options => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | clear_options => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | has_options => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | num_options => 'count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | builder => 'build_options' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub options_ref { [shift->options] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # this is used for rendering | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 43 | has 'options_index' => ( traits => ['Counter'], isa => 'Num', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw', default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | handles => { inc_options_index => 'inc', dec_options_index => 'dec', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | reset_options_index => 'reset' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 61 | ▶ | sub clear_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 61 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 61 | $self->next::method(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 61 | $self->reset_options_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 63 | ▶ | sub build_options { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_options: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 43 | has 'options_from' => ( isa => 'Str', is => 'rw', default => 'none' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 43 | has 'do_not_reload' => ( isa => 'Bool', is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 43 | has 'no_option_validation' => ( isa => 'Bool', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 43 | has 'option_wrapper' => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 107 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 107 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 107 | $self->build_options_method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 107 | ▶ | if( $self->options && $self->has_options ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->options and $self->has_options
MC/DC50%1/2
$self->options and $self->has_options
$self->options
$self->has_options
Truth table66%2/3
A and B
A= $self->optionsB= $self->has_options
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 44 | $self->options_from('build'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 44 | $self->default_from_options([$self->options]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 107 | $self->input_without_param; # vivify | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 43 | has 'options_method' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | traits => ['Code'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => 'CodeRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | writer => '_set_options_method', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | predicate => 'has_options_method', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | handles => { 'get_options' => 'execute_method' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 107 | ▶ | sub build_options_method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_options_method: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 107 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 107 | my $set_options = $self->set_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 107 | ▶ | $set_options ||= "options_" . HTML::FormHandler::Field::convert_full_name($self->full_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$set_options ||= 'options_' . HTML::FormHandler::Field::convert_full_name($self->full_name)
MC/DC0%0/1
$set_options ||= 'options_' . HTML::FormHandler::Field::convert_full_name($self->full_name)
$set_options
Truth table50%1/2
A
A= $set_options
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 107 | ▶ | if ( $self->form && $self->form->can($set_options) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->form and $self->form->can($set_options)
MC/DC100%2/2
$self->form and $self->form->can($set_options)
$self->form
$self->form->can($set_options)
Truth table100%3/3
A and B
A= $self->formB= $self->form->can($set_options)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 55 | my $attr = $self->form->meta->find_method_by_name( $set_options ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 55 | ▶ | if ( $attr and $attr->isa('Moose::Meta::Method::Accessor') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr and $attr->isa("Moose::Meta::Method::Accessor")
MC/DC50%1/2
$attr and $attr->isa("Moose::Meta::Method::Accessor")
$attr
$attr->isa("Moose::Meta::Method::Accessor")
Truth table66%2/3
A and B
A= $attrB= $attr->isa("Moose::Meta::Method::Accessor")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | $self->_set_options_method( sub { my $self = shift; $self->form->$set_options; } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 53 | ▶ | $self->_set_options_method( sub { my $self = shift; $self->form->$set_options($self); } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 43 | has 'sort_options_method' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | traits => ['Code'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | isa => 'CodeRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | predicate => 'has_sort_options_method', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sort_options => 'execute_method', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 43 | has 'set_options' => ( isa => 'Str', is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 43 | has 'multiple' => ( isa => 'Bool', is => 'rw', default => '0' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # following is for unusual case where a multiple select is a has_many type relation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 43 | has 'has_many' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 43 | has 'size' => ( isa => 'Int|Undef', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 43 | has 'label_column' => ( isa => 'Str', is => 'rw', default => 'name' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 43 | has 'localize_labels' => ( isa => 'Bool', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 43 | has 'active_column' => ( isa => 'Str', is => 'rw', default => 'active' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 43 | has 'auto_widget_size' => ( isa => 'Int', is => 'rw', default => '0' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 43 | has 'sort_column' => ( isa => 'Str|ArrayRef[Str]', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 43 | has '+widget' => ( default => 'Select' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub html_element { 'select' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html_element: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 43 | has '+type_attr' => ( default => 'select' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 43 | has 'empty_select' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 107 | ▶ | has '+deflate_method' => ( default => sub { \&select_deflate } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 43 | has '+input_without_param' => ( lazy => 1, builder => 'build_input_without_param' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 107 | ▶ | sub build_input_without_param { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_input_without_param: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 107 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 107 | ▶ | if( $self->multiple ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 39 | $self->not_nullable(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 39 | return []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 68 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 43 | has 'value_when_empty' => ( is => 'ro', lazy => 1, builder => 'build_value_when_empty' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 28 | ▶ | sub build_value_when_empty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_value_when_empty: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | ▶ | return [] if $self->multiple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 43 | our $class_messages = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'select_not_multiple' => 'This field does not take multiple values', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'select_invalid_value' => '\'[_1]\' is not a valid value', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 28 | ▶ | sub get_class_messages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_class_messages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 28 | %{ $self->next::method }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | %$class_messages, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub select_widget { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_widget: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $size = $field->auto_widget_size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return $field->widget unless $field->widget eq 'Select' && $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$field->widget eq "Select" and $size
MC/DC0%0/2
$field->widget eq "Select" and $size
$field->widget eq "Select"
$size
Truth table0%0/3
A and B
A= $field->widget eq "Select"B= $size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $options = $field->options || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$field->options || []
MC/DC0%0/1
$field->options || []
$field->options
Truth table0%0/2
A
A= $field->options
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return 'Select' if @$options > $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return $field->multiple ? 'checkbox_group' : 'radio_group'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | ▶ | sub as_label { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_label: called CC=11 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | ▶ | $value = $self->value unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | if ( $self->multiple ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | unless ( ref($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if( $self->has_inflate_default_method ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my @values = $self->inflate_default($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $value = \@values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # not sure under what circumstances this would happen, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # just in case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | my @labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | my %value_hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | @value_hash{@$value} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | for ( $self->options ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 12 | ▶ | if ( exists $value_hash{$_->{value}} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | push @labels, $_->{label}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | delete $value_hash{$_->{value}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 8 | ▶ | last unless keys %value_hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | my $str = join(', ', @labels); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | for ( $self->options ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $_->{label} if $_->{value} eq $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 115 | ▶ | sub _inner_validate_field { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inner_validate_field: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 115 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 115 | my $value = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 115 | ▶ | return unless defined $value; # nothing to check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 115 | ▶ | if ( ref $value eq 'ARRAY' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
ref $value eq "ARRAY" and not $self->can("multiple") && $self->multiple
$self->can('multiple') && $self->multiple
MC/DC66%2/3
ref $value eq "ARRAY" and not $self->can("multiple") && $self->multiple
ref $value eq "ARRAY"
$self->can('multiple')
$self->multiple
Truth table75%3/4
A and not(B && C)
A= ref $value eq "ARRAY"B= $self->can('multiple')C= $self->multiple
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | !( $self->can('multiple') && $self->multiple ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | $self->add_error( $self->get_message('select_not_multiple') ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ▶ | elsif ( ref $value ne 'ARRAY' && $self->multiple ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $value ne "ARRAY" and $self->multiple
MC/DC100%2/2
ref $value ne "ARRAY" and $self->multiple
ref $value ne "ARRAY"
$self->multiple
Truth table100%3/3
A and B
A= ref $value ne "ARRAY"B= $self->multiple
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | $value = [$value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | $self->_set_value($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 113 | ▶ | return if $self->no_option_validation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # create a lookup hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 112 | my %options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 112 | foreach my $opt ( @{ $self->options } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1433 | ▶ | if ( exists $opt->{group} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 12 | foreach my $group_opt ( @{ $opt->{options} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 36 | $options{$group_opt->{value}} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1421 | $options{$opt->{value}} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 112 | ▶ | if( $self->has_many ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | $value = [map { $_->{$self->has_many} } @$value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 112 | ▶ | for my $value ( ref $value eq 'ARRAY' ? @$value : ($value) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 125 | ▶ | unless ( $options{$value} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 26 | $self->add_error($self->get_message('select_invalid_value'), $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 86 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 20 | ▶ | sub _result_from_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_from_object: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 20 | my ( $self, $result, $item ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 20 | $result = $self->next::method( $result, $item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 20 | $self->_load_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 20 | ▶ | $result->_set_value($self->default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->default and not $result->has_value
MC/DC0%0/2
defined $self->default and not $result->has_value
defined $self->default
not $result->has_value
Truth table33%1/3
A and not(B)
A= defined $self->defaultB= not $result->has_value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | if( defined $self->default && not $result->has_value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 20 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 135 | ▶ | sub _result_from_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_from_fields: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 135 | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 135 | $result = $self->next::method($result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 135 | $self->_load_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 135 | ▶ | $result->_set_value($self->default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->default and not $result->has_value
MC/DC100%2/2
defined $self->default and not $result->has_value
defined $self->default
not $result->has_value
Truth table100%3/3
A and not(B)
A= defined $self->defaultB= not $result->has_value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | if( defined $self->default && not $result->has_value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 135 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 81 | ▶ | sub _result_from_input { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_from_input: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 81 | my ( $self, $result, $input, $exists ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 81 | ▶ | $input = ref $input eq 'ARRAY' ? $input : [$input] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | if $self->multiple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 81 | $result = $self->next::method( $result, $input, $exists ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 81 | $self->_load_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 81 | ▶ | $result->_set_value($self->default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->default and not $result->has_value
MC/DC100%2/2
defined $self->default and not $result->has_value
defined $self->default
not $result->has_value
Truth table100%3/3
A and not(B)
A= defined $self->defaultB= not $result->has_value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | if( defined $self->default && not $result->has_value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 81 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 236 | ▶ | sub _load_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_options: called CC=13 SCAR=26.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 236 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 236 | ▶ | if ( $self->options_from eq 'build' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->options_from eq "build" or $self->has_options and $self->do_not_reload
$self->has_options and $self->do_not_reload
MC/DC33%1/3
$self->options_from eq "build" or $self->has_options and $self->do_not_reload
$self->options_from eq "build"
$self->has_options
$self->do_not_reload
Truth table75%3/4
A or B and C
A= $self->options_from eq "build"B= $self->has_optionsC= $self->do_not_reload
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ( $self->has_options && $self->do_not_reload ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 168 | my @options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 168 | ▶ | if( $self->has_options_method ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 158 | @options = $self->get_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 158 | $self->options_from('method'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | elsif ( $self->form ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 10 | my $full_accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 10 | ▶ | $full_accessor = $self->parent->full_accessor if $self->parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 10 | @options = $self->form->lookup_options( $self, $full_accessor ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 10 | ▶ | $self->options_from('model') if scalar @options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 168 | ▶ | return unless @options; # so if there isn't an options method and no options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # from a table, already set options attributes stays put | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # possibilities: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # @options = ( 1 => 'one', 2 => 'two' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # @options = ([ 1 => 'one', 2 => 'tw' ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # @options = ([ { value => 1, label => 'one'}, { value => 2, label => 'two'}]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # @options = ([[ 'one', 'two' ]]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 158 | ▶ | my $opts = ref $options[0] eq 'ARRAY' ? $options[0] : \@options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 158 | ▶ | if ( ref $opts->[0] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # do the array of hashrefs separately so we can get the defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 26 | $self->default_from_options($opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 158 | $opts = $self->options($opts); # coerce will reformat | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 158 | ▶ | if ($opts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # sort options if sort method exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 158 | ▶ | $opts = $self->sort_options($opts) if $self->has_sort_options_method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 158 | $self->options($opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # This is because setting 'checked => 1' or 'selected => 1' in an options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # hashref is the equivalent of setting a default on the field. Originally | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # that was handled only in rendering, but it moved knowledge about where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # the 'fif' value came from into the renderer, which was bad. So instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # we're setting the defaults from the options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # It's probably better to use 'defaults' to start with, but since there are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # people using this method, this at least normalizes it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 70 | ▶ | sub default_from_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_from_options: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 70 | my ( $self, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 70 | ▶ | my @defaults = map { $_->{value} } grep { $_->{checked} || $_->{selected} } @$options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{'checked'} || $_->{'selected'}
MC/DC50%1/2
$_->{'checked'} || $_->{'selected'}
$_->{'checked'}
$_->{'selected'}
Truth table66%2/3
A || B
A= $_->{'checked'}B= $_->{'selected'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 70 | ▶ | if( scalar @defaults ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | if( $self->multiple ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | $self->default(\@defaults); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | $self->default($defaults[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 820 | ▶ | before 'value' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 820 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 820 | ▶ | return undef unless $self->has_result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 819 | my $value = $self->result->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 819 | ▶ | if( $self->multiple ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 258 | ▶ | if ( !defined $value || $value eq '' || ( ref $value eq 'ARRAY' && scalar @$value == 0 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition88%8/9
not defined $value or $value eq "" or ref $value eq "ARRAY" and scalar @$value == 0
not defined $value or $value eq ""
ref $value eq "ARRAY" and scalar @$value == 0
MC/DC75%3/4
not defined $value or $value eq "" or ref $value eq "ARRAY" and scalar @$value == 0
not defined $value
$value eq ""
ref $value eq "ARRAY"
scalar @$value == 0
Truth table80%4/5
not(A) or B or C and D
A= not defined $valueB= $value eq ""C= ref $value eq "ARRAY"D= scalar @$value == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 112 | $self->_set_value( $self->value_when_empty ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | ▶ | elsif ( $self->has_many && scalar @$value && ref($value->[0]) ne 'HASH' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$self->has_many and scalar @$value and ref $value->[0] ne "HASH"
$self->has_many and scalar @$value
MC/DC100%2/2
$self->has_many and scalar @$value and ref $value->[0] ne "HASH"
$self->has_many
ref $value->[0] ne "HASH"
Truth table100%3/3
A and B
A= $self->has_manyB= ref $value->[0] ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | my @new_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 4 | foreach my $ele (@$value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | push @new_values, { $self->has_many => $ele }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | $self->_set_value( \@new_values ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 43 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 137 | ▶ | sub select_deflate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_deflate: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 137 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 137 | ▶ | return $value unless ( $self->has_many && $self->multiple ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->has_many and $self->multiple
MC/DC50%1/2
$self->has_many and $self->multiple
$self->has_many
$self->multiple
Truth table66%2/3
A and B
A= $self->has_manyB= $self->multiple
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # the following is for the edge case of a has_many select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | ▶ | return $value unless ref($value) eq 'ARRAY' && scalar @$value && ref($value->[0]) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
ref $value eq "ARRAY" and scalar @$value and ref $value->[0] eq "HASH"
ref $value eq "ARRAY" and scalar @$value
MC/DC0%0/2
ref $value eq "ARRAY" and scalar @$value and ref $value->[0] eq "HASH"
ref $value eq "ARRAY"
ref $value->[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $value eq "ARRAY"B= ref $value->[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | return [map { $_->{$self->has_many} } @$value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 43 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 43 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 43 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||