FormHandler/Widget/Wrapper/Bootstrap.pm

filter: Statementstmt 100% 60 / 60 Branchbran 96.6% 29 / 30 Conditioncond 94.4% 17 / 18 MC/DCmcdc 90.0% 9 / 10 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 96.0% 121 / 126 CC 25 SCAR 26.9
CC
25
Cov
98%
wrap_field
20.0
do_prepend_append
6.0
BEGIN
1.0
CRAP 14.7
« FormHandler/BuildFields.pm ↑ Summary FormHandler/Widget/Field/Role/SelectedOption.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.410002';
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 7 ▶use HTML::Entities qw( encode_entities );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 with 'HTML::FormHandler::Widget::Wrapper::Base';
10  
11  
12  
13 55 ▶sub wrap_field {
Subroutine wrap_field: called CC=20 SCAR=30.0
Pod undocumented
14 55 my ( $self, $result, $rendered_widget ) = @_;
15  
16 55 my $output;
17 # is this a control group or a form action?
18 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
19 || $self->type_attr eq 'reset' );
20 # create attribute string for wrapper
21 55 my $attr = $self->wrapper_attributes($result);
22 # no 'control-group' class for Hidden fields, 'form-actions' for submit/reset
23 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
24 55 ▶ unshift @{$attr->{class}}, $div_class if $div_class;
Branch: 1 branch
BranchTrueFalseTotal
if $div_class 54 1 55
25 55 my $attr_str = process_attrs( $attr );
26 # wrapper is always a div
27 55 ▶ if ( $self->do_wrapper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_wrapper) 49 6 55
28 49 $output .= $self->get_tag('before_wrapper');
29 49 $output .= qq{\n<div$attr_str>};
30 }
31 # render the label
32 55 ▶ $output .= "\n" . $self->do_render_label($result, undef, ['control-label'] )
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_label 45 10 55
33 if $self->do_label;
34 55 $output .= $self->get_tag('before_element');
35 # the controls div for ... controls
36 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
37 unless $form_actions || !$self->do_wrapper;
38 # yet another tag
39 55 $output .= $self->get_tag('before_element_inside_div');
40 # handle input-prepend and input-append
41 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
42 $self->get_tag('input_append_button') ) {
43 5 $rendered_widget = $self->do_prepend_append($rendered_widget);
44 }
45 elsif( lc $self->widget eq 'checkbox' ) {
46 8 $rendered_widget = $self->wrap_checkbox($result, $rendered_widget)
47 }
48  
49 55 $output .= "\n$rendered_widget";
50 # various 'help-inline' bits: errors, warnings
51 55 ▶ unless( $self->get_tag('no_errors') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_tag("no_errors")) 55 0 55
52 $output .= qq{\n<span class="help-inline">$_</span>}
53 55 for map { encode_entities($_) } $result->all_errors;
54 55 $output .= qq{\n<span class="help-inline">$_</span>} for $result->all_warnings;
55 }
56 # extra after element stuff
57 55 $output .= $self->get_tag('after_element');
58 # close 'control' div
59 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
60 # close wrapper
61 55 ▶ if ( $self->do_wrapper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_wrapper) 49 6 55
62 49 $output .= "\n</div>";
63 49 $output .= $self->get_tag('after_wrapper');
64 }
65 55 return "$output";
66 }
67  
68 5 ▶sub do_prepend_append {
Subroutine do_prepend_append: called CC=6 SCAR=17.9
Pod undocumented
69 5 my ( $self, $rendered_widget ) = @_;
70  
71 5 my @class;
72 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
73 2 $rendered_widget = qq{<span class="add-on">$ip_tag</span>$rendered_widget};
74 2 push @class, 'input-prepend';
75 }
76 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
77 2 $rendered_widget = qq{$rendered_widget<span class="add-on">$ia_tag</span>};
78 2 push @class, 'input-append';
79 }
80 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
81 2 ▶ my @buttons = ref $iab_tag eq 'ARRAY' ? @$iab_tag : ($iab_tag);
Branch: 1 branch
BranchTrueFalseTotal
ref $iab_tag eq 'ARRAY' ? : 1 1 2
82 2 foreach my $btn ( @buttons ) {
83 3 $rendered_widget = qq{$rendered_widget<button type="button" class="btn">$btn</button>};
84 }
85 2 push @class, 'input-append';
86 }
87 5 my $attr = process_attrs( { class => \@class } );
88 5 $rendered_widget =
89 qq{<div$attr>
90 $rendered_widget
91 </div>};
92 5 return $rendered_widget;
93 }
94  
95 7 1;
96  
97 __END__
« FormHandler/BuildFields.pm ↑ Summary FormHandler/Widget/Field/Role/SelectedOption.pm »