| 1 | package Tags::HTML::Element::Option; | ||
| 2 | |||
| 3 | 3 | ▶ | use base qw(Tags::HTML); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use Error::Pure qw(err); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use Scalar::Util qw(blessed); | ||
| 9 | use Tags::HTML::Element::Utils qw(tags_boolean tags_data tags_value); | ||
| 10 | |||
| 11 | our $VERSION = 0.15; | ||
| 12 | |||
| 13 | sub _cleanup { | ||
| 14 | my $self = shift; | ||
| 15 | |||
| 16 | delete $self->{'_option'}; | ||
| 17 | |||
| 18 | return; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub _init { | ||
| 22 | my ($self, $option) = @_; | ||
| 23 | |||
| 24 | # Check input. | ||
| 25 | if (! defined $option | ||
| 26 | || ! blessed($option) | ||
| 27 | || ! $option->isa('Data::HTML::Element::Option')) { | ||
| 28 | |||
| 29 | err "Option object must be a 'Data::HTML::Element::Option' instance."; | ||
| 30 | } | ||
| 31 | |||
| 32 | $self->{'_option'} = $option; | ||
| 33 | |||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | # Process 'Tags'. | ||
| 38 | sub _process { | ||
| 39 | my $self = shift; | ||
| 40 | |||
| 41 | if (! exists $self->{'_option'}) { | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | |||
| 45 | $self->{'tags'}->put( | ||
| 46 | ['b', 'option'], | ||
| 47 | tags_value($self, $self->{'_option'}, 'css_class', 'class'), | ||
| 48 | tags_value($self, $self->{'_option'}, 'id'), | ||
| 49 | tags_boolean($self, $self->{'_option'}, 'disabled'), | ||
| 50 | tags_boolean($self, $self->{'_option'}, 'selected'), | ||
| 51 | tags_value($self, $self->{'_option'}, 'value'), | ||
| 52 | # TODO Other. https://www.w3schools.com/tags/tag_option.asp | ||
| 53 | ); | ||
| 54 | tags_data($self, $self->{'_option'}); | ||
| 55 | $self->{'tags'}->put( | ||
| 56 | ['e', 'option'], | ||
| 57 | ); | ||
| 58 | |||
| 59 | return; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub _process_css { | ||
| 63 | my $self = shift; | ||
| 64 | |||
| 65 | if (! exists $self->{'_option'}) { | ||
| 66 | return; | ||
| 67 | } | ||
| 68 | |||
| 69 | my $css_class = ''; | ||
| 70 | if (defined $self->{'_option'}->css_class) { | ||
| 71 | $css_class = '.'.$self->{'_option'}->css_class; | ||
| 72 | } | ||
| 73 | |||
| 74 | $self->{'css'}->put( | ||
| 75 | # TODO Implement consistent CSS. | ||
| 76 | ); | ||
| 77 | |||
| 78 | return; | ||
| 79 | } | ||
| 80 | |||
| 81 | 1; | ||
| 82 | |||
| 83 | __END__ | ||