File Coverage

blib/lib/WebService/MinFraud/Data/Rx/Type/Enum.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 35 38 92.1


line stmt bran cond sub pod time code
1             package WebService::MinFraud::Data::Rx::Type::Enum;
2              
3 2     2   40 use 5.010;
  2         8  
4              
5 2     2   11 use strict;
  2         4  
  2         38  
6 2     2   19 use warnings;
  2         13  
  2         54  
7 2     2   13 use namespace::autoclean;
  2         4  
  2         19  
8              
9             our $VERSION = '1.010000';
10              
11 2     2   225 use parent 'Data::Rx::CommonType::EasyNew';
  2         4  
  2         9  
12              
13             sub assert_valid {
14 14     14 0 3374 my ( $self, $value ) = @_;
15              
16 14         70 $self->{schema}->assert_valid($value);
17             }
18              
19             sub guts_from_arg {
20 141     141 0 104124 my ( undef, $arg, $rx ) = @_;
21              
22 141         988 my $meta = $rx->make_schema(
23             {
24             type => '//rec',
25             required => {
26             contents => {
27             type => '//rec',
28             required => {
29             type => '//str', # e.g. //int or //str. Really we only
30             # want schemas that have a 'value' option
31             values => {
32             type => '//arr',
33             contents => '//def',
34              
35             # should be of type, as above, but we can't test this,
36             # so we accept any defined value for now, and then test
37             # the values below
38             },
39             },
40             },
41             },
42             }
43             );
44              
45 141         35175 $meta->assert_valid($arg);
46              
47 141         76074 my $type = $arg->{contents}{type};
48 141         283 my @values = @{ $arg->{contents}{values} };
  141         651  
49              
50             # subsequent test that the provided values are acceptable
51 141         575 $rx->make_schema( { type => '//arr', contents => $type } )
52             ->assert_valid( \@values );
53              
54             my $schema = $rx->make_schema(
55             {
56             type => '//any',
57 141         90360 of => [ map { { type => $type, value => $_ } } @values, ]
  5310         8957  
58             }
59             );
60              
61 141         264110 return { schema => $schema, };
62             }
63              
64             sub type_uri {
65             ## no critic(ValuesAndExpressions::ProhibitCommaSeparatedStatements)
66 57     57 0 17900 'tag:maxmind.com,MAXMIND:rx/enum';
67             }
68              
69             1;
70              
71             # ABSTRACT: A type that defines an enumeration
72              
73             __END__
74              
75             =pod
76              
77             =encoding UTF-8
78              
79             =head1 NAME
80              
81             WebService::MinFraud::Data::Rx::Type::Enum - A type that defines an enumeration
82              
83             =head1 VERSION
84              
85             version 1.010000
86              
87             =head1 SUPPORT
88              
89             Bugs may be submitted through L<https://github.com/maxmind/minfraud-api-perl/issues>.
90              
91             =head1 AUTHOR
92              
93             Mateu Hunter <mhunter@maxmind.com>
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             This software is copyright (c) 2015 - 2020 by MaxMind, Inc.
98              
99             This is free software; you can redistribute it and/or modify it under
100             the same terms as the Perl 5 programming language system itself.
101              
102             =cut