| 1 | package Tags::HTML::Element::Form; | ||
| 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 Class::Utils qw(set_params split_params); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use Error::Pure qw(err); | ||
| 9 | use Scalar::Util qw(blessed); | ||
| 10 | use Tags::HTML::Element::Utils qw(tags_data tags_value); | ||
| 11 | |||
| 12 | our $VERSION = 0.15; | ||
| 13 | |||
| 14 | # Constructor. | ||
| 15 | sub new { | ||
| 16 | my ($class, @params) = @_; | ||
| 17 | |||
| 18 | # Create object. | ||
| 19 | my ($object_params_ar, $other_params_ar) = split_params( | ||
| 20 | ['background_color'], @params); | ||
| 21 | my $self = $class->SUPER::new(@{$other_params_ar}); | ||
| 22 | |||
| 23 | # Background color. | ||
| 24 | $self->{'background_color'} = '#f2f2f2'; | ||
| 25 | |||
| 26 | # Process params. | ||
| 27 | set_params($self, @{$object_params_ar}); | ||
| 28 | |||
| 29 | # Object. | ||
| 30 | return $self; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _cleanup { | ||
| 34 | my $self = shift; | ||
| 35 | |||
| 36 | delete $self->{'_form'}; | ||
| 37 | |||
| 38 | return; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub _init { | ||
| 42 | my ($self, $form) = @_; | ||
| 43 | |||
| 44 | # Check form. | ||
| 45 | if (! defined $form | ||
| 46 | || ! blessed($form) | ||
| 47 | || ! $form->isa('Data::HTML::Element::Form')) { | ||
| 48 | |||
| 49 | err "Form object must be a 'Data::HTML::Element::Form' instance."; | ||
| 50 | } | ||
| 51 | |||
| 52 | $self->{'_form'} = $form; | ||
| 53 | |||
| 54 | return; | ||
| 55 | } | ||
| 56 | |||
| 57 | # Process 'Tags'. | ||
| 58 | sub _process { | ||
| 59 | my $self = shift; | ||
| 60 | |||
| 61 | if (! exists $self->{'_form'}) { | ||
| 62 | return; | ||
| 63 | } | ||
| 64 | |||
| 65 | $self->{'tags'}->put( | ||
| 66 | ['b', 'form'], | ||
| 67 | tags_value($self, $self->{'_form'}, 'css_class', 'class'), | ||
| 68 | tags_value($self, $self->{'_form'}, 'action'), | ||
| 69 | tags_value($self, $self->{'_form'}, 'method'), | ||
| 70 | defined $self->{'_form'}->{'label'} ? ( | ||
| 71 | ['b', 'fieldset'], | ||
| 72 | ['b', 'legend'], | ||
| 73 | ['d', $self->{'_form'}->{'label'}], | ||
| 74 | ['e', 'legend'], | ||
| 75 | ) : (), | ||
| 76 | ); | ||
| 77 | tags_data($self, $self->{'_form'}); | ||
| 78 | $self->{'tags'}->put( | ||
| 79 | defined $self->{'_form'}->{'label'} ? ( | ||
| 80 | ['e', 'fieldset'], | ||
| 81 | ) : (), | ||
| 82 | ['e', 'form'], | ||
| 83 | ); | ||
| 84 | |||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub _process_css { | ||
| 89 | my $self = shift; | ||
| 90 | |||
| 91 | if (! exists $self->{'_form'}) { | ||
| 92 | return; | ||
| 93 | } | ||
| 94 | |||
| 95 | my $css_class = ''; | ||
| 96 | if (defined $self->{'_form'}->css_class) { | ||
| 97 | $css_class = '.'.$self->{'_form'}->css_class; | ||
| 98 | } | ||
| 99 | my $css_legend = $css_class; | ||
| 100 | if ($css_legend) { | ||
| 101 | $css_legend .= ' '; | ||
| 102 | } | ||
| 103 | $css_legend .= 'legend'; | ||
| 104 | my $css_fieldset = $css_class; | ||
| 105 | if ($css_fieldset) { | ||
| 106 | $css_fieldset .= ' '; | ||
| 107 | } | ||
| 108 | $css_fieldset .= 'fieldset'; | ||
| 109 | |||
| 110 | $self->{'css'}->put( | ||
| 111 | ['s', $css_class], | ||
| 112 | ['d', 'border-radius', '5px'], | ||
| 113 | ['d', 'background-color', $self->{'background_color'}], | ||
| 114 | ['d', 'padding', '20px'], | ||
| 115 | ['e'], | ||
| 116 | |||
| 117 | ['s', $css_fieldset], | ||
| 118 | ['d', 'padding', '20px'], | ||
| 119 | ['d', 'border-radius', '15px'], | ||
| 120 | ['e'], | ||
| 121 | |||
| 122 | ['s', $css_legend], | ||
| 123 | ['d', 'padding-left', '10px'], | ||
| 124 | ['d', 'padding-right', '10px'], | ||
| 125 | ['e'], | ||
| 126 | ); | ||
| 127 | |||
| 128 | return; | ||
| 129 | } | ||
| 130 | |||
| 131 | 1; | ||
| 132 | |||
| 133 | __END__ | ||