| 1 | package Data::HTML::Element::Button; | ||
| 2 | |||
| 3 | 14 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 14 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 0 | ▶ | use Data::HTML::Element::Utils qw(check_data check_data_type); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use Error::Pure qw(err); | ||
| 8 | use List::Util 1.33 qw(none); | ||
| 9 | use Mo qw(build default is); | ||
| 10 | use Mo::utils 0.06 qw(check_array check_bool check_required); | ||
| 11 | use Mo::utils::CSS 0.02 qw(check_css_class); | ||
| 12 | use Readonly; | ||
| 13 | |||
| 14 | Readonly::Array our @DATA_TYPES => qw(plain tags); | ||
| 15 | Readonly::Array our @ENCTYPES => ( | ||
| 16 | 'application/x-www-form-urlencoded', | ||
| 17 | 'multipart/form-data', | ||
| 18 | 'text/plain', | ||
| 19 | ); | ||
| 20 | Readonly::Array our @FORM_METHODS => qw(get post); | ||
| 21 | Readonly::Array our @TYPES => qw(button reset submit); | ||
| 22 | |||
| 23 | our $VERSION = 0.17; | ||
| 24 | |||
| 25 | has autofocus => ( | ||
| 26 | ro => 1, | ||
| 27 | ); | ||
| 28 | |||
| 29 | has css_class => ( | ||
| 30 | ro => 1, | ||
| 31 | ); | ||
| 32 | |||
| 33 | has data => ( | ||
| 34 | default => [], | ||
| 35 | ro => 1, | ||
| 36 | ); | ||
| 37 | |||
| 38 | has data_type => ( | ||
| 39 | ro => 1, | ||
| 40 | ); | ||
| 41 | |||
| 42 | has disabled => ( | ||
| 43 | ro => 1, | ||
| 44 | ); | ||
| 45 | |||
| 46 | has form => ( | ||
| 47 | ro => 1, | ||
| 48 | ); | ||
| 49 | |||
| 50 | has form_action => ( | ||
| 51 | ro => 1, | ||
| 52 | ); | ||
| 53 | |||
| 54 | has form_enctype => ( | ||
| 55 | ro => 1, | ||
| 56 | ); | ||
| 57 | |||
| 58 | has form_method => ( | ||
| 59 | ro => 1, | ||
| 60 | ); | ||
| 61 | |||
| 62 | has form_no_validate => ( | ||
| 63 | ro => 1, | ||
| 64 | ); | ||
| 65 | |||
| 66 | has id => ( | ||
| 67 | ro => 1, | ||
| 68 | ); | ||
| 69 | |||
| 70 | has name => ( | ||
| 71 | ro => 1, | ||
| 72 | ); | ||
| 73 | |||
| 74 | has pop_over_target => ( | ||
| 75 | ro => 1, | ||
| 76 | ); | ||
| 77 | |||
| 78 | has type => ( | ||
| 79 | ro => 1, | ||
| 80 | ); | ||
| 81 | |||
| 82 | has value => ( | ||
| 83 | ro => 1, | ||
| 84 | ); | ||
| 85 | |||
| 86 | sub BUILD { | ||
| 87 | my $self = shift; | ||
| 88 | |||
| 89 | # Check autofocus. | ||
| 90 | if (! defined $self->{'autofocus'}) { | ||
| 91 | $self->{'autofocus'} = 0; | ||
| 92 | } | ||
| 93 | check_bool($self, 'autofocus'); | ||
| 94 | |||
| 95 | # Check CSS class. | ||
| 96 | check_css_class($self, 'css_class'); | ||
| 97 | |||
| 98 | # Check data type. | ||
| 99 | check_data_type($self); | ||
| 100 | |||
| 101 | # Check data based on type. | ||
| 102 | check_data($self); | ||
| 103 | |||
| 104 | # Check disabled. | ||
| 105 | if (! defined $self->{'disabled'}) { | ||
| 106 | $self->{'disabled'} = 0; | ||
| 107 | } | ||
| 108 | check_bool($self, 'disabled'); | ||
| 109 | |||
| 110 | # Check form_enctype. | ||
| 111 | if (defined $self->{'form_enctype'}) { | ||
| 112 | if (none { $self->{'form_enctype'} eq $_ } @ENCTYPES) { | ||
| 113 | err "Parameter 'form_enctype' has bad value.", | ||
| 114 | 'Value', $self->{'form_enctype'}, | ||
| 115 | ; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | # Check form_method. | ||
| 120 | if (! defined $self->{'form_method'}) { | ||
| 121 | $self->{'form_method'} = 'get'; | ||
| 122 | } | ||
| 123 | if (none { $self->{'form_method'} eq $_ } @FORM_METHODS) { | ||
| 124 | err "Parameter 'form_method' has bad value."; | ||
| 125 | } | ||
| 126 | |||
| 127 | # Check form_action. | ||
| 128 | # TODO | ||
| 129 | |||
| 130 | # Check form_no_validate. | ||
| 131 | if (! defined $self->{'form_no_validate'}) { | ||
| 132 | $self->{'form_no_validate'} = 0; | ||
| 133 | } | ||
| 134 | check_bool($self, 'form_no_validate'); | ||
| 135 | |||
| 136 | # Check type. | ||
| 137 | if (! defined $self->{'type'}) { | ||
| 138 | $self->{'type'} = 'button'; | ||
| 139 | } | ||
| 140 | if (none { $self->{'type'} eq $_ } @TYPES) { | ||
| 141 | err "Parameter 'type' has bad value."; | ||
| 142 | } | ||
| 143 | |||
| 144 | return; | ||
| 145 | } | ||
| 146 | |||
| 147 | 1; | ||
| 148 | |||
| 149 | __END__ | ||