FormHandler/Widget/Field/RadioGroup.pm

filter: Statementstmt 94.5% 70 / 74 Branchbran 70.0% 14 / 20 Conditioncond 63.1% 12 / 19 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 7 totaltotal 76.7% 109 / 142 CC 20 SCAR 17.1
CC
20
Cov
85%
render_element
10.1
wrap_radio
5.8
render
3.1
CRAP 5.5
« FormHandler/Widget/Wrapper/Base.pm ↑ Summary FormHandler/Foo.pm »
1 package HTML::FormHandler::Widget::Field::RadioGroup;
2 # ABSTRACT: radio group rendering widget
3 10 $HTML::FormHandler::Widget::Field::RadioGroup::VERSION = '0.410001';
4 10 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 7 ▶sub type_attr { 'radio' }
Subroutine type_attr: called CC=1 SCAR=0.0
Pod undocumented
10  
11 sub render {
12 14 ▶ my ( $self, $result ) = @_;
Subroutine render: called CC=3 SCAR=11.2
Pod undocumented
13 14 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
680
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
14 14 ▶ die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 14 14
15 14 my $output = $self->render_element( $result );
16 14 return $self->wrap_field( $result, $output );
17 }
18  
19 sub render_element {
20 14 ▶ my ( $self, $result ) = @_;
Subroutine render_element: called CC=10 SCAR=23.1
Pod undocumented
21 14 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
1400
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
22  
23 14 my $output = '';
24 14 ▶ $output .= "<br />" if $self->get_tag('radio_br_after');
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_tag("radio_br_after") 1 13 14
25  
26 14 foreach my $option ( @{ $self->{options} } ) {
27 36 ▶ if ( my $label = $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = $option->{'group'}) { } 4 32 36
28 4 ▶ $label = $self->_localize( $label ) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 4 4
29 4 ▶ my $attr = $option->{attributes} || {};
Condition100%2/2
$option->{'attributes'} || {}
l!l
13
MC/DC100%1/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table100%2/2
A
A= $option->{'attributes'}
Aresult
11
00
30 4 my $attr_str = process_attrs($attr);
31 4 ▶ my $lattr = $option->{label_attributes} || {};
Condition100%2/2
$option->{'label_attributes'} || {}
l!l
13
MC/DC100%1/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table100%2/2
A
A= $option->{'label_attributes'}
Aresult
11
00
32 4 my $lattr_str= process_attrs($lattr);
33 4 $output .= qq{\n<div$attr_str><label$lattr_str>$label</label>};
34 4 foreach my $group_opt ( @{ $option->{options} } ) {
35 11 $output .= $self->render_option( $group_opt, $result );
36 }
37 4 $output .= qq{\n</div>};
38 }
39 else {
40 32 $output .= $self->render_option( $option, $result );
41 }
42 36 ▶ $output .= '<br />' if $self->get_tag('radio_br_after');
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_tag("radio_br_after") 2 34 36
43 }
44 14 $self->reset_options_index;
45 14 return $output;
46 }
47  
48 sub render_option {
49 45 ▶ my ( $self, $option, $result ) = @_;
Subroutine render_option: called CC=2 SCAR=7.0
Pod undocumented
50  
51 45 ▶ $result ||= $result;
Condition66%2/3
$result ||= $result
l!l&&r!l&&!r
4401
MC/DC50%1/2
$result ||= $result
$result $result
Truth table66%2/3
A ||= B
A= $resultB= $result
ABresult
1X1
011
000
52 45 my $rendered_widget = $self->render_radio( $result, $option );
53 45 my $output = $self->wrap_radio( $rendered_widget, $option->{label} );
54 45 $self->inc_options_index;
55 45 return $output;
56 }
57  
58 sub render_wrapped_option {
59 1 ▶ my ( $self, $option, $result ) = @_;
Subroutine render_wrapped_option: called CC=2 SCAR=7.4
Pod undocumented
60  
61 1 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
010
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
62 1 my $output = $self->render_option( $option, $result );
63 1 return $self->wrap_field( $result, $output );
64 }
65  
66 sub render_radio {
67 45 ▶ my ( $self, $result, $option ) = @_;
Subroutine render_radio: called CC=3 SCAR=11.0
Pod undocumented
68 45 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
4410
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
69  
70 45 my $value = $option->{value};
71 45 my $id = $self->id . "." . $self->options_index;
72 45 my $output = '<input type="radio" name="'
73 . $self->html_name . qq{" id="$id" value="}
74 . $self->html_filter($value) . '"';
75 45 ▶ $output .= ' checked="checked"'
Branch: 1 branch
BranchTrueFalseTotal
if $result->fif eq $value 7 38 45
76 if $result->fif eq $value;
77 45 $output .= process_attrs($option->{attributes});
78 45 $output .= ' />';
79 45 return $output;
80 }
81  
82 sub wrap_radio {
83 45 ▶ my ( $self, $rendered_widget, $option_label ) = @_;
Subroutine wrap_radio: called CC=5 SCAR=17.6
Pod undocumented
84  
85 45 my $id = $self->id . "." . $self->options_index;
86 45 my $for = qq{ for="$id"};
87  
88 # use "simple" label attributes for inner label
89 45 my @label_class = ('radio');
90 45 ▶ if ( $self->get_tag('inline') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("inline")) 0 45 45
91 0 my $class = 'inline';
92 0 ▶ $class = 'radio-inline' if $self->has_flag('is_b3');
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_flag("is_b3") 0 0 0
93 0 push @label_class, $class;
94 }
95 45 my $lattrs = process_attrs( { class => \@label_class } );
96  
97 # return wrapped radio, either on left or right
98 45 my $label = $self->_localize($option_label);
99 45 my $output = '';
100 45 ▶ if ( $self->get_tag('label_left') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag('label_left')) { } 0 45 45
101 0 $output = qq{<label$lattrs$for>\n$label\n$rendered_widget</label>};
102 }
103 else {
104 45 $output = qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
105 }
106 45 ▶ if ( $self->get_tag('radio_element_wrapper') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("radio_element_wrapper")) 12 33 45
107 12 $output = qq{<div class="radio">$output</div>};
108 }
109 45 return $output;
110 }
111  
112 10 1;
113  
114 __END__
115  
116 =pod
117  
118 =encoding UTF-8
119  
120 =head1 NAME
121  
122 HTML::FormHandler::Widget::Field::RadioGroup - radio group rendering widget
123  
124 =head1 VERSION
125  
126 version 0.410001
127  
128 =head1 SYNOPSIS
129  
130 Renders a radio group (from a 'Select' field);
131  
132 Tags: radio_br_after
133  
134 See L<HTML::FormHandler::Field::Select> for documentation on
135 select fields and options.
136  
137 =head1 AUTHOR
138  
139 FormHandler Contributors - see HTML::FormHandler
140  
141 =head1 COPYRIGHT AND LICENSE
142  
143 This software is copyright (c) 2017 by Gerda Shank.
144  
145 This is free software; you can redistribute it and/or modify it under
146 the same terms as the Perl 5 programming language system itself.
147  
148 =cut
« FormHandler/Widget/Wrapper/Base.pm ↑ Summary FormHandler/Foo.pm »