package Data::HTML::Element::Button;
use strict;
use warnings;
use Data::HTML::Element::Utils qw(check_data check_data_type);
use Error::Pure qw(err);
use List::Util 1.33 qw(none);
use Mo qw(build default is);
use Mo::utils 0.06 qw(check_array check_bool check_required);
use Mo::utils::CSS 0.02 qw(check_css_class);
use Readonly;
Readonly::Array our @DATA_TYPES => qw(plain tags);
Readonly::Array our @ENCTYPES => (
'application/x-www-form-urlencoded',
'multipart/form-data',
'text/plain',
);
Readonly::Array our @FORM_METHODS => qw(get post);
Readonly::Array our @TYPES => qw(button reset submit);
our $VERSION = 0.17;
has autofocus => (
ro => 1,
);
has css_class => (
ro => 1,
);
has data => (
default => [],
ro => 1,
);
has data_type => (
ro => 1,
);
has disabled => (
ro => 1,
);
has form => (
ro => 1,
);
has form_action => (
ro => 1,
);
has form_enctype => (
ro => 1,
);
has form_method => (
ro => 1,
);
has form_no_validate => (
ro => 1,
);
has id => (
ro => 1,
);
has name => (
ro => 1,
);
has pop_over_target => (
ro => 1,
);
has type => (
ro => 1,
);
has value => (
ro => 1,
);
sub BUILD {
my $self = shift;
# Check autofocus.
if (! defined $self->{'autofocus'}) {
$self->{'autofocus'} = 0;
}
check_bool($self, 'autofocus');
# Check CSS class.
check_css_class($self, 'css_class');
# Check data type.
check_data_type($self);
# Check data based on type.
check_data($self);
# Check disabled.
if (! defined $self->{'disabled'}) {
$self->{'disabled'} = 0;
}
check_bool($self, 'disabled');
# Check form_enctype.
if (defined $self->{'form_enctype'}) {
if (none { $self->{'form_enctype'} eq $_ } @ENCTYPES) {
err "Parameter 'form_enctype' has bad value.",
'Value', $self->{'form_enctype'},
;
}
}
# Check form_method.
if (! defined $self->{'form_method'}) {
$self->{'form_method'} = 'get';
}
if (none { $self->{'form_method'} eq $_ } @FORM_METHODS) {
err "Parameter 'form_method' has bad value.";
}
# Check form_action.
# TODO
# Check form_no_validate.
if (! defined $self->{'form_no_validate'}) {
$self->{'form_no_validate'} = 0;
}
check_bool($self, 'form_no_validate');
# Check type.
if (! defined $self->{'type'}) {
$self->{'type'} = 'button';
}
if (none { $self->{'type'} eq $_ } @TYPES) {
err "Parameter 'type' has bad value.";
}
return;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
Data::HTML::Element::Button - Data object for HTML button element.
=head1 SYNOPSIS
use Data::HTML::Element::Button;
my $obj = Data::HTML::Element::Button->new(%params);
my $autofocus = $obj->autofocus;
my $css_class = $obj->css_class;
my $data = $obj->data;
my $data_type = $obj->data_type;
my $disabled = $obj->disabled;
my $form = $obj->form;
my $form_action = $obj->form_action;
my $form_enctype = $obj->form_enctype;
my $form_method = $obj->form_method;
my $form_no_validate = $obj->form_no_validate;
my $id = $obj->id;
my $name = $obj->name;
my $pop_over_target = $obj->pop_over_target;
my $type = $obj->type;
my $value = $obj->value;
=head1 METHODS
=head2 C
my $obj = Data::HTML::Element::Button->new(%params);
Constructor.
=over 8
=item * C
Button autofocus flag.
Default value is 0.
=item * C
Button CSS class.
Default value is undef.
=item * C
Button data content. It's reference to array.
Data type of data is described in 'data_type' parameter.
Default value is [].
=item * C
Button data type for content.
Possible value are: cb plain tags
The 'cb' content is code reference.
The 'plain' content are string(s).
The 'tags' content is structure described in L.
Default value is 'plain'.
=item * C
Button autofocus flag.
Default value is 0.
=item * C