| 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'
$self->name eq "form_actions" or $self->type_attr eq "submit"
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'
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 55 | ▶ | unshift @{$attr->{class}}, $div_class if $div_class; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 55 | my $attr_str = process_attrs( $attr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | # wrapper is always a div | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 55 | ▶ | if ( $self->do_wrapper ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$form_actions or not $self->do_wrapper
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$self->get_tag("input_prepend") or $self->get_tag("input_append") or $self->get_tag("input_append_button")
$self->get_tag("input_prepend") or $self->get_tag("input_append")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$form_actions or not $self->do_wrapper
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # close wrapper | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 55 | ▶ | if ( $self->do_wrapper ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | my @buttons = ref $iab_tag eq 'ARRAY' ? @$iab_tag : ($iab_tag); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||