| 1 | package HTML::FormHandler::Widget::Field::CheckboxGroup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: checkbox group field role | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | $HTML::FormHandler::Widget::Field::CheckboxGroup::VERSION = '0.410000'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use Moose::Role; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use namespace::autoclean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | sub render { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | $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 | 10 | ▶ | die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | my $output = $self->render_element( $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | return $self->wrap_field( $result, $output ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | sub render_element { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | my ( $self, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_element: called CC=8 SCAR=20.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | ▶ | $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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # loop through options | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | my $output = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | foreach my $option ( @{ $self->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 30 | ▶ | if ( my $label = $option->{group} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | $label = $self->_localize( $label ) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | ▶ | my $attr = $option->{attributes} || {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option->{'attributes'} || {}
MC/DC100%1/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table100%2/2
A
A= $option->{'attributes'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | my $attr_str = process_attrs($attr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | my $lattr = $option->{label_attributes} || {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$option->{'label_attributes'} || {}
MC/DC100%1/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table100%2/2
A
A= $option->{'label_attributes'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | my $lattr_str= process_attrs($lattr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | $output .= qq{\n<div$attr_str><label$lattr_str>$label</label>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | foreach my $group_opt ( @{ $option->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 15 | $output .= $self->render_option( $group_opt, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | $output .= qq{\n</div>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | $output .= $self->render_option( $option, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 10 | $self->reset_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | sub render_option { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 40 | ▶ | my ( $self, $option, $result ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_option: called CC=15 SCAR=28.3
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # get existing values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 40 | my $fif = $result->fif; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 40 | my %fif_lookup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 40 | ▶ | @fif_lookup{@$fif} = () if $self->multiple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # create option label attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 40 | ▶ | my $lattr = $option->{label_attributes} || {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$option->{'label_attributes'} || {}
MC/DC0%0/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table50%1/2
A
A= $option->{'label_attributes'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 40 | push @{ $lattr->{class} }, 'checkbox'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 40 | ▶ | if ( $self->get_tag('inline') ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | my $class = 'inline'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | ▶ | $class = 'checkbox-inline' if $self->has_flag('is_b3'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 9 | push @{ $lattr->{class} }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 40 | my $lattr_str = process_attrs( $lattr ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 40 | my $id = $self->id . '.' . $self->options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 40 | my $output = qq{\n<label$lattr_str for="$id">}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 40 | my $value = $option->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 40 | $output .= qq{\n<input type="checkbox"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 40 | $output .= qq{ value="} . $self->html_filter($value) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 40 | $output .= qq{ name="} . $self->html_name . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 40 | $output .= qq{ id="$id"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # handle option attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 40 | ▶ | my $attr = $option->{attributes} || {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$option->{'attributes'} || {}
MC/DC0%0/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table50%1/2
A
A= $option->{'attributes'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 40 | ▶ | 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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $attr->{disabled} = 'disabled'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 40 | ▶ | if ( defined $fif && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/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/DC0%0/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 table16%1/6
A and B and C or D
A= defined $fifB= $self->multipleC= exists $fif_lookup{$value}D= $fif eq $value
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ( ( $self->multiple && exists $fif_lookup{$value} ) || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ( $fif eq $value ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | $attr->{checked} = 'checked'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 40 | $output .= process_attrs($attr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 40 | $output .= " />\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # handle label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 40 | my $label = $option->{label}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 40 | ▶ | $label = $self->_localize($label) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 40 | $output .= $self->html_filter($label); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 40 | $output .= "\n</label>"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 40 | $self->inc_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 40 | ▶ | if ($self->get_tag('checkbox_element_wrapper')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | $output = qq{<div class="checkbox">$output</div>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 40 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 7 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =pod | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =encoding UTF-8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =head1 NAME | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | HTML::FormHandler::Widget::Field::CheckboxGroup - checkbox group field role | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =head1 VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | version 0.410000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head1 SYNOPSIS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | Checkbox group widget for rendering multiple selects. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | Checkbox element label class is 'checkbox', plus 'inline' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | if the 'inline' tag is set. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | Options hashrefs must have the keys 'value', and 'label'. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | They may have an 'attributes' hashref key. The 'checked' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | attribute should not be set in the options hashref. It should | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | be set by supplying a default value or from params input. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | See L<HTML::FormHandler::Field::Select> for documentation on | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | select fields and options. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =head1 AUTHOR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | FormHandler Contributors - see HTML::FormHandler | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 COPYRIGHT AND LICENSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | This software is copyright (c) 2017 by Gerda Shank. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | This is free software; you can redistribute it and/or modify it under | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | the same terms as the Perl 5 programming language system itself. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||