JSONSchema/PrimativeTypes.pm

filter: Statementstmt 85.7% 48 / 56 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.9% 13 / 21 Podpod n/a totaltotal 70.1% 61 / 87 CC 5 SCAR 13.5
CC
5
Cov
75%
__ANON__
12.0
__ANON__
12.0
__ANON__
2.0
CRAP 3.8
↑ Summary JSONSchema.pm »
1 2 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use experimental 'builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Types::JSONSchema::PrimativeTypes;
7  
8 2 our $AUTHORITY = 'cpan:TOBYINK';
9 2 our $VERSION = '0.001000';
10  
11 use Type::Library
12 2 ▶ -base,
Subroutine BEGIN: called CC=1 SCAR=0.0
13 -declare => qw/
14 JNull
15 JBoolean
16 JObject
17 JArray
18 JNumber
19 JString
20
21 JTrue
22 JFalse
23 JInteger
24 JAny
25
26 JSPrimativeName
27 JSPrimativeType
28 2 /;
29 2 ▶use Types::Common -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use Type::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 2 declare JNull,
33 as Undef;
34  
35 declare JBoolean,
36 as InstanceOf[ 'boolean', 'JSON::PP::Boolean', 'JSON::XS::Boolean' ]
37 | ScalarRef[ Enum[ 0, 1 ] ]
38 | Value->create_child_type(
39 name => 'PerlNativeBoolean',
40 0 ▶ constraint => sub { builtin::is_bool($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 76 ▶ inlined => sub { my $var = pop; qq{do{ use experimental 'builtin'; builtin::is_bool($var) }} },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 2 );
43  
44 declare JTrue,
45 as JBoolean,
46 0 ▶ where { ( 'SCALAR' eq ( ref $_ or '' ) ) ? $$_ : $_ },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
'SCALAR' eq (ref $_ || '') ? : 0 0 0
Condition0%0/2
ref $_ || ''
l!l
00
MC/DC0%0/1
ref $_ || ''
ref $_
Truth table0%0/2
A
A= ref $_
Aresult
11
00
47 4 ▶ inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 4 my $var = $_;
49 4 my $parent = $_[0]->parent->inline_check( $var );
50 4 qq{$parent and ( 'SCALAR' eq ( ref $var or '' ) ) ? \${$var} : $var}
51 2 };
52  
53 declare JFalse,
54 as JBoolean,
55 0 ▶ where { ( 'SCALAR' eq ( ref $_ or '' ) ) ? !$$_ : !$_ },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
'SCALAR' eq (ref $_ || '') ? : 0 0 0
Condition0%0/2
ref $_ || ''
l!l
00
MC/DC0%0/1
ref $_ || ''
ref $_
Truth table0%0/2
A
A= ref $_
Aresult
11
00
56 4 ▶ inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 4 my $var = $_;
58 4 my $parent = $_[0]->parent->inline_check( $var );
59 4 qq{$parent and ( 'SCALAR' eq ( ref $var or '' ) ) ? !\${$var} : !$var}
60 2 };
61  
62 2 declare JObject,
63 as HashRef;
64  
65 2 declare JArray,
66 as ArrayRef;
67  
68 declare JNumber,
69 as Num,
70 0 ▶ where { builtin::created_as_number( $_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 26 ▶ inline_as { ( Value->inline_check($_), qq{do{ use experimental 'builtin'; builtin::created_as_number( $_ ) }} ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
72  
73 declare JInteger,
74 as JNumber,
75 0 ▶ where { int($_) == $_ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 4 ▶ inline_as { ( undef, qq{int($_) == $_} ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
77  
78 declare JString,
79 as Str,
80 0 ▶ where { builtin::created_as_string( $_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 22 ▶ inline_as { ( Value->inline_check($_), qq{do{ use experimental 'builtin'; builtin::created_as_string( $_ ) }} ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
82  
83 2 declare JAny,
84 as JNull | JBoolean | JObject | JArray | JNumber | JString;
85  
86 2 my %primative_name_to_type = (
87 null => JNull,
88 boolean => JBoolean,
89 object => JObject,
90 array => JArray,
91 number => JNumber,
92 string => JString,
93 );
94  
95 2 declare JSPrimativeName,
96 as Enum[ sort keys %primative_name_to_type ];
97  
98 2 declare JSPrimativeType,
99 as InstanceOf->of('Type::Tiny')->with_attribute_values(
100 library => Enum[ 'Types::JSONSchema::PrimativeTypes' ],
101 name => Enum[ sort map $_->name, values %primative_name_to_type ],
102 );
103  
104 coerce JSPrimativeType,
105 0 ▶ from JSPrimativeName, via { $primative_name_to_type{$_} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 ▶ from Enum['integer'], via { JInteger };
Subroutine __ANON__: not called CC=1 SCAR=1.2
107  
108 2 1;
109  
110 __END__
↑ Summary JSONSchema.pm »