| 1 | package HTML::FormHandler::Widget::Field::Select; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: select field rendering widget | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 32 | $HTML::FormHandler::Widget::Field::Select::VERSION = '0.410000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 32 | ▶ | use Moose::Role; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 32 | ▶ | use namespace::autoclean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 32 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | sub render { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 39 | ▶ | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 39 | ▶ | $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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 39 | ▶ | die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 39 | my $output = $self->render_element( $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 39 | return $self->wrap_field( $result, $output ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sub render_element { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 40 | ▶ | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_element: called CC=7 SCAR=19.6
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | ▶ | $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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # create select element | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 40 | my $output = $self->render_select_start( $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # create empty select | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 40 | ▶ | if( defined $self->empty_select ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | $output .= $self->render_empty_select; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # loop through options | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 40 | foreach my $option ( @{ $self->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 132 | ▶ | if ( my $label = $option->{group} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | $label = $self->_localize( $label ) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | $output .= qq{\n<optgroup label="$label">}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | foreach my $group_opt ( @{ $option->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 9 | $output .= $self->render_option( $group_opt, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | $output .= qq{\n</optgroup>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 129 | $output .= $self->render_option( $option, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 40 | $self->reset_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 40 | $output .= '</select>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 40 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub render_select_start { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 40 | ▶ | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_select_start: called CC=4 SCAR=13.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | ▶ | $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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 40 | my $id = $self->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 40 | my $output = '<select name="' . $self->html_name . qq{" id="$id"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 40 | ▶ | $output .= ' multiple="multiple"' if $self->multiple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 40 | ▶ | $output .= ' size="' . $self->size . '"' if defined $self->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 40 | $output .= process_attrs($self->element_attributes($result)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 40 | $output .= '>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 40 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sub render_empty_select { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_empty_select: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my $label = $self->_localize($self->empty_select); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | my $id = $self->id . "." . $self->options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | my $output = qq{\n<option value="" id="$id">$label</option>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | $self->inc_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub render_option { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 138 | ▶ | my ( $self, $option, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_option: called CC=12 SCAR=25.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 138 | ▶ | $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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # current values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 138 | my $fif = $result->fif; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 138 | my %fif_lookup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 138 | ▶ | @fif_lookup{@$fif} = () if $self->multiple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # not sure why the value of an option would be undef, but just in case, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # set to empty string because of 'eq' below | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 138 | ▶ | my $value = defined $option->{value} ? $option->{value} : ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 138 | my $id = $self->id . '.' . $self->options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 138 | my $output = qq{\n<option value="} . $self->html_filter($value) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 138 | $output .= qq{ id="$id"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # handle option attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 138 | ▶ | 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'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 138 | ▶ | 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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $attrs->{disabled} = 'disabled'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 138 | ▶ | 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/DC25%1/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 table50%3/6
A and B and C or D
A= defined $fifB= $self->multipleC= exists $fif_lookup{$value}D= $fif eq $value
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ( ( $self->multiple && exists $fif_lookup{$value} ) || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ( $fif eq $value ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 31 | $attrs->{selected} = 'selected'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 138 | $output .= process_attrs($attrs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # handle label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 138 | my $label = $option->{label}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 138 | ▶ | $label = $self->_localize($label) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 138 | $output .= '>' . ( $self->html_filter($label) ) . '</option>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 138 | $self->inc_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 138 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 32 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =pod | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | =encoding UTF-8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =head1 NAME | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | HTML::FormHandler::Widget::Field::Select - select field rendering widget | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | =head1 VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | version 0.410000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | =head1 DESCRIPTION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Renders single and multiple selects. Options hashrefs must | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | have 'value' and 'label' keys, and may have an 'attributes' key. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | See L<HTML::FormHandler::Field::Select> for documentation on | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | select fields and options. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 NAME | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | HTML::FormHandler::Widget::Field::Select | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 AUTHOR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | FormHandler Contributors - see HTML::FormHandler | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | =head1 COPYRIGHT AND LICENSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | This software is copyright (c) 2017 by Gerda Shank. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | This is free software; you can redistribute it and/or modify it under | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | the same terms as the Perl 5 programming language system itself. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||