blib/lib/Catmandu/Validator/JSONSchema.pm

filter: Statementstmt 100% 27 / 27 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 97.2% 35 / 36 CC 2 SCAR 2.5
CC
2
Cov
100%
validate_data
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary
1 package Catmandu::Validator::JSONSchema;
2 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Catmandu::Util qw(:is :check);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use JSON::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = "0.15";
8  
9 1 with qw(Catmandu::Validator);
10  
11 1 has schema => (
12 is => 'ro',
13 required => 1
14 );
15  
16 has _validator => (
17 is => 'ro',
18 lazy => 1,
19 2 ▶ builder => sub {
Subroutine _build__validator: called CC=1 SCAR=0.0
20 2 my $validator = JSON::Validator->new;
21 2 $validator->schema($_[0]->schema);
22 2 $validator;
23 }
24 1 );
25  
26 5 ▶sub validate_data {
Subroutine validate_data: called CC=2 SCAR=6.9
Pod undocumented
27 5 my($self, $hash)=@_;
28  
29 5 my $errors = undef;
30  
31 5 my @result = $self->_validator->validate($hash);
32  
33 5 ▶ if (@result) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result) 3 2 5
34 $errors = [
35 map {
36 3 +{
37 3 property => $_->path(),
38 message => $_->message(),
39 details => $_->details()
40 };
41 } @result
42 ];
43 }
44  
45 5 $errors;
46 }
47  
48 1 1;
49 __END__
↑ Summary