Widget/Constraint/In.pm untested

filter: Statementstmt 0.0% 0 / 18 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 29 CC 4 SCAR 25.1
CC
4
Cov
0%
validate
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 package HTML::Widget::Constraint::In;
2 use base 'HTML::Widget::Constraint';
3  
4 use strict;
5 use warnings;
6  
7 __PACKAGE__->mk_accessors(qw/in/);
8  
9 =head1 NAME
10  
11 HTML::Widget::Constraint::In - Check that a value is one of a current set.
12  
13 =head1 SYNOPSIS
14  
15 $widget->constraint( In => "foo" )->in(qw/possible values/);
16  
17 =head1 DESCRIPTION
18  
19 =head1 METHODS
20  
21  
22 =head2 validate
23  
24 =cut
25  
26 sub validate {
27 my ( $self, $value ) = @_;
28  
29 # Return valid on an empty value
30 return 1 unless defined($value);
31 return 1 if ( $value eq '' );
32  
33 my $in = $self->in;
34  
35 my %in = map { $_ => 1 } ref $in ? @{ $self->in } : $in;
36  
37 return exists $in{$value};
38 }
39  
40 =head2 in
41  
42 Arguments: @values
43  
44 A list of valid values for that element.
45  
46 =cut
47  
48 1;
49