| 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
| |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | return "$path ain't no email I never heard of pardner" unless Data::Validate::Email::is_email($input); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $input and not ref $input
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
| |||||||||||||||||||||||||||||
| 33 | 6 | my ($modname) = $input =~ m/^([\w:]+)::\w+$/; | |||||||||||||||||||||||||||
| 34 | 6 | ▶ | return "$path is not a fully qualified sub name" unless $modname; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | eval { require $modpath; 1 } or return "$path refers to a module ($modname) which cannot be loaded"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||