FormHandler/Widget/Wrapper/Bootstrap.pm

filter: Statementstmt 100% 56 / 56 Branchbran 96.6% 29 / 30 Conditioncond 94.4% 17 / 18 MC/DCmcdc 90.0% 9 / 10 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 95.8% 116 / 121 CC 25 SCAR 27.2
CC
25
Cov
98%
wrap_field
20.0
do_prepend_append
6.0
BEGIN
1.0
CRAP 15.1
« FormHandler/Widget/Field/HorizCheckboxGroup.pm ↑ Summary FormHandler/Widget/Wrapper/Simple.pm »
1 package HTML::FormHandler::Widget::Wrapper::Bootstrap;
2 # ABSTRACT: Twitter Bootstrap 2.0 field wrapper
3 7 $HTML::FormHandler::Widget::Wrapper::Bootstrap::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 7 with 'HTML::FormHandler::Widget::Wrapper::Base';
9  
10  
11  
12 sub wrap_field {
13 55 ▶ my ( $self, $result, $rendered_widget ) = @_;
Subroutine wrap_field: called CC=20 SCAR=30.0
Pod undocumented
14  
15 55 my $output;
16 # is this a control group or a form action?
17 55 ▶ my $form_actions = ( $self->name eq 'form_actions' || $self->type_attr eq 'submit'
Condition83%5/6
$self->name eq 'form_actions' || $self->type_attr eq 'submit' || $self->type_attr eq 'reset'
l!l&&r!l&&!r
3052
$self->name eq "form_actions" or $self->type_attr eq "submit"
l!l&&r!l&&!r
2152
MC/DC66%2/3
$self->name eq 'form_actions' || $self->type_attr eq 'submit' || $self->type_attr eq 'reset'
$self->name eq "form_actions" $self->type_attr eq "submit" $self->type_attr eq 'reset'
Truth table75%3/4
A or B || C
A= $self->name eq "form_actions"B= $self->type_attr eq "submit"C= $self->type_attr eq 'reset'
ABCresult
1XX1
01X1
0011
0000
18 || $self->type_attr eq 'reset' );
19 # create attribute string for wrapper
20 55 my $attr = $self->wrapper_attributes($result);
21 # no 'control-group' class for Hidden fields, 'form-actions' for submit/reset
22 55 ▶ my $div_class = $self->type eq 'Hidden' ? undef : $form_actions ? "form-actions" : "control-group";
Branch: 2 branches
BranchTrueFalseTotal
$self->type eq 'Hidden' ? : 1 54 55
$form_actions ? : 3 51 54
23 55 ▶ unshift @{$attr->{class}}, $div_class if $div_class;
Branch: 1 branch
BranchTrueFalseTotal
if $div_class 54 1 55
24 55 my $attr_str = process_attrs( $attr );
25 # wrapper is always a div
26 55 ▶ if ( $self->do_wrapper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_wrapper) 49 6 55
27 49 $output .= $self->get_tag('before_wrapper');
28 49 $output .= qq{\n<div$attr_str>};
29 }
30 # render the label
31 55 ▶ $output .= "\n" . $self->do_render_label($result, undef, ['control-label'] )
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_label 45 10 55
32 if $self->do_label;
33 55 $output .= $self->get_tag('before_element');
34 # the controls div for ... controls
35 55 ▶ $output .= qq{\n<div class="controls">}
Branch: 1 branch
BranchTrueFalseTotal
unless $form_actions or not $self->do_wrapper 46 9 55
Condition100%3/3
$form_actions or not $self->do_wrapper
l!l&&r!l&&!r
3646
MC/DC100%2/2
$form_actions or not $self->do_wrapper
$form_actions not $self->do_wrapper
Truth table100%3/3
A or not(B)
A= $form_actionsB= not $self->do_wrapper
ABresult
1X1
011
000
36 unless $form_actions || !$self->do_wrapper;
37 # yet another tag
38 55 $output .= $self->get_tag('before_element_inside_div');
39 # handle input-prepend and input-append
40 55 ▶ if( $self->get_tag('input_prepend') || $self->get_tag('input_append') ||
Branch: 2 branches
BranchTrueFalseTotal
if ($self->get_tag('input_prepend') or $self->get_tag('input_append') or $self->get_tag('input_append_button')) { } 5 50 55
elsif (lc $self->widget eq 'checkbox') { } 8 42 50
Condition100%6/6
$self->get_tag("input_prepend") or $self->get_tag("input_append") or $self->get_tag("input_append_button")
l!l&&r!l&&!r
3250
$self->get_tag("input_prepend") or $self->get_tag("input_append")
l!l&&r!l&&!r
2152
MC/DC100%3/3
$self->get_tag("input_prepend") or $self->get_tag("input_append") or $self->get_tag("input_append_button")
$self->get_tag("input_prepend") $self->get_tag("input_append") $self->get_tag("input_append_button")
Truth table100%4/4
A or B or C
A= $self->get_tag("input_prepend")B= $self->get_tag("input_append")C= $self->get_tag("input_append_button")
ABCresult
1XX1
01X1
0011
0000
41 $self->get_tag('input_append_button') ) {
42 5 $rendered_widget = $self->do_prepend_append($rendered_widget);
43 }
44 elsif( lc $self->widget eq 'checkbox' ) {
45 8 $rendered_widget = $self->wrap_checkbox($result, $rendered_widget)
46 }
47  
48 55 $output .= "\n$rendered_widget";
49 # various 'help-inline' bits: errors, warnings
50 55 ▶ unless( $self->get_tag('no_errors') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_tag("no_errors")) 55 0 55
51 $output .= qq{\n<span class="help-inline">$_</span>}
52 55 for $result->all_errors;
53 55 $output .= qq{\n<span class="help-inline">$_</span>} for $result->all_warnings;
54 }
55 # extra after element stuff
56 55 $output .= $self->get_tag('after_element');
57 # close 'control' div
58 55 ▶ $output .= '</div>' unless $form_actions || !$self->do_wrapper;
Branch: 1 branch
BranchTrueFalseTotal
unless $form_actions or not $self->do_wrapper 46 9 55
Condition100%3/3
$form_actions or not $self->do_wrapper
l!l&&r!l&&!r
3646
MC/DC100%2/2
$form_actions or not $self->do_wrapper
$form_actions not $self->do_wrapper
Truth table100%3/3
A or not(B)
A= $form_actionsB= not $self->do_wrapper
ABresult
1X1
011
000
59 # close wrapper
60 55 ▶ if ( $self->do_wrapper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_wrapper) 49 6 55
61 49 $output .= "\n</div>";
62 49 $output .= $self->get_tag('after_wrapper');
63 }
64 55 return "$output";
65 }
66  
67 sub do_prepend_append {
68 5 ▶ my ( $self, $rendered_widget ) = @_;
Subroutine do_prepend_append: called CC=6 SCAR=17.9
Pod undocumented
69  
70 5 my @class;
71 5 ▶ if( my $ip_tag = $self->get_tag('input_prepend' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ip_tag = $self->get_tag("input_prepend")) 2 3 5
72 2 $rendered_widget = qq{<span class="add-on">$ip_tag</span>$rendered_widget};
73 2 push @class, 'input-prepend';
74 }
75 5 ▶ if ( my $ia_tag = $self->get_tag('input_append' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ia_tag = $self->get_tag("input_append")) 2 3 5
76 2 $rendered_widget = qq{$rendered_widget<span class="add-on">$ia_tag</span>};
77 2 push @class, 'input-append';
78 }
79 5 ▶ if ( my $iab_tag = $self->get_tag('input_append_button') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $iab_tag = $self->get_tag("input_append_button")) 2 3 5
80 2 ▶ my @buttons = ref $iab_tag eq 'ARRAY' ? @$iab_tag : ($iab_tag);
Branch: 1 branch
BranchTrueFalseTotal
ref $iab_tag eq 'ARRAY' ? : 1 1 2
81 2 foreach my $btn ( @buttons ) {
82 3 $rendered_widget = qq{$rendered_widget<button type="button" class="btn">$btn</button>};
83 }
84 2 push @class, 'input-append';
85 }
86 5 my $attr = process_attrs( { class => \@class } );
87 5 $rendered_widget =
88 qq{<div$attr>
89 $rendered_widget
90 </div>};
91 5 return $rendered_widget;
92 }
93  
94 7 1;
95  
96 __END__
97  
98 =pod
99  
100 =encoding UTF-8
101  
102 =head1 NAME
103  
104 HTML::FormHandler::Widget::Wrapper::Bootstrap - Twitter Bootstrap 2.0 field wrapper
105  
106 =head1 VERSION
107  
108 version 0.410000
109  
110 =head1 SYNOPSIS
111  
112 Wrapper to implement Bootstrap 2.0 style form element rendering. This wrapper
113 does some very specific Bootstrap things, like wrap the form elements
114 in divs with non-changeable classes. It is not as flexible as the
115 'Simple' wrapper, but means that you don't have to specify those classes
116 in your form code.
117  
118 It wraps form elements with 'control-group' divs, and form 'actions' with
119 'form-actions' divs. It adds special additional wrappers for checkboxes and radio
120 buttons, with wrapped labels.
121  
122 =head1 DESCRIPTION
123  
124 Tags supported:
125  
126 label_no_filter -- don't html filter the label
127 label_after -- useful for putting a colon, or other trailing formatting
128 before_element -- insert tag before input, outside element's control div
129 before_element_inside_div -- insert tag before input element, inside control div
130 input_prepend -- for Bootstrap 'input-prepend' class
131 input_append -- for Bootstrap 'input-append' class
132 input_append_button -- 'input-append' with button instead of span
133 no_errors -- don't append error to field rendering
134 after_element -- insert tag after input element
135  
136 =head1 AUTHOR
137  
138 FormHandler Contributors - see HTML::FormHandler
139  
140 =head1 COPYRIGHT AND LICENSE
141  
142 This software is copyright (c) 2017 by Gerda Shank.
143  
144 This is free software; you can redistribute it and/or modify it under
145 the same terms as the Perl 5 programming language system itself.
146  
147 =cut
« FormHandler/Widget/Field/HorizCheckboxGroup.pm ↑ Summary FormHandler/Widget/Wrapper/Simple.pm »