| 1 | package HTML::FormHandler::Widget::Field::CheckboxGroup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: checkbox group field role | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | $HTML::FormHandler::Widget::Field::CheckboxGroup::VERSION = '0.410002'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moose::Role; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use namespace::autoclean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use HTML::Entities qw( encode_entities ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | sub render { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | my ( $self, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | $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 | 11 | ▶ | die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | my $output = $self->render_element( $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | return $self->wrap_field( $result, $output ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | sub render_element { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_element: called CC=8 SCAR=20.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | my ( $self, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | $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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # loop through options | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 11 | my $output = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | foreach my $option ( @{ $self->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 31 | ▶ | if ( my $label = $option->{group} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | $label = $self->_localize( $label ) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | 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'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | my $attr_str = process_attrs($attr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | 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'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my $lattr_str= process_attrs($lattr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | $output .= qq{\n<div$attr_str><label$lattr_str>} . encode_entities($label, '<>&') . qq{</label>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | foreach my $group_opt ( @{ $option->{options} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 17 | $output .= $self->render_option( $group_opt, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | $output .= qq{\n</div>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 25 | $output .= $self->render_option( $option, $result ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | $self->reset_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 42 | ▶ | sub render_option { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_option: called CC=15 SCAR=28.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 42 | my ( $self, $option, $result ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 42 | ▶ | $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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # get existing values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 42 | my $fif = $result->fif; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 42 | my %fif_lookup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 42 | ▶ | @fif_lookup{@$fif} = () if $self->multiple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # create option label attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 42 | ▶ | 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'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 42 | push @{ $lattr->{class} }, 'checkbox'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 42 | ▶ | if ( $self->get_tag('inline') ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | my $class = 'inline'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 9 | ▶ | $class = 'checkbox-inline' if $self->has_flag('is_b3'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 9 | push @{ $lattr->{class} }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 42 | my $lattr_str = process_attrs( $lattr ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 42 | my $id = $self->id . '.' . $self->options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 42 | my $output = qq{\n<label$lattr_str for="$id">}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 42 | my $value = $option->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 42 | $output .= qq{\n<input type="checkbox"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 42 | $output .= qq{ value="} . $self->html_filter($value) . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 42 | $output .= qq{ name="} . $self->html_name . '"'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 42 | $output .= qq{ id="$id"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # handle option attributes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 42 | ▶ | 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'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 42 | ▶ | 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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $attr->{disabled} = 'disabled'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 42 | ▶ | if ( defined $fif && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/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 table33%2/6
A and B and C or D
A= defined $fifB= $self->multipleC= exists $fif_lookup{$value}D= $fif eq $value
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ( ( $self->multiple && exists $fif_lookup{$value} ) || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ( $fif eq $value ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | $attr->{checked} = 'checked'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 42 | $output .= process_attrs($attr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 42 | $output .= " />\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # handle label | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 42 | my $label = $option->{label}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 42 | ▶ | $label = $self->_localize($label) if $self->localize_labels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 42 | $output .= encode_entities($label, '<>&'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 42 | $output .= "\n</label>"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 42 | $self->inc_options_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 42 | ▶ | if ($self->get_tag('checkbox_element_wrapper')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $output = qq{<div class="checkbox">$output</div>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 42 | return $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||