blib/lib/JSON/Validator/Schema/Troglodyne.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 95.1% 79 / 83 CC 9 SCAR 12.3
CC
9
Cov
96%
_validate_type_callback
7.0
_validate_type_email
3.0
BEGIN
1.0
CRAP 3.4
↑ Summary
1 package JSON::Validator::Schema::Troglodyne;
2 2 $JSON::Validator::Schema::Troglodyne::VERSION = '1.000';
3 # ABSTRACT: Troglodyne extensions to the OpenAPIv3 schema validator.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use re '/aa';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use parent qw{JSON::Validator::Schema::OpenAPIv3};
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Data::Validate::Email();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use List::Util qw{any};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 7 ▶sub _validate_type_email {
Subroutine _validate_type_email: called CC=3 SCAR=11.0
19 7 my ( $self, $input, $info ) = @_;
20 7 my $path = $self->_troglodyne_path($info);
21 7 ▶ return "wrong type, not email" if ref $input;
Branch: 1 branch
BranchTrueFalseTotal
if ref $input 1 6 7
22 6 ▶ return "$path ain't no email I never heard of pardner" unless Data::Validate::Email::is_email($input);
Branch: 1 branch
BranchTrueFalseTotal
unless Data::Validate::Email::is_email($input) 1 5 6
23 5 return;
24 }
25  
26  
27 7 ▶sub _validate_type_callback {
Subroutine _validate_type_callback: called CC=7 SCAR=19.5
28 7 my ( $self, $input, $info ) = @_;
29  
30 7 my $path = $self->_troglodyne_path($info);
31  
32 7 ▶ return "$path is not a fully qualified sub name" unless defined $input && !ref $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input and not ref $input 1 6 7
Condition66%2/3
defined $input and not ref $input
!ll&&!rl&&r
016
MC/DC50%1/2
defined $input and not ref $input
defined $input not ref $input
Truth table66%2/3
A and not(B)
A= defined $inputB= not ref $input
ABresult
0X0
100
111
33 6 my ($modname) = $input =~ m/^([\w:]+)::\w+$/;
34 6 ▶ return "$path is not a fully qualified sub name" unless $modname;
Branch: 1 branch
BranchTrueFalseTotal
unless $modname 1 5 6
35  
36 5 my $modpath = $modname;
37 5 $modpath =~ s{::}{/}g;
38 5 $modpath .= '.pm';
39  
40 5 local $@;
41 # Require so we can check the sub exists, but don't dobule-require
42 5 my @available = keys(%INC);
43 5 ▶ my $loaded = any { m/\Q$modpath\E/ } @available;
Subroutine __ANON__: called CC=1 SCAR=0.0
44 5 ▶ if (!$loaded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loaded) 1 4 5
45 1 ▶ eval { require $modpath; 1 } or return "$path refers to a module ($modname) which cannot be loaded";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $modpath; 1 } } or return "$path refers to a module ($modname) which cannot be loaded" 0 1 1
46 }
47  
48 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 4 ▶ return "$path refers to a sub which does not exist" unless defined &{$input};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$input;} 1 3 4
50 3 return;
51 }
52  
53 # Build the path the module usually does for errors
54 14 ▶sub _troglodyne_path {
Subroutine _troglodyne_path: called CC=1 SCAR=0.0
55 14 my ($self, $input) = @_;
56 14 return "$input->{base_url}/".join('/', @{$input->{path}});
57 }
58  
59 2 1;
60  
61 __END__
↑ Summary