| 1 | package HTML::FormHandler::Render::Simple; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: simple rendering role | ||||||||||||||||||||||||||||||||||
| 3 | 8 | $HTML::FormHandler::Render::Simple::VERSION = '0.410001'; | |||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 8 | requires( 'sorted_fields', 'field' ); | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs', 'ucc_widget'); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use HTML::Entities qw( encode_entities ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | sub render { | ||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 15 | 6 | my $output = $self->render_start; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 6 | $output .= $self->render_form_errors; | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 6 | foreach my $field ( $self->sorted_fields ) { | |||||||||||||||||||||||||||||||||
| 20 | 39 | $output .= $self->render_field($field); | |||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 6 | $output .= $self->render_end; | |||||||||||||||||||||||||||||||||
| 24 | 6 | return $output; | |||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | sub render_form_errors { | ||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_form_errors: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | return '' unless $self->has_form_errors; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | 1 | my $output = "\n<div class=\"form_errors\">"; | |||||||||||||||||||||||||||||||||
| 33 | $output .= qq{\n<span class="error_message">$_</span>} | ||||||||||||||||||||||||||||||||||
| 34 | 1 | for map { encode_entities($_) } $self->all_form_errors; | |||||||||||||||||||||||||||||||||
| 35 | 1 | $output .= "\n</div>"; | |||||||||||||||||||||||||||||||||
| 36 | 1 | return $output; | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | sub render_field { | ||||||||||||||||||||||||||||||||||
| 40 | 96 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_field: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 96 | ▶ | if ( ref( \$field ) eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | 2 | $field = $self->field($field); | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | 96 | ▶ | die "must pass field to render_field" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $field and $field->isa("HTML::FormHandler::Field")
MC/DC0%0/2
defined $field and $field->isa("HTML::FormHandler::Field")
defined $field
$field->isa("HTML::FormHandler::Field")
Truth table33%1/3
A and B
A= defined $fieldB= $field->isa("HTML::FormHandler::Field")
| |||||||||||||||||||||||||||||||||||
| 46 | unless ( defined $field && $field->isa('HTML::FormHandler::Field') ); | ||||||||||||||||||||||||||||||||||
| 47 | # widgets should be in camel case, since they are Perl package names | ||||||||||||||||||||||||||||||||||
| 48 | 96 | my $widget = ucc_widget($field->widget); | |||||||||||||||||||||||||||||||||
| 49 | 96 | ▶ | return '' if $widget eq 'no_render'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 50 | 91 | my $rendered_field; | |||||||||||||||||||||||||||||||||
| 51 | 91 | my $form_render = 'render_' . $widget; | |||||||||||||||||||||||||||||||||
| 52 | 91 | ▶ | if ( $self->can($form_render) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 53 | 90 | $rendered_field = $self->$form_render($field); | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | elsif ( $field->can('render') ) { | ||||||||||||||||||||||||||||||||||
| 56 | 1 | $rendered_field = $field->render; | |||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||
| 59 | 0 | die "No widget method found for '$widget' in H::F::Render::Simple"; | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | 91 | return $self->wrap_field( $field, $rendered_field ); | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | sub wrap_field { | ||||||||||||||||||||||||||||||||||
| 65 | 67 | ▶ | my ( $self, $field, $rendered_field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
wrap_field: called CC=10 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 67 | ▶ | return "\n$rendered_field" if $field->uwrapper eq 'none'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 68 | 67 | ▶ | return "\n$rendered_field" if ! $field->do_wrapper; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 67 | my $output = "\n"; | |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 67 | my $wrapper_tag = $field->get_tag('wrapper_tag'); | |||||||||||||||||||||||||||||||||
| 73 | 67 | ▶ | $wrapper_tag ||= $field->has_flag('is_repeatable') ? 'fieldset' : 'div'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$wrapper_tag ||= $field->has_flag("is_repeatable") ? "fieldset" : "div"
MC/DC0%0/2
$wrapper_tag ||= $field->has_flag("is_repeatable") ? "fieldset" : "div"
$wrapper_tag
$field->has_flag("is_repeatable") ? "fieldset" : "div"
Truth table66%2/3
A ||= B
A= $wrapper_tagB= $field->has_flag("is_repeatable") ? "fieldset" : "div"
| |||||||||||||||||||||||||||||||||||
| 74 | 67 | my $attrs = process_attrs($field->wrapper_attributes); | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 67 | $output .= qq{<$wrapper_tag$attrs>}; | |||||||||||||||||||||||||||||||||
| 77 | 67 | ▶ | if( $wrapper_tag eq 'fieldset' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 78 | 2 | $output .= '<legend>' . $field->loc_label . '</legend>'; | |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | ▶ | elsif ( ! $field->get_tag('label_none') && $field->do_label && length( $field->label ) > 0 ) { | |||||||||||||||||||||||||||||||||
|
Condition66%4/6
not $field->get_tag("label_none") and $field->do_label and length $field->label > 0
not $field->get_tag("label_none") and $field->do_label
MC/DC33%1/3
not $field->get_tag("label_none") and $field->do_label and length $field->label > 0
not $field->get_tag("label_none")
$field->do_label
length $field->label > 0
Truth table50%2/4
not(A) and B and C
A= not $field->get_tag("label_none")B= $field->do_labelC= length $field->label > 0
| |||||||||||||||||||||||||||||||||||
| 81 | 57 | $output .= "\n" . $self->render_label($field); | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 67 | $output .= "\n$rendered_field"; | |||||||||||||||||||||||||||||||||
| 85 | $output .= qq{\n<span class="error_message">$_</span>} | ||||||||||||||||||||||||||||||||||
| 86 | 67 | for map { encode_entities($_) } $field->all_errors; | |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 67 | $output .= "\n</$wrapper_tag>"; | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 67 | return "$output"; | |||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | sub render_text { | ||||||||||||||||||||||||||||||||||
| 94 | 43 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_text: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 95 | 43 | my $output = '<input type="' . $field->input_type . '" name="'; | |||||||||||||||||||||||||||||||||
| 96 | 43 | $output .= $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 97 | 43 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 98 | 43 | ▶ | $output .= ' size="' . $field->size . '"' if $field->size; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | 43 | ▶ | $output .= ' maxlength="' . $field->maxlength . '"' if $field->maxlength; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 100 | 43 | $output .= ' value="' . $field->html_filter($field->fif) . '"'; | |||||||||||||||||||||||||||||||||
| 101 | 43 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 102 | 43 | $output .= ' />'; | |||||||||||||||||||||||||||||||||
| 103 | 43 | return $output; | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | sub render_password { | ||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_password: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 108 | 0 | my $output = '<input type="password" name="'; | |||||||||||||||||||||||||||||||||
| 109 | 0 | $output .= $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 110 | 0 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $output .= ' size="' . $field->size . '"' if $field->size; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | $output .= ' maxlength="' . $field->maxlength . '"' if $field->maxlength; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | 0 | $output .= ' value="' . $field->html_filter($field->fif) . '"'; | |||||||||||||||||||||||||||||||||
| 114 | 0 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 115 | 0 | $output .= ' />'; | |||||||||||||||||||||||||||||||||
| 116 | 0 | return $output; | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | sub render_hidden { | ||||||||||||||||||||||||||||||||||
| 120 | 5 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_hidden: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 121 | 5 | my $output = '<input type="hidden" name="'; | |||||||||||||||||||||||||||||||||
| 122 | 5 | $output .= $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 123 | 5 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 124 | 5 | $output .= ' value="' . $field->html_filter($field->fif) . '"'; | |||||||||||||||||||||||||||||||||
| 125 | 5 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 126 | 5 | $output .= ' />'; | |||||||||||||||||||||||||||||||||
| 127 | 5 | return $output; | |||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||
| 130 | sub render_select { | ||||||||||||||||||||||||||||||||||
| 131 | 14 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_select: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 14 | my $multiple = $field->multiple; | |||||||||||||||||||||||||||||||||
| 134 | 14 | my $id = $field->id; | |||||||||||||||||||||||||||||||||
| 135 | 14 | my $output = '<select name="' . $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 136 | 14 | $output .= qq{ id="$id"}; | |||||||||||||||||||||||||||||||||
| 137 | 14 | ▶ | $output .= ' multiple="multiple"' if $multiple == 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | 14 | ▶ | $output .= ' size="' . $field->size . '"' if $field->size; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 14 | my $html_attributes = process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 140 | 14 | $output .= $html_attributes; | |||||||||||||||||||||||||||||||||
| 141 | 14 | $output .= '>'; | |||||||||||||||||||||||||||||||||
| 142 | 14 | my $index = 0; | |||||||||||||||||||||||||||||||||
| 143 | 14 | ▶ | if( defined $field->empty_select ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | 0 | $output .= '<option value="">' . $field->_localize($field->empty_select) . '</option>'; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | 14 | my $fif = $field->fif; | |||||||||||||||||||||||||||||||||
| 147 | 14 | my %fif_lookup; | |||||||||||||||||||||||||||||||||
| 148 | 14 | ▶ | @fif_lookup{@$fif} = () if $multiple; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | 14 | foreach my $option ( @{ $field->{options} } ) { | |||||||||||||||||||||||||||||||||
| 150 | 47 | my $value = $option->{value}; | |||||||||||||||||||||||||||||||||
| 151 | 47 | $output .= '<option value="' | |||||||||||||||||||||||||||||||||
| 152 | . $field->html_filter($value) | ||||||||||||||||||||||||||||||||||
| 153 | . qq{" id="$id.$index"}; | ||||||||||||||||||||||||||||||||||
| 154 | 47 | ▶ | if( defined $option->{disabled} && $option->{disabled} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $option->{"disabled"} and $option->{"disabled"}
MC/DC100%2/2
defined $option->{"disabled"} and $option->{"disabled"}
defined $option->{"disabled"}
$option->{"disabled"}
Truth table100%3/3
A and B
A= defined $option->{"disabled"}B= $option->{"disabled"}
| |||||||||||||||||||||||||||||||||||
| 155 | 4 | $output .= ' disabled="disabled"'; | |||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | 47 | ▶ | if ( defined $fif ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 158 | 47 | ▶ | if ( $multiple && exists $fif_lookup{$value} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$multiple and exists $fif_lookup{$value}
MC/DC100%2/2
$multiple and exists $fif_lookup{$value}
$multiple
exists $fif_lookup{$value}
Truth table100%3/3
A and B
A= $multipleB= exists $fif_lookup{$value}
| |||||||||||||||||||||||||||||||||||
| 159 | 8 | $output .= ' selected="selected"'; | |||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||
| 161 | elsif ( $fif eq $value ) { | ||||||||||||||||||||||||||||||||||
| 162 | 4 | $output .= ' selected="selected"'; | |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||
| 165 | 47 | $output .= $html_attributes; | |||||||||||||||||||||||||||||||||
| 166 | 47 | my $label = $option->{label}; | |||||||||||||||||||||||||||||||||
| 167 | 47 | ▶ | $label = $field->_localize($label) if $field->localize_labels; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | 47 | $output .= '>' . ( $field->html_filter($label) ) . '</option>'; | |||||||||||||||||||||||||||||||||
| 169 | 47 | $index++; | |||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | 14 | $output .= '</select>'; | |||||||||||||||||||||||||||||||||
| 172 | 14 | return $output; | |||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | sub render_checkbox { | ||||||||||||||||||||||||||||||||||
| 176 | 10 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_checkbox: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | 10 | my $output = '<input type="checkbox" name="' . $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 179 | 10 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 180 | 10 | $output .= ' value="' . $field->html_filter($field->checkbox_value) . '"'; | |||||||||||||||||||||||||||||||||
| 181 | 10 | ▶ | $output .= ' checked="checked"' if $field->fif eq $field->checkbox_value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 182 | 10 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 183 | 10 | $output .= ' />'; | |||||||||||||||||||||||||||||||||
| 184 | 10 | return $output; | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | sub render_radio_group { | ||||||||||||||||||||||||||||||||||
| 188 | 5 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_radio_group: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 5 | my $output = " <br />"; | |||||||||||||||||||||||||||||||||
| 191 | 5 | my $index = 0; | |||||||||||||||||||||||||||||||||
| 192 | 5 | foreach my $option ( @{ $field->options } ) { | |||||||||||||||||||||||||||||||||
| 193 | 10 | my $id = $field->id . ".$index"; | |||||||||||||||||||||||||||||||||
| 194 | 10 | $output .= qq{<label for="$id"><input type="radio" value="} . $field->html_filter($option->{value}) . '"'; | |||||||||||||||||||||||||||||||||
| 195 | 10 | $output .= ' name="' . $field->html_name . '" id="' . "$id\""; | |||||||||||||||||||||||||||||||||
| 196 | 10 | ▶ | $output .= ' checked="checked"' if $option->{value} eq $field->fif; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 197 | 10 | $output .= ' />'; | |||||||||||||||||||||||||||||||||
| 198 | 10 | $output .= $field->html_filter($option->{label}) . '</label><br />'; | |||||||||||||||||||||||||||||||||
| 199 | 10 | $index++; | |||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | 5 | return $output; | |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | sub render_textarea { | ||||||||||||||||||||||||||||||||||
| 205 | 5 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_textarea: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 206 | 5 | ▶ | my $fif = $field->fif || ''; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$field->fif || ''
MC/DC100%1/1
$field->fif || ''
$field->fif
Truth table100%2/2
A
A= $field->fif
| |||||||||||||||||||||||||||||||||||
| 207 | 5 | my $id = $field->id; | |||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | my $cols = $field->cols || 10; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$field->cols || 10
MC/DC100%1/1
$field->cols || 10
$field->cols
Truth table100%2/2
A
A= $field->cols
| |||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | my $rows = $field->rows || 5; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$field->rows || 5
MC/DC100%1/1
$field->rows || 5
$field->rows
Truth table100%2/2
A
A= $field->rows
| |||||||||||||||||||||||||||||||||||
| 210 | 5 | my $name = $field->html_name; | |||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | 5 | my $output = | |||||||||||||||||||||||||||||||||
| 213 | qq(<textarea name="$name" id="$id" ) | ||||||||||||||||||||||||||||||||||
| 214 | . process_attrs($field->element_attributes) | ||||||||||||||||||||||||||||||||||
| 215 | . qq(rows="$rows" cols="$cols">) | ||||||||||||||||||||||||||||||||||
| 216 | . $field->html_filter($fif) | ||||||||||||||||||||||||||||||||||
| 217 | . q(</textarea>); | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 5 | return $output; | |||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||
| 222 | sub render_upload { | ||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_upload: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 0 | my $output; | |||||||||||||||||||||||||||||||||
| 226 | 0 | $output = '<input type="file" name="'; | |||||||||||||||||||||||||||||||||
| 227 | 0 | $output .= $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 228 | 0 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 229 | 0 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 230 | 0 | $output .= ' />'; | |||||||||||||||||||||||||||||||||
| 231 | 0 | return $output; | |||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | sub render_label { | ||||||||||||||||||||||||||||||||||
| 235 | 81 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_label: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||
| 237 | 81 | my $attrs = process_attrs( $field->label_attributes ); | |||||||||||||||||||||||||||||||||
| 238 | 81 | my $label = $field->html_filter($field->loc_label); | |||||||||||||||||||||||||||||||||
| 239 | 81 | ▶ | $label .= $field->get_tag('label_after') | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 240 | if( $field->tag_exists('label_after') ); | ||||||||||||||||||||||||||||||||||
| 241 | 81 | ▶ | my $label_tag = $field->tag_exists('label_tag') ? $field->get_tag('label_tag') : 'label'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 242 | 81 | return qq{<$label_tag$attrs for="} . $field->id . qq{">$label</$label_tag>}; | |||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | sub render_compound { | ||||||||||||||||||||||||||||||||||
| 246 | 3 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_compound: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||
| 248 | 3 | my $output = ''; | |||||||||||||||||||||||||||||||||
| 249 | 3 | foreach my $subfield ( $field->sorted_fields ) { | |||||||||||||||||||||||||||||||||
| 250 | 9 | $output .= $self->render_field($subfield); | |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||
| 252 | 3 | return $output; | |||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||
| 255 | sub render_submit { | ||||||||||||||||||||||||||||||||||
| 256 | 5 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_submit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | 5 | my $output = '<input type="submit" name="'; | |||||||||||||||||||||||||||||||||
| 259 | 5 | $output .= $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 260 | 5 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 261 | 5 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 262 | 5 | $output .= ' value="' . $field->html_filter($field->_localize($field->value)) . '" />'; | |||||||||||||||||||||||||||||||||
| 263 | 5 | return $output; | |||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | sub render_reset { | ||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 0 | my $output = '<input type="reset" name="'; | |||||||||||||||||||||||||||||||||
| 270 | 0 | $output .= $field->html_name . '"'; | |||||||||||||||||||||||||||||||||
| 271 | 0 | $output .= ' id="' . $field->id . '"'; | |||||||||||||||||||||||||||||||||
| 272 | 0 | $output .= process_attrs($field->element_attributes); | |||||||||||||||||||||||||||||||||
| 273 | 0 | $output .= ' value="' . $field->html_filter($field->value) . '" />'; | |||||||||||||||||||||||||||||||||
| 274 | 0 | return $output; | |||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||
| 277 | sub render_captcha { | ||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | my ( $self, $field ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
render_captcha: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||
| 280 | 0 | my $output = '<img src="' . $self->captcha_image_url . '"/>'; | |||||||||||||||||||||||||||||||||
| 281 | 0 | $output .= '<input id="' . $field->id . '" name="'; | |||||||||||||||||||||||||||||||||
| 282 | 0 | $output .= $field->html_name . '"/>'; | |||||||||||||||||||||||||||||||||
| 283 | 0 | return $output; | |||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | 8 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 288 | 8 | 1; | |||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||
| 290 | __END__ | ||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | =pod | ||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||
| 298 | HTML::FormHandler::Render::Simple - simple rendering role | ||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||
| 302 | version 0.410001 | ||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||
| 306 | This is a Moose role that is an example of a simple rendering | ||||||||||||||||||||||||||||||||||
| 307 | routine for L<HTML::FormHandler>. It's here as an example of | ||||||||||||||||||||||||||||||||||
| 308 | how to write a custom renderer in one package, if you prefer | ||||||||||||||||||||||||||||||||||
| 309 | that to using the widgets. It won't always be updated with | ||||||||||||||||||||||||||||||||||
| 310 | improvements by default, because it was becoming a lot of work to update | ||||||||||||||||||||||||||||||||||
| 311 | the rendering in multiple places. | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | For a 'MyApp::Form::Renderer' which you've created and modified, | ||||||||||||||||||||||||||||||||||
| 314 | in your Form class: | ||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||
| 316 | package MyApp::Form::Silly; | ||||||||||||||||||||||||||||||||||
| 317 | use Moose; | ||||||||||||||||||||||||||||||||||
| 318 | extends 'HTML::FormHandler::Model::DBIC'; | ||||||||||||||||||||||||||||||||||
| 319 | with 'MyApp::Form::Renderers'; | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | In a template: | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | [% form.render %] | ||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | The widgets are rendered with C<< $field->render >>; rendering | ||||||||||||||||||||||||||||||||||
| 326 | routines from a class like this use C<< $form->render_field('field_name') >> | ||||||||||||||||||||||||||||||||||
| 327 | to render individual fields: | ||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | [% form.render_field( 'title' ) %] | ||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | This role provides HTML output routines for the 'widget' types | ||||||||||||||||||||||||||||||||||
| 334 | defined in the provided FormHandler fields. Each 'widget' name | ||||||||||||||||||||||||||||||||||
| 335 | has a 'widget_$name' method here. | ||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | These widget routines output strings with HTML suitable for displaying | ||||||||||||||||||||||||||||||||||
| 338 | form fields. | ||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||
| 340 | The widget for a particular field can be defined in the form. You can | ||||||||||||||||||||||||||||||||||
| 341 | create additional widget routines in your form for custom widgets. | ||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | The fill-in-form values ('fif') are cleaned with the 'render_filter' | ||||||||||||||||||||||||||||||||||
| 344 | method of the base field class. You can change the filter to suit | ||||||||||||||||||||||||||||||||||
| 345 | your own needs: see L<HTML::FormHandler::Manual::Rendering> | ||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | =head2 render | ||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||
| 349 | To render all the fields in a form in sorted order (using | ||||||||||||||||||||||||||||||||||
| 350 | 'sorted_fields' method). | ||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||
| 352 | =head2 render_start, render_end | ||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||
| 354 | These use the methods in L<HTML::FormHandler::Widget::Form::Simple> now. If | ||||||||||||||||||||||||||||||||||
| 355 | you want to customize them, copy them to your own package. | ||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||
| 357 | Will render the beginning and ending <form> tags and fieldsets. Allows for easy | ||||||||||||||||||||||||||||||||||
| 358 | splitting up of the form if you want to hand-render some of the fields. | ||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||
| 360 | [% form.render_start %] | ||||||||||||||||||||||||||||||||||
| 361 | [% form.render_field('title') %] | ||||||||||||||||||||||||||||||||||
| 362 | <insert specially rendered field> | ||||||||||||||||||||||||||||||||||
| 363 | [% form.render_field('some_field') %] | ||||||||||||||||||||||||||||||||||
| 364 | [% form.render_end %] | ||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||
| 366 | =head2 render_field | ||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||
| 368 | Render a field passing in a field object or a field name | ||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||
| 370 | $form->render_field( $field ) | ||||||||||||||||||||||||||||||||||
| 371 | $form->render_field( 'title' ) | ||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | =head2 render_text | ||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||
| 375 | Output an HTML string for a text widget | ||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||
| 377 | =head2 render_password | ||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | Output an HTML string for a password widget | ||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||
| 381 | =head2 render_hidden | ||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||
| 383 | Output an HTML string for a hidden input widget | ||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||
| 385 | =head2 render_select | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | Output an HTML string for a 'select' widget, single or multiple | ||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||
| 389 | =head2 render_checkbox | ||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||
| 391 | Output an HTML string for a 'checkbox' widget | ||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||
| 393 | =head2 render_radio_group | ||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||
| 395 | Output an HTML string for a 'radio_group' selection widget. | ||||||||||||||||||||||||||||||||||
| 396 | This widget should be for a field that inherits from 'Select', | ||||||||||||||||||||||||||||||||||
| 397 | since it requires the existence of an 'options' array. | ||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||
| 399 | =head2 render_textarea | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | Output an HTML string for a textarea widget | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | =head2 render_compound | ||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||
| 405 | Renders field with 'compound' widget | ||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | =head2 render_submit | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | Renders field with 'submit' widget | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | FormHandler Contributors - see HTML::FormHandler | ||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||
| 417 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||
| 419 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||
| 420 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||
| 422 | =cut | ||||||||||||||||||||||||||||||||||