Service/CheckParameters.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary Service/Profiles/Search.pm »
1 package XAS::Service::CheckParameters;
2  
3 our $VERSION = '0.01';
4  
5 use XAS::Class
6 0 ▶ debug => 0,
Subroutine BEGIN: called CC=1 SCAR=2.6
7 version => $VERSION,
8 base => 'XAS::Base',
9 utils => ':validation dotid',
10 codec => 'JSON',
11 constants => 'HASHREF',
12 mixins => 'check_parameters',
13 0 ;
14  
15 #use Data::Dumper;
16  
17 # ----------------------------------------------------------------------
18 # Public Methods
19 # ----------------------------------------------------------------------
20  
21 sub check_parameters {
22 my $self = shift;
23 my ($params, $type) = validate_params(\@_, [
24 { type => HASHREF },
25 1,
26 ]);
27  
28 my @errors;
29 my $results = $self->profile->check($params, $type);
30 my $valids = $results->valid();
31  
32 if ($results->has_missing) {
33  
34 for my $f ($results->missing) {
35  
36 my $error = {
37 id => $f,
38 msg => $results->msgs->{'missing'} || 'is missing',
39 };
40  
41 push(@errors, $error);
42  
43 }
44  
45 }
46  
47 if ($results->has_invalid) {
48  
49 for my $f ($results->invalid) {
50  
51 my $error = {
52 id => $f,
53 msg => $results->msgs->{$f} || 'is invalid',
54 };
55  
56 push(@errors, $error);
57  
58 }
59  
60 }
61  
62 if (scalar(@errors) > 0) {
63  
64 $self->throw_msg(
65 dotid($self->class) . '.check_parameters.' . $type,
66 'errors',
67 encode(@errors)
68 );
69  
70 }
71  
72 return $valids;
73  
74 }
75  
76 1;
77  
78 __END__
↑ Summary Service/Profiles/Search.pm »