| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# ABSTRACT: Types related to Mailbox.org API |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use v5.24; |
|
5
|
4
|
|
|
4
|
|
343690
|
|
|
|
4
|
|
|
|
|
32
|
|
|
6
|
|
|
|
|
|
|
use strict; |
|
7
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
69
|
|
|
8
|
4
|
|
|
4
|
|
17
|
|
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
158
|
|
|
9
|
|
|
|
|
|
|
use Type::Library |
|
10
|
|
|
|
|
|
|
-base, |
|
11
|
4
|
|
|
|
|
54
|
-declare => qw( HashRefRestricted Boolean ); |
|
12
|
4
|
|
|
4
|
|
911
|
|
|
|
4
|
|
|
|
|
62602
|
|
|
13
|
|
|
|
|
|
|
use Type::Utils -all; |
|
14
|
4
|
|
|
4
|
|
4819
|
use Types::Standard -types; |
|
|
4
|
|
|
|
|
16942
|
|
|
|
4
|
|
|
|
|
38
|
|
|
15
|
4
|
|
|
4
|
|
9206
|
|
|
|
4
|
|
|
|
|
118193
|
|
|
|
4
|
|
|
|
|
45
|
|
|
16
|
|
|
|
|
|
|
use Carp; |
|
17
|
4
|
|
|
4
|
|
17656
|
use JSON::PP; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
275
|
|
|
18
|
4
|
|
|
4
|
|
1554
|
use Scalar::Util qw(blessed); |
|
|
4
|
|
|
|
|
28736
|
|
|
|
4
|
|
|
|
|
280
|
|
|
19
|
4
|
|
|
4
|
|
30
|
|
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
1588
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $meta = __PACKAGE__->meta; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$meta->add_type( |
|
25
|
|
|
|
|
|
|
name => 'HashRefRestricted', |
|
26
|
|
|
|
|
|
|
parent => HashRef, |
|
27
|
|
|
|
|
|
|
constraint_generator => sub { |
|
28
|
|
|
|
|
|
|
return $meta->get_type('HashRefRestricted') if !@_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @keys = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
croak "Need a list of valid keys" if !@keys; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %valid_keys = map { $_ => 1 } @keys; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return sub { |
|
37
|
|
|
|
|
|
|
return if ref $_ ne 'HASH'; |
|
38
|
|
|
|
|
|
|
return 1 if !$_->%*; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
for my $key ( keys $_->%* ) { |
|
41
|
|
|
|
|
|
|
return if !$valid_keys{$key}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return 1; |
|
45
|
|
|
|
|
|
|
}; |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
coercion_generator => sub { |
|
48
|
|
|
|
|
|
|
my ($parent, $child, $param) = @_; |
|
49
|
|
|
|
|
|
|
return $parent->coercion; |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
#inline_generator => sub {}, |
|
52
|
|
|
|
|
|
|
#deep_explanation => sub {}, |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$meta->add_type( |
|
56
|
|
|
|
|
|
|
name => 'Boolean', |
|
57
|
|
|
|
|
|
|
parent => InstanceOf['JSON::PP::Boolean'], |
|
58
|
|
|
|
|
|
|
constraint_generator => sub { |
|
59
|
|
|
|
|
|
|
return $meta->get_type('Boolean') if !@_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return sub { |
|
62
|
|
|
|
|
|
|
return if ! ( blessed $_ and $_->isa('JSON::PP::Boolean') ); |
|
63
|
|
|
|
|
|
|
return 1; |
|
64
|
|
|
|
|
|
|
}; |
|
65
|
|
|
|
|
|
|
}, |
|
66
|
|
|
|
|
|
|
coercion_generator => sub { |
|
67
|
|
|
|
|
|
|
my ($parent, $child, $param) = @_; |
|
68
|
|
|
|
|
|
|
return $parent->coercion; |
|
69
|
|
|
|
|
|
|
}, |
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
coerce Boolean, |
|
73
|
|
|
|
|
|
|
from Bool, |
|
74
|
|
|
|
|
|
|
via { |
|
75
|
|
|
|
|
|
|
my $new = $_ ? $JSON::PP::true : $JSON::PP::false; |
|
76
|
|
|
|
|
|
|
$new; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=pod |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=encoding UTF-8 |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
API::MailboxOrg::Types - Types related to Mailbox.org API |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 VERSION |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
version 1.0.1 |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
{ |
|
100
|
|
|
|
|
|
|
package # private package - do not index |
|
101
|
|
|
|
|
|
|
TestClass; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Moo; |
|
104
|
|
|
|
|
|
|
use API::MailboxOrg::Types qw(Boolean HashRefRestricted); |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
has true_or_false => ( is => 'ro', isa => Boolean, coerce => 1 ); |
|
107
|
|
|
|
|
|
|
has map => ( is => 'ro', isa => HashRefRestricted[qw(a b)] ); # allow only keys a and b |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $obj = TestClass->new( |
|
113
|
|
|
|
|
|
|
true_or_false => 1, # 0|1|""|undef|JSON::PP::Boolean object |
|
114
|
|
|
|
|
|
|
map => { |
|
115
|
|
|
|
|
|
|
a => 1, |
|
116
|
|
|
|
|
|
|
b => 1, |
|
117
|
|
|
|
|
|
|
# a key 'c' would cause a 'die' |
|
118
|
|
|
|
|
|
|
}, |
|
119
|
|
|
|
|
|
|
); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 TYPES |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 HashRefRestricted[`a] |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This expects a hash reference. You can restrict the allowed keys |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 Boolean |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
A JSON::PP::Boolean object. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 COERCIONS |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
These coercions are defined. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 To Boolean |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * String/Integer to boolean |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The values "" (empty string), I<undef>, 0, and 1 are coerced to C<JSON::PP::Boolean> objects. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Renee Baecker <reneeb@cpan.org> |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Renee Baecker. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This is free software, licensed under: |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |