line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
14182
|
use utf8; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
24
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package JSON::API::v1::Resource; |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
5
|
3
|
|
|
3
|
|
777
|
use Moose; |
|
3
|
|
|
|
|
472028
|
|
|
3
|
|
|
|
|
23
|
|
6
|
3
|
|
|
3
|
|
20770
|
use namespace::autoclean; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
29
|
|
7
|
3
|
|
|
3
|
|
270
|
use Carp qw(croak); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
967
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: A JSON API Resource object |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has id => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => 'Str', |
14
|
|
|
|
|
|
|
predicate => 'has_id', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has type => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => 'Str', |
20
|
|
|
|
|
|
|
predicate => 'has_type', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has attributes => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
isa => 'HashRef', |
26
|
|
|
|
|
|
|
predicate => 'has_attributes', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has relationships => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => 'Defined', |
32
|
|
|
|
|
|
|
predicate => 'has_relationships', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub TO_JSON { |
37
|
15
|
|
|
15
|
0
|
78
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
15
|
100
|
100
|
|
|
451
|
if ($self->has_id && $self->has_type) { |
|
|
100
|
100
|
|
|
|
|
40
|
|
|
|
|
|
|
return { |
41
|
11
|
100
|
|
|
|
303
|
id => $self->id, |
|
|
100
|
|
|
|
|
|
42
|
|
|
|
|
|
|
type => $self->type, |
43
|
|
|
|
|
|
|
$self->has_attributes ? (attributes => $self->attributes) : (), |
44
|
|
|
|
|
|
|
$self->has_meta_object ? (meta => $self->meta_object) : (), |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($self->has_id || $self->has_type) { |
48
|
2
|
100
|
|
|
|
56
|
croak( |
49
|
|
|
|
|
|
|
sprintf("Unable to represent a valid data object, %s is missing", |
50
|
|
|
|
|
|
|
$self->has_id ? 'type' : 'id') |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
2
|
|
|
|
|
35
|
return undef; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
with qw( |
59
|
|
|
|
|
|
|
JSON::API::v1::Roles::TO_JSON |
60
|
|
|
|
|
|
|
JSON::API::v1::Roles::MetaObject |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=encoding UTF-8 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
JSON::API::v1::Resource - A JSON API Resource object |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 0.001 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SYNOPSIS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use JSON::API::v1::Resource; |
82
|
|
|
|
|
|
|
my $object = JSON::API::v1::Resource->new( |
83
|
|
|
|
|
|
|
# If omitted, this becomes a "NULL" object |
84
|
|
|
|
|
|
|
id => 1, |
85
|
|
|
|
|
|
|
type => 'example', |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# optional |
88
|
|
|
|
|
|
|
attributes => { |
89
|
|
|
|
|
|
|
'title' => 'Some example you are', |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$object->TO_JSON_API_V1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DESCRIPTION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This module attempts to make a Moose object behave like a JSON API object as |
98
|
|
|
|
|
|
|
defined by L<jsonapi.org>. This object adheres to the v1 specification. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SEE ALSO |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * L<https://jsonapi.org/format/#document-resource-objects> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Wesley Schwengle <waterkip@cpan.org> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Wesley Schwengle. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software, licensed under: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The (three-clause) BSD License |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |