File Coverage

blib/lib/Valiemon/Attributes/Enum.pm
Criterion Covered Total %
statement 25 26 96.1
branch 1 2 50.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 0 2 0.0
total 36 42 85.7


line stmt bran cond sub pod time code
1             package Valiemon::Attributes::Enum;
2 1     1   760 use strict;
  1         2  
  1         42  
3 1     1   7 use warnings;
  1         2  
  1         43  
4 1     1   6 use utf8;
  1         2  
  1         7  
5 1     1   705 use parent qw(Valiemon::Attributes);
  1         384  
  1         6  
6              
7 1     1   78 use Carp qw(croak);
  1         3  
  1         121  
8 1     1   775 use List::MoreUtils qw(any);
  1         14930  
  1         12  
9              
10 17     17 0 59 sub attr_name { 'enum' }
11              
12             sub is_valid {
13 17     17 0 33 my ($class, $context, $schema, $data) = @_;
14              
15 17         40 my $enum = $schema->{enum};
16             $context->in_attr($class, sub {
17 17 50 33 17   116 if (ref $enum ne 'ARRAY' || scalar @$enum < 1) {
18 0         0 croak sprintf '`enum` must be an array and have at leas one element at %s', $context->position
19             }
20              
21 17         163 any { $context->prims->is_equal($data, $_) } @$enum;
  54         186  
22 17         146 });
23             }
24              
25             1;