| 1 | package HTML::FormHandler::Widget::Field::Select; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: select field rendering widget | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 33 | $HTML::FormHandler::Widget::Field::Select::VERSION = '0.410002'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use Moose::Role; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 33 | ▶ | use HTML::Entities qw( encode_entities ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use namespace::autoclean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 33 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | sub render { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | my ( $self, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | ▶ | $result ||= $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 40 | ▶ | die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 40 | my $output = $self->render_element( $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 40 | return $self->wrap_field( $result, $output ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 41 | ▶ | sub render_element { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_element: called CC=7 SCAR=19.6
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 41 | my ( $self, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 41 | ▶ | $result ||= $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # create select element | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 41 | my $output = $self->render_select_start( $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # create empty select | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 41 | ▶ | if( defined $self->empty_select ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | $output .= $self->render_empty_select; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # loop through options | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 41 | foreach my $option ( @{ $self->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 133 | ▶ | if ( my $label = $option->{group} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | $label = $self->_localize( $label ) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | $output .= qq{\n<optgroup label="} . encode_entities($label, '"&') . qq{">}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | foreach my $group_opt ( @{ $option->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | $output .= $self->render_option( $group_opt, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | $output .= qq{\n</optgroup>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 129 | $output .= $self->render_option( $option, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 41 | $self->reset_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 41 | $output .= '</select>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 41 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 41 | ▶ | sub render_select_start { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_select_start: called CC=4 SCAR=13.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 41 | my ( $self, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 41 | ▶ | $result ||= $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 41 | my $id = $self->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 41 | my $output = '<select name="' . $self->html_name . qq{" id="$id"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 41 | ▶ | $output .= ' multiple="multiple"' if $self->multiple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 41 | ▶ | $output .= ' size="' . $self->size . '"' if defined $self->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 41 | $output .= process_attrs($self->element_attributes($result)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 41 | $output .= '>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 41 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | sub render_empty_select { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_empty_select: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | my $label = $self->_localize($self->empty_select); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | my $id = $self->id . "." . $self->options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | my $output = qq{\n<option value="" id="$id">$label</option>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | $self->inc_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 140 | ▶ | sub render_option { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_option: called CC=12 SCAR=25.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 140 | my ( $self, $option, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 140 | ▶ | $result ||= $self->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$result ||= $self->result
MC/DC0%0/2
$result ||= $self->result
$result
$self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # current values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 140 | my $fif = $result->fif; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 140 | my %fif_lookup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 140 | ▶ | @fif_lookup{@$fif} = () if $self->multiple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # not sure why the value of an option would be undef, but just in case, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # set to empty string because of 'eq' below | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 140 | ▶ | my $value = defined $option->{value} ? $option->{value} : ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 140 | my $id = $self->id . '.' . $self->options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 140 | my $output = qq{\n<option value="} . $self->html_filter($value) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 140 | $output .= qq{ id="$id"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # handle option attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 140 | ▶ | my $attrs = $option->{attributes} || {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$option->{'attributes'} || {}
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 140 | ▶ | if( defined $option->{disabled} && $option->{disabled} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $option->{"disabled"} and $option->{"disabled"}
MC/DC0%0/2
defined $option->{"disabled"} and $option->{"disabled"}
defined $option->{"disabled"}
$option->{"disabled"}
Truth table33%1/3
A and B
A= defined $option->{"disabled"}B= $option->{"disabled"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $attrs->{disabled} = 'disabled'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 140 | ▶ | if ( defined $fif && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
$self->multiple and exists $fif_lookup{$value} or $fif eq $value
$self->multiple and exists $fif_lookup{$value}
MC/DC75%3/4
defined $fif and $self->multiple && exists $fif_lookup{$value} || $fif eq $value
defined $fif
$self->multiple
exists $fif_lookup{$value}
$fif eq $value
Truth table66%4/6
A and B and C or D
A= defined $fifB= $self->multipleC= exists $fif_lookup{$value}D= $fif eq $value
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ( ( $self->multiple && exists $fif_lookup{$value} ) || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ( $fif eq $value ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 31 | $attrs->{selected} = 'selected'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 140 | $output .= process_attrs($attrs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # handle label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 140 | my $label = $option->{label}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 140 | ▶ | $label = $self->_localize($label) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 140 | $output .= '>' . encode_entities($label, '<>&') . '</option>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 140 | $self->inc_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 140 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 33 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||