AsType/Type.pm

filter: Statementstmt 100% 51 / 51 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 2 totaltotal 95.1% 78 / 82 CC 5 SCAR 6.5
CC
5
Cov
98%
_build_base_type
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« AsType.pm ↑ Summary AsType/Draft3.pm »
1 package JSON::Schema::AsType::Type;
2 45 our $AUTHORITY = 'cpan:YANICK';
3 45 $JSON::Schema::AsType::Type::VERSION = '1.0.0';
4 # ABSTRACT: JSON::Schema::AsType role providing all Type::Tiny methods
5  
6  
7 45 ▶use 5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 45 ▶use feature 'signatures', 'module_true';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 45 ▶use Types::Standard qw/ Any /;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 45 ▶use List::Util qw/ reduce /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 45 ▶use Type::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 45 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 45 ▶use MooseX::MungeHas 'is_ro';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 45 ▶use JSON::Schema::AsType::Annotations;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 45 has type => (
22 is => 'rwp',
23 handles => [qw/ check validate validate_explain /],
24 builder => 1,
25 lazy => 1
26 );
27  
28 45 has base_type => (
29 is => 'ro',
30 builder => 1,
31 lazy => 1,
32 );
33  
34 6 ▶sub validate_schema {
Subroutine validate_schema: called CC=1 SCAR=0.0
Pod undocumented
35 6 my $self = shift;
36 6 $self->metaschema->validate( $self->schema );
37 }
38  
39 2 ▶sub validate_explain_schema {
Subroutine validate_explain_schema: called CC=1 SCAR=0.0
Pod undocumented
40 2 my $self = shift;
41 2 $self->metaschema->validate_explain( $self->schema );
42 }
43  
44 4830 ▶sub _build_base_type {
Subroutine _build_base_type: called CC=5 SCAR=16.1
45 4830 my $self = shift;
46  
47 4830 ▶ return $self->schema ? Any : ~Any
Branch: 2 branches
BranchTrueFalseTotal
if &JSON::is_bool(scalar $self->schema) 231 4599 4830
$self->schema ? : 79 152 231
48 if JSON::is_bool( $self->schema );
49  
50 my @types =
51 5404 ▶ grep { $_ and $_->name ne 'Any' }
Condition66%2/3
$_ && $_->name ne 'Any'
!ll&&!rl&&r
0225382
MC/DC50%1/2
$_ && $_->name ne 'Any'
$_ $_->name ne 'Any'
Truth table66%2/3
A && B
A= $_B= $_->name ne 'Any'
ABresult
0X0
100
111
52 4599 map { $self->_process_keyword($_) } $self->all_active_keywords;
53  
54 return Type::Tiny->new(
55 display_name => $self->uri,
56 4599 ▶ parent => @types ? reduce { $a & $b } @types : Any,
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
@types ? : 4234 365 4599
57 );
58 }
59  
60 my $Scope = Type::Tiny->new(
61 name => 'Scope',
62 3463 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 3463 my $type = shift;
64 107275 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
65 annotation_scope(
66 107275 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 107275 $type->check($_);
68 }
69 107275 );
70 }
71 3463 },
72 7 ▶ deep_explanation => sub( $type, $value, $varname ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 7 my @whines;
74 7 my $inner = $type->parameters->[0];
75 7 push @whines, sprintf "%s was %s, and failed %s: %s",
76 $varname, $value, $inner->name, join "\n",
77 $inner->validate_explain($value)->@*;
78 7 return \@whines;
79 }
80 45 );
81  
82 3472 ▶sub _build_type($self) {
Subroutine _build_type: called CC=1 SCAR=0.0
83 3472 return $Scope->of( $self->base_type );
84 }
85  
86 __END__
« AsType.pm ↑ Summary AsType/Draft3.pm »