line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::JSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1105854
|
use strict; |
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
64
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
5
|
2
|
|
|
2
|
|
48
|
use 5.008003; |
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: JSON datatype for Moose |
8
|
|
|
|
|
|
|
our $VERSION = '1.01'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
1182
|
use MooseX::Types -declare => [qw/ JSON relaxedJSON /]; |
|
2
|
|
|
|
|
93805
|
|
|
2
|
|
|
|
|
10
|
|
12
|
2
|
|
|
2
|
|
9909
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
13
|
2
|
|
|
2
|
|
5586
|
use JSON (); ## no critic (Community::PreferredAlternatives) |
|
2
|
|
|
|
|
21715
|
|
|
2
|
|
|
|
|
412
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
subtype JSON, |
16
|
|
|
|
|
|
|
as "Str", |
17
|
|
|
|
|
|
|
where { ref( eval { 'JSON'->new->decode($_) } ) ne '' }, |
18
|
|
|
|
|
|
|
message { "Must be valid JSON" }; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
coerce JSON, |
21
|
|
|
|
|
|
|
from 'Defined', |
22
|
|
|
|
|
|
|
via { 'JSON'->new->allow_nonref->encode($_) }; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
subtype relaxedJSON, |
25
|
|
|
|
|
|
|
as "Str", |
26
|
|
|
|
|
|
|
where { ref( eval { 'JSON'->new->relaxed->decode($_) } ) ne '' }, |
27
|
|
|
|
|
|
|
message { "Must be at least relaxed JSON" }; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
coerce relaxedJSON, |
30
|
|
|
|
|
|
|
from 'Defined', |
31
|
|
|
|
|
|
|
via { 'JSON'->new->allow_nonref->encode($_) }; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding UTF-8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
MooseX::Types::JSON - JSON datatype for Moose |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 VERSION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
version 1.01 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package Foo; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use Moose; |
54
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
55
|
|
|
|
|
|
|
use MooseX::Types::JSON qw( JSON relaxedJSON ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has config => ( is => 'rw', isa => JSON ); |
58
|
|
|
|
|
|
|
has options => ( is => 'rw', isa => relaxedJSON ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
String type constraints that match valid and relaxed JSON. For the meaning of |
61
|
|
|
|
|
|
|
'relaxed' see L<JSON>. All the heavy lifting in the background is also |
62
|
|
|
|
|
|
|
done by L<JSON>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Coercions from Defined types are included. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item * JSON |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
A Str that is valid JSON. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item * relaxedJSON |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
A Str that is 'relaxed' JSON. For the meaning of 'relaxed' see L<JSON>. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Contributors: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Steve Huff |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This software is copyright (c) 2014,2022 by Michael Langner. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
91
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |