File Coverage

blib/lib/SyForm/ViewFieldRole/HTML.pm
Criterion Covered Total %
statement 23 24 95.8
branch 10 14 71.4
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 43 49 87.7


line stmt bran cond sub pod time code
1             package SyForm::ViewFieldRole::HTML;
2             BEGIN {
3 3     3   1676 $SyForm::ViewFieldRole::HTML::AUTHORITY = 'cpan:GETTY';
4             }
5             # ABSTRACT:
6             $SyForm::ViewFieldRole::HTML::VERSION = '0.103';
7 3     3   21 use Moo::Role;
  3         5  
  3         18  
8 3     3   1113 use SyForm::ViewField::InputHTML;
  3         6  
  3         73  
9 3     3   1277 use SyForm::ViewField::LabelHTML;
  3         8  
  3         1188  
10              
11             has html_name => (
12             is => 'lazy',
13             );
14              
15             sub _build_html_name {
16 13     13   95 my ( $self ) = @_;
17 13         267 return $self->field->name;
18             }
19              
20             has html_id => (
21             is => 'lazy',
22             );
23              
24             sub _build_html_id {
25 13     13   96 my ( $self ) = @_;
26 13         195 return $self->html_name;
27             }
28              
29 13     13 0 33 sub has_syform_formhtml_children { 1 }
30              
31             has syform_formhtml_children => (
32             is => 'lazy',
33             );
34              
35             sub _build_syform_formhtml_children {
36 13     13   101 my ( $self ) = @_;
37             return [
38 13 50       194 $self->syform_viewfield_inputhtml,
39             $self->has_label ? ( $self->syform_viewfield_labelhtml ) : (),
40             ];
41             }
42              
43             has syform_viewfield_inputhtml => (
44             is => 'lazy',
45             );
46              
47             sub _build_syform_viewfield_inputhtml {
48 13     13   93 my ( $self ) = @_;
49             return SyForm::ViewField::InputHTML->new(
50             type => 'text',
51             name => $self->html_name,
52             id => $self->html_id,
53             $self->has_label ? ( title => $self->label ) : (),
54             $self->has_val ? ( value => $self->val ) : (),
55 13 50       203 $self->field->has_input ? ( %{$self->field->input} ) : (),
  3 100       83  
    100          
56             );
57             }
58              
59             has syform_viewfield_labelhtml => (
60             is => 'lazy',
61             );
62              
63             sub _build_syform_viewfield_labelhtml {
64 13     13   24913 my ( $self ) = @_;
65 13 50       37 SyForm->throw('Require label for labelhtml') unless $self->has_label;
66             return SyForm::ViewField::LabelHTML->new(
67             for => $self->html_id,
68             label => $self->label,
69             $self->is_invalid ? ( errors => $self->errors ) : (),
70 13 100       202 $self->field->has_html_label ? ( %{$self->field->html_label} ) : (),
  0 50          
71             );
72             }
73              
74             1;
75              
76             __END__
77              
78             =pod
79              
80             =head1 NAME
81              
82             SyForm::ViewFieldRole::HTML -
83              
84             =head1 VERSION
85              
86             version 0.103
87              
88             =head1 AUTHOR
89              
90             Torsten Raudssus <torsten@raudss.us>
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             This software is copyright (c) 2014 by Torsten Raudssus.
95              
96             This is free software; you can redistribute it and/or modify it under
97             the same terms as the Perl 5 programming language system itself.
98              
99             =cut