| 1 | package SyForm::ViewField::InputHTML; | ||||||||||
| 2 | 7 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | $SyForm::ViewField::InputHTML::AUTHORITY = 'cpan:GETTY'; | |||||||||
| 4 | } | ||||||||||
| 5 | 7 | $SyForm::ViewField::InputHTML::VERSION = '0.103'; | |||||||||
| 6 | 7 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 7 | ▶ | use List::MoreUtils qw( uniq ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 7 | ▶ | use HTML::Declare ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 7 | with qw( | |||||||||
| 11 | MooX::Traits | ||||||||||
| 12 | SyForm::CommonRole::EventHTML | ||||||||||
| 13 | SyForm::CommonRole::GlobalHTML | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 7 | our @input_attributes = qw( | |||||||||
| 17 | accept | ||||||||||
| 18 | align | ||||||||||
| 19 | alt | ||||||||||
| 20 | autocomplete | ||||||||||
| 21 | autofocus | ||||||||||
| 22 | checked | ||||||||||
| 23 | disabled | ||||||||||
| 24 | form | ||||||||||
| 25 | formaction | ||||||||||
| 26 | formenctype | ||||||||||
| 27 | formmethod | ||||||||||
| 28 | formnovalidate | ||||||||||
| 29 | formtarget | ||||||||||
| 30 | height | ||||||||||
| 31 | list | ||||||||||
| 32 | max | ||||||||||
| 33 | maxlength | ||||||||||
| 34 | min | ||||||||||
| 35 | multiple | ||||||||||
| 36 | name | ||||||||||
| 37 | pattern | ||||||||||
| 38 | placeholder | ||||||||||
| 39 | readonly | ||||||||||
| 40 | required | ||||||||||
| 41 | size | ||||||||||
| 42 | src | ||||||||||
| 43 | step | ||||||||||
| 44 | type | ||||||||||
| 45 | value | ||||||||||
| 46 | width | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | 7 | our @textarea_attributes = qw( | |||||||||
| 50 | autocomplete | ||||||||||
| 51 | autofocus | ||||||||||
| 52 | cols | ||||||||||
| 53 | disabled | ||||||||||
| 54 | form | ||||||||||
| 55 | maxlength | ||||||||||
| 56 | minlength | ||||||||||
| 57 | name | ||||||||||
| 58 | placeholder | ||||||||||
| 59 | readonly | ||||||||||
| 60 | required | ||||||||||
| 61 | rows | ||||||||||
| 62 | selectionDirection | ||||||||||
| 63 | selectionEnd | ||||||||||
| 64 | selectionStart | ||||||||||
| 65 | spellcheck | ||||||||||
| 66 | wrap | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | 7 | our @valid_types = qw( | |||||||||
| 70 | button | ||||||||||
| 71 | checkbox | ||||||||||
| 72 | color | ||||||||||
| 73 | date | ||||||||||
| 74 | datetime | ||||||||||
| 75 | datetime-local | ||||||||||
| 76 | |||||||||||
| 77 | file | ||||||||||
| 78 | hidden | ||||||||||
| 79 | image | ||||||||||
| 80 | month | ||||||||||
| 81 | number | ||||||||||
| 82 | password | ||||||||||
| 83 | radio | ||||||||||
| 84 | range | ||||||||||
| 85 | reset | ||||||||||
| 86 | search | ||||||||||
| 87 | submit | ||||||||||
| 88 | tel | ||||||||||
| 89 | text | ||||||||||
| 90 | time | ||||||||||
| 91 | url | ||||||||||
| 92 | week | ||||||||||
| 93 | ); | ||||||||||
| 94 | |||||||||||
| 95 | 7 | my @own_attributes = uniq( | |||||||||
| 96 | @input_attributes, | ||||||||||
| 97 | @textarea_attributes, | ||||||||||
| 98 | ); | ||||||||||
| 99 | |||||||||||
| 100 | 7 | my @remote_attributes = uniq( | |||||||||
| 101 | @SyForm::CommonRole::EventHTML::attributes, | ||||||||||
| 102 | @SyForm::CommonRole::GlobalHTML::attributes, | ||||||||||
| 103 | ); | ||||||||||
| 104 | |||||||||||
| 105 | 7 | our @attributes; | |||||||||
| 106 | |||||||||||
| 107 | 7 | for my $own_attribute (@own_attributes) { | |||||||||
| 108 | push @attributes, $own_attribute | ||||||||||
| 109 | 266 | ▶ | unless grep { $own_attribute eq $_ } @remote_attributes; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 7 | for my $attribute (@attributes) { | |||||||||
| 113 | 252 | has $attribute => ( | |||||||||
| 114 | is => 'ro', | ||||||||||
| 115 | predicate => 1, | ||||||||||
| 116 | ); | ||||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 7 | has html_declare => ( | |||||||||
| 120 | is => 'lazy', | ||||||||||
| 121 | ); | ||||||||||
| 122 | |||||||||||
| 123 | 19 | ▶ | sub _build_html_declare { | ||||||||
|
Subroutine
_build_html_declare: called CC=11 SCAR=24.0
| |||||||||||
| 124 | 19 | my ( $self ) = @_; | |||||||||
| 125 | 19 | my %html_attributes = %{$self->data_attributes}; | |||||||||
| 126 | 19 | for my $key (@remote_attributes) { | |||||||||
| 127 | 1615 | my $has = 'has_'.$key; | |||||||||
| 128 | 1615 | ▶ | $html_attributes{$key} = $self->$key if $self->$has; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | } | ||||||||||
| 130 | 19 | ▶ | if ($self->type eq 'textarea') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 2 | for my $key (@textarea_attributes) { | |||||||||
| 132 | 34 | my $has = 'has_'.$key; | |||||||||
| 133 | 34 | ▶ | $html_attributes{$key} = $self->$key if $self->$has; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | } | ||||||||||
| 135 | 2 | ▶ | delete $html_attributes{value} if defined $html_attributes{value}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 2 | ▶ | my $value = $self->has_value ? $self->value : ""; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | 2 | return TEXTAREA { %html_attributes, _ => $value }; | |||||||||
| 138 | } else { | ||||||||||
| 139 | SyForm->throw("Unknown type") | ||||||||||
| 140 | 17 | ▶ | unless grep { $self->type eq $_ } @valid_types; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 17 | for my $key (@input_attributes) { | |||||||||
| 142 | 510 | my $has = 'has_'.$key; | |||||||||
| 143 | 510 | ▶ | $html_attributes{$key} = $self->$key if $self->$has; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | } | ||||||||||
| 145 | 17 | return INPUT { %html_attributes }; | |||||||||
| 146 | } | ||||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | 7 | 1; | |||||||||
| 150 | |||||||||||
| 151 | __END__ | ||||||||||