| 1 | package API::MailboxOrg::Types; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Types related to Mailbox.org API | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | use Type::Library | ||||||||||||||||||||||||||||
| 11 | 4 | ▶ | -base, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | -declare => qw( HashRefRestricted Boolean ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Type::Utils -all; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Types::Standard -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = '1.0.2'; # VERSION | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | my $meta = __PACKAGE__->meta; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | $meta->add_type( | ||||||||||||||||||||||||||||
| 26 | name => 'HashRefRestricted', | ||||||||||||||||||||||||||||
| 27 | parent => HashRef, | ||||||||||||||||||||||||||||
| 28 | 3 | ▶ | constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 29 | 3 | ▶ | return $meta->get_type('HashRefRestricted') if !@_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | my @keys = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | ▶ | croak "Need a list of valid keys" if !@keys; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3 | my %valid_keys = map { $_ => 1 } @keys; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 38 | 5 | ▶ | return if ref $_ ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 5 | ▶ | return 1 if !$_->%*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 4 | for my $key ( keys $_->%* ) { | |||||||||||||||||||||||||||
| 42 | 6 | ▶ | return if !$valid_keys{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | return 1; | |||||||||||||||||||||||||||
| 46 | 3 | }; | |||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | 2 | ▶ | coercion_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | my ($parent, $child, $param) = @_; | |||||||||||||||||||||||||||
| 50 | 2 | return $parent->coercion; | |||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||
| 52 | #inline_generator => sub {}, | ||||||||||||||||||||||||||||
| 53 | #deep_explanation => sub {}, | ||||||||||||||||||||||||||||
| 54 | 4 | ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | $meta->add_type( | ||||||||||||||||||||||||||||
| 57 | name => 'Boolean', | ||||||||||||||||||||||||||||
| 58 | parent => InstanceOf['JSON::PP::Boolean'], | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | constraint_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return $meta->get_type('Boolean') if !@_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return if ! ( blessed $_ and $_->isa('JSON::PP::Boolean') ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($_) and $_->isa("JSON::PP::Boolean")
MC/DC0%0/2
builtin::blessed($_) and $_->isa("JSON::PP::Boolean")
builtin::blessed($_)
$_->isa("JSON::PP::Boolean")
Truth table0%0/3
A and B
A= builtin::blessed($_)B= $_->isa("JSON::PP::Boolean")
| |||||||||||||||||||||||||||||
| 64 | 0 | return 1; | |||||||||||||||||||||||||||
| 65 | 0 | }; | |||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | coercion_generator => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 68 | 0 | my ($parent, $child, $param) = @_; | |||||||||||||||||||||||||||
| 69 | 0 | return $parent->coercion; | |||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | 4 | ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | coerce Boolean, | ||||||||||||||||||||||||||||
| 74 | from Bool, | ||||||||||||||||||||||||||||
| 75 | 4 | ▶ | via { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | my $new = $_ ? $JSON::PP::true : $JSON::PP::false; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 4 | $new; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 4 | ; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||