FormHandler/Widget/Wrapper/Simple.pm

filter: Statementstmt 100% 48 / 48 Branchbran 95.0% 19 / 20 Conditioncond 66.6% 8 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 88.1% 82 / 93 CC 18 SCAR 27.1
CC
18
Cov
94%
wrap_field
18.1
BEGIN
1.0
BEGIN
1.0
CRAP 15.0
« FormHandler/Widget/Wrapper/Bootstrap.pm ↑ Summary FormHandler/BuildFields.pm »
1 package HTML::FormHandler::Widget::Wrapper::Simple;
2 # ABSTRACT: simple field wrapper
3 131 $HTML::FormHandler::Widget::Wrapper::Simple::VERSION = '0.410000';
4 131 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 131 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 131 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 131 ▶use HTML::FormHandler::Render::Util ('process_attrs');
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 131 with 'HTML::FormHandler::Widget::Wrapper::Base';
10  
11  
12  
13 sub wrap_field {
14 439 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine wrap_field: called CC=18 SCAR=29.0
Pod undocumented
15  
16 439 my $output;
17 # get wrapper tag if set
18 439 ▶ my $label_tag = $self->label_tag || '';
Condition50%1/2
$self->label_tag || ''
l!l
4390
MC/DC0%0/1
$self->label_tag || ''
$self->label_tag
Truth table50%1/2
A
A= $self->label_tag
Aresult
11
00
19 439 my $wrapper_tag;
20 439 ▶ if( $self->do_wrapper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_wrapper) 390 49 439
21 390 $output .= $self->get_tag('before_wrapper');
22 390 $wrapper_tag = $self->get_tag('wrapper_tag');
23 # default wrapper tags
24 390 ▶ $wrapper_tag ||= $self->has_flag('is_repeatable') ? 'fieldset' : 'div';
Branch: 1 branch
BranchTrueFalseTotal
$self->has_flag('is_repeatable') ? : 13 360 373
Condition66%2/3
$wrapper_tag ||= $self->has_flag("is_repeatable") ? "fieldset" : "div"
l!l&&r!l&&!r
173730
MC/DC0%0/2
$wrapper_tag ||= $self->has_flag("is_repeatable") ? "fieldset" : "div"
$wrapper_tag $self->has_flag("is_repeatable") ? "fieldset" : "div"
Truth table66%2/3
A ||= B
A= $wrapper_tagB= $self->has_flag("is_repeatable") ? "fieldset" : "div"
ABresult
1X1
011
000
25 # get attribute string
26 390 my $attrs = process_attrs( $self->wrapper_attributes($result) );
27 # write wrapper tag
28 390 $output .= qq{\n<$wrapper_tag$attrs>};
29 390 ▶ $label_tag = 'legend' if $wrapper_tag eq 'fieldset';
Branch: 1 branch
BranchTrueFalseTotal
if $wrapper_tag eq "fieldset" 19 371 390
30 }
31 # write label; special processing for checkboxes
32 439 ▶ $rendered_widget = $self->wrap_checkbox($result, $rendered_widget)
Branch: 1 branch
BranchTrueFalseTotal
if lc $self->widget eq "checkbox" 23 416 439
33 if ( lc $self->widget eq 'checkbox' );
34 438 ▶ $output .= "\n" . $self->do_render_label($result, $label_tag)
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_label 329 109 438
35 if $self->do_label;
36 # append 'before_element'
37 438 $output .= $self->get_tag('before_element');
38  
39 # start controls div
40 438 ▶ if ( $self->get_tag('controls_div') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->get_tag('controls_div')) { } 1 437 438
elsif ($self->has_element_wrapper_class) { } 1 436 437
41 1 $output .= qq{\n<div class="controls">};
42 }
43 elsif ( $self->has_element_wrapper_class ) {
44 1 my $ew_attr = $self->element_wrapper_attributes($result);
45 1 my $element_wrapper_attrs = process_attrs( $ew_attr );
46 1 $output .= qq{\n<div$element_wrapper_attrs>};
47 }
48  
49 # the input element itself
50 438 $output .= "\n$rendered_widget";
51  
52 # close controls div
53 438 ▶ if ( $self->get_tag('controls_div') || $self->has_element_wrapper_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_tag("controls_div") or $self->has_element_wrapper_class) 2 436 438
Condition100%3/3
$self->get_tag("controls_div") or $self->has_element_wrapper_class
l!l&&r!l&&!r
11436
MC/DC100%2/2
$self->get_tag("controls_div") or $self->has_element_wrapper_class
$self->get_tag("controls_div") $self->has_element_wrapper_class
Truth table100%3/3
A or B
A= $self->get_tag("controls_div")B= $self->has_element_wrapper_class
ABresult
1X1
011
000
54 # end control div
55 2 $output .= "\n</div>";
56 }
57  
58 # the 'after_element'
59 438 $output .= $self->get_tag('after_element');
60 # the error messages
61 438 ▶ unless( $self->get_tag('no_errors') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_tag("no_errors")) 438 0 438
62 438 ▶ my $error_class = $self->get_tag('error_class') || 'error_message';
Condition50%1/2
$self->get_tag('error_class') || 'error_message'
l!l
0438
MC/DC0%0/1
$self->get_tag('error_class') || 'error_message'
$self->get_tag('error_class')
Truth table50%1/2
A
A= $self->get_tag('error_class')
Aresult
11
00
63 $output .= qq{\n<span class="$error_class">$_</span>}
64 438 for map { encode_entities($_) } $result->all_errors;
65 # warnings (incompletely implemented - only on field itself)
66 438 ▶ my $warning_class = $self->get_tag('warning_class') || 'warning_message';
Condition50%1/2
$self->get_tag('warning_class') || 'warning_message'
l!l
0438
MC/DC0%0/1
$self->get_tag('warning_class') || 'warning_message'
$self->get_tag('warning_class')
Truth table50%1/2
A
A= $self->get_tag('warning_class')
Aresult
11
00
67 $output .= qq{\n<span class="warning_message">$_</span>}
68 438 for $result->all_warnings;
69 }
70 438 ▶ if( $self->do_wrapper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_wrapper) 389 49 438
71 389 $output .= "\n</$wrapper_tag>";
72 389 $output .= $self->get_tag('after_wrapper');
73 }
74 438 return "$output";
75 }
76  
77  
78 131 1;
79  
80 __END__
81  
82 =pod
83  
84 =encoding UTF-8
85  
86 =head1 NAME
87  
88 HTML::FormHandler::Widget::Wrapper::Simple - simple field wrapper
89  
90 =head1 VERSION
91  
92 version 0.410000
93  
94 =head1 SYNOPSIS
95  
96 This is the default wrapper role. It will be installed if
97 no other wrapper is specified and widget_wrapper is not set to
98 'none'.
99  
100 Relevant field flags:
101  
102 do_wrapper
103 do_label
104  
105 If 'do_label' is set and not 'do_wrapper', only the label plus
106 the form element will be rendered.
107  
108 Supported 'tags', all set via the 'tags' hashref on the field:
109  
110 wrapper_tag -- the tag to use in the wrapper, default 'div'
111  
112 label_tag -- tag to use for label (default 'label')
113 label_after -- string to append to label, for example ': ' to append a colon
114  
115 before_element -- string that goes right before the element
116 after_element -- string that goes right after the element
117  
118 no_errors -- don't issue error messages on the field
119 error_class -- class for error messages (default 'error_message')
120 warning_class -- class for warning messages (default 'warning_message' )
121  
122 no_wrapped_label -- for checkboxes. Don't provide an inner wrapped label
123 (from Base wrapper)
124  
125 Example:
126  
127 has_field 'foo' => ( tags => { wrapper_tag => 'span', no_errors => 1 } );
128  
129 =head1 AUTHOR
130  
131 FormHandler Contributors - see HTML::FormHandler
132  
133 =head1 COPYRIGHT AND LICENSE
134  
135 This software is copyright (c) 2017 by Gerda Shank.
136  
137 This is free software; you can redistribute it and/or modify it under
138 the same terms as the Perl 5 programming language system itself.
139  
140 =cut
« FormHandler/Widget/Wrapper/Bootstrap.pm ↑ Summary FormHandler/BuildFields.pm »