You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
694 B
Perl
37 lines
694 B
Perl
package KasmVNC::EnumValidator;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use v5.10;
|
|
use List::MoreUtils qw(any);
|
|
use Data::Dumper;
|
|
use KasmVNC::Utils;
|
|
|
|
sub new {
|
|
my ($class, $args) = @_;
|
|
my $self = bless {
|
|
allowedValues => $args->{allowedValues}
|
|
}, $class;
|
|
}
|
|
|
|
sub validate {
|
|
my $self = shift;
|
|
my $configKey = shift;
|
|
my @values = @{ listify($configKey->value()) };
|
|
|
|
foreach my $value (@values) {
|
|
unless (any { $_ eq $value } @{ $self->{allowedValues} }) {
|
|
$configKey->addErrorMessage($self->errorMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
sub errorMessage {
|
|
my $self = shift;
|
|
|
|
my $allowedValuesText = join ", ", @{ $self->{allowedValues} };
|
|
"must be one of [$allowedValuesText]"
|
|
}
|
|
|
|
1;
|