| 1 | package HTML::FormHandler::Render::Table; | ||||||||||||||
| 2 | # ABSTRACT: render a form with a table layout | ||||||||||||||
| 3 | 4 | $HTML::FormHandler::Render::Table::VERSION = '0.410002'; | |||||||||||||
| 4 | 4 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 4 | with 'HTML::FormHandler::Render::Simple' => | |||||||||||||
| 7 | { -excludes => [ 'render', 'wrap_field', 'render_end', 'render_start' ] }; | ||||||||||||||
| 8 | 4 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs'); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 4 | ▶ | use HTML::Entities qw( encode_entities ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | 3 | ▶ | sub render { | ||||||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 13 | 3 | my $self = shift; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 3 | my $output = $self->render_start; | |||||||||||||
| 16 | 3 | $output .= $self->render_form_errors; | |||||||||||||
| 17 | 3 | foreach my $field ( $self->sorted_fields ) { | |||||||||||||
| 18 | 21 | $output .= $self->render_field($field); | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | 3 | $output .= $self->render_end; | |||||||||||||
| 21 | 3 | return $output; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 3 | ▶ | sub render_start { | ||||||||||||
|
Subroutine
render_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 25 | 3 | my $self = shift; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 3 | my $attrs = process_attrs($self->attributes); | |||||||||||||
| 28 | 3 | return qq{<form$attrs><table>}; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 3 | ▶ | sub render_form_errors { | ||||||||||||
|
Subroutine
render_form_errors: called CC=3 SCAR=17.3
Pod
undocumented
| |||||||||||||||
| 32 | 3 | my $self = shift; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 3 | ▶ | return '' unless $self->has_form_errors; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 0 | my $output = "\n<tr class=\"form_errors\"><td colspan=\"2\">"; | |||||||||||||
| 36 | $output .= qq{\n<span class="error_message">$_</span>} | ||||||||||||||
| 37 | 0 | for map { encode_entities($_) } $self->all_form_errors; | |||||||||||||
| 38 | 0 | $output .= "\n</td></tr>"; | |||||||||||||
| 39 | 0 | return $output; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 3 | ▶ | sub render_end { | ||||||||||||
|
Subroutine
render_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 43 | 3 | my $self = shift; | |||||||||||||
| 44 | 3 | my $output = "</table>\n"; | |||||||||||||
| 45 | 3 | $output .= "</form>\n"; | |||||||||||||
| 46 | 3 | return $output; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 24 | ▶ | sub wrap_field { | ||||||||||||
|
Subroutine
wrap_field: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||
| 50 | 24 | my ( $self, $field, $rendered_field ) = @_; | |||||||||||||
| 51 | |||||||||||||||
| 52 | 24 | my $attrs = process_attrs($field->wrapper_attributes); | |||||||||||||
| 53 | 24 | my $output = qq{\n<tr$attrs>}; | |||||||||||||
| 54 | 24 | ▶ | my $l_type = $field->widget eq 'Compound' ? 'legend' : 'label'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 24 | ▶ | if ( $l_type eq 'label' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | 23 | $output .= '<td>' . $self->render_label($field) . '</td>'; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | elsif ( $l_type eq 'legend' ) { | ||||||||||||||
| 59 | 1 | $output .= '<td>' . $self->render_label($field) . '</td></tr>'; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | 24 | ▶ | if ( $l_type ne 'legend' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 23 | $output .= '<td>'; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | 24 | $output .= $rendered_field; | |||||||||||||
| 65 | $output .= qq{\n<span class="error_message">$_</span>} | ||||||||||||||
| 66 | 0 | for map { encode_entities($_) } $field->all_errors; | |||||||||||||
| 67 | 24 | ▶ | if ( $l_type ne 'legend' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 23 | $output .= "</td></tr>\n"; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | 24 | return $output; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 4 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 74 | 4 | 1; | |||||||||||||
| 75 | |||||||||||||||
| 76 | __END__ | ||||||||||||||