FormHandler/Widget/Field/RadioGroup.pm

filter: Statementstmt 94.8% 73 / 77 Branchbran 70.0% 14 / 20 Conditioncond 63.1% 12 / 19 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 7 totaltotal 77.4% 113 / 146 CC 20 SCAR 16.8
CC
20
Cov
85%
render_element
10.1
wrap_radio
5.8
render
3.1
CRAP 5.4
« FormHandler/Foo.pm ↑ Summary FormHandler/Field/Captcha.pm »
1 package HTML::FormHandler::Widget::Field::RadioGroup;
2 # ABSTRACT: radio group rendering widget
3 11 $HTML::FormHandler::Widget::Field::RadioGroup::VERSION = '0.410002';
4 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 7 ▶sub type_attr { 'radio' }
Subroutine type_attr: called CC=1 SCAR=0.0
Pod undocumented
11  
12 15 ▶sub render {
Subroutine render: called CC=3 SCAR=11.2
Pod undocumented
13 15 my ( $self, $result ) = @_;
14 15 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
690
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
15 15 ▶ die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 15 15
16 15 my $output = $self->render_element( $result );
17 15 return $self->wrap_field( $result, $output );
18 }
19  
20 15 ▶sub render_element {
Subroutine render_element: called CC=10 SCAR=23.1
Pod undocumented
21 15 my ( $self, $result ) = @_;
22 15 ▶ $result ||= $self->result;
Condition33%1/3
$result ||= $self->result
l!l&&r!l&&!r
1500
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table33%1/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
23  
24 15 my $output = '';
25 15 ▶ $output .= "<br />" if $self->get_tag('radio_br_after');
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_tag("radio_br_after") 1 14 15
26  
27 15 foreach my $option ( @{ $self->{options} } ) {
28 37 ▶ if ( my $label = $option->{group} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $label = $option->{'group'}) { } 5 32 37
29 5 ▶ $label = $self->_localize( $label ) if $self->localize_labels;
Branch: 1 branch
BranchTrueFalseTotal
if $self->localize_labels 0 5 5
30 5 ▶ my $attr = $option->{attributes} || {};
Condition100%2/2
$option->{'attributes'} || {}
l!l
14
MC/DC100%1/1
$option->{'attributes'} || {}
$option->{'attributes'}
Truth table100%2/2
A
A= $option->{'attributes'}
Aresult
11
00
31 5 my $attr_str = process_attrs($attr);
32 5 ▶ my $lattr = $option->{label_attributes} || {};
Condition100%2/2
$option->{'label_attributes'} || {}
l!l
14
MC/DC100%1/1
$option->{'label_attributes'} || {}
$option->{'label_attributes'}
Truth table100%2/2
A
A= $option->{'label_attributes'}
Aresult
11
00
33 5 my $lattr_str= process_attrs($lattr);
34 5 $output .= qq{\n<div$attr_str><label$lattr_str>} . encode_entities($label, '<>&') . qq{</label>};
35 5 foreach my $group_opt ( @{ $option->{options} } ) {
36 13 $output .= $self->render_option( $group_opt, $result );
37 }
38 5 $output .= qq{\n</div>};
39 }
40 else {
41 32 $output .= $self->render_option( $option, $result );
42 }
43 37 ▶ $output .= '<br />' if $self->get_tag('radio_br_after');
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_tag("radio_br_after") 2 35 37
44 }
45 15 $self->reset_options_index;
46 15 return $output;
47 }
48  
49 47 ▶sub render_option {
Subroutine render_option: called CC=2 SCAR=7.0
Pod undocumented
50 47 my ( $self, $option, $result ) = @_;
51  
52 47 ▶ $result ||= $result;
Condition66%2/3
$result ||= $result
l!l&&r!l&&!r
4601
MC/DC50%1/2
$result ||= $result
$result $result
Truth table66%2/3
A ||= B
A= $resultB= $result
ABresult
1X1
011
000
53 47 my $rendered_widget = $self->render_radio( $result, $option );
54 47 my $output = $self->wrap_radio( $rendered_widget, $option->{label} );
55 47 $self->inc_options_index;
56 47 return $output;
57 }
58  
59 1 ▶sub render_wrapped_option {
Subroutine render_wrapped_option: called CC=2 SCAR=7.4
Pod undocumented
60 1 my ( $self, $option, $result ) = @_;
61  
62 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
63 1 my $output = $self->render_option( $option, $result );
64 1 return $self->wrap_field( $result, $output );
65 }
66  
67 47 ▶sub render_radio {
Subroutine render_radio: called CC=3 SCAR=11.0
Pod undocumented
68 47 my ( $self, $result, $option ) = @_;
69 47 ▶ $result ||= $self->result;
Condition66%2/3
$result ||= $self->result
l!l&&r!l&&!r
4610
MC/DC0%0/2
$result ||= $self->result
$result $self->result
Truth table66%2/3
A ||= B
A= $resultB= $self->result
ABresult
1X1
011
000
70  
71 47 my $value = $option->{value};
72 47 my $id = $self->id . "." . $self->options_index;
73 47 my $output = '<input type="radio" name="'
74 . $self->html_name . qq{" id="$id" value="}
75 . $self->html_filter($value) . '"';
76 47 ▶ $output .= ' checked="checked"'
Branch: 1 branch
BranchTrueFalseTotal
if $result->fif eq $value 7 40 47
77 if $result->fif eq $value;
78 47 $output .= process_attrs($option->{attributes});
79 47 $output .= ' />';
80 47 return $output;
81 }
82  
83 47 ▶sub wrap_radio {
Subroutine wrap_radio: called CC=5 SCAR=17.6
Pod undocumented
84 47 my ( $self, $rendered_widget, $option_label ) = @_;
85  
86 47 my $id = $self->id . "." . $self->options_index;
87 47 my $for = qq{ for="$id"};
88  
89 # use "simple" label attributes for inner label
90 47 my @label_class = ('radio');
91 47 ▶ if ( $self->get_tag('inline') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("inline")) 0 47 47
92 0 my $class = 'inline';
93 0 ▶ $class = 'radio-inline' if $self->has_flag('is_b3');
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_flag("is_b3") 0 0 0
94 0 push @label_class, $class;
95 }
96 47 my $lattrs = process_attrs( { class => \@label_class } );
97  
98 # return wrapped radio, either on left or right
99 47 my $label = encode_entities( $self->_localize($option_label), '<>&' );
100 47 my $output = '';
101 47 ▶ if ( $self->get_tag('label_left') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag('label_left')) { } 0 47 47
102 0 $output = qq{<label$lattrs$for>\n$label\n$rendered_widget</label>};
103 }
104 else {
105 47 $output = qq{<label$lattrs$for>$rendered_widget\n$label\n</label>};
106 }
107 47 ▶ if ( $self->get_tag('radio_element_wrapper') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("radio_element_wrapper")) 12 35 47
108 12 $output = qq{<div class="radio">$output</div>};
109 }
110 47 return $output;
111 }
112  
113 11 1;
114  
115 __END__
« FormHandler/Foo.pm ↑ Summary FormHandler/Field/Captcha.pm »