| HTML-Widget documentation | Contained in the HTML-Widget distribution. |
HTML::Widget::Constraint::In - Check that a value is one of a current set.
$widget->constraint( In => "foo" )->in(qw/possible values/);
Arguments: @values
A list of valid values for that element.
| HTML-Widget documentation | Contained in the HTML-Widget distribution. |
package HTML::Widget::Constraint::In; use base 'HTML::Widget::Constraint'; use strict; use warnings; __PACKAGE__->mk_accessors(qw/in/);
sub validate { my ( $self, $value ) = @_; # Return valid on an empty value return 1 unless defined($value); return 1 if ( $value eq '' ); my $in = $self->in; my %in = map { $_ => 1 } ref $in ? @{ $self->in } : $in; return exists $in{$value}; }
1;