line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
12005
|
use utf8; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
18
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package JSON::API::v1::Links; |
4
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
5
|
3
|
|
|
3
|
|
566
|
use Moose; |
|
3
|
|
|
|
|
390006
|
|
|
3
|
|
|
|
|
22
|
|
6
|
3
|
|
|
3
|
|
15176
|
use namespace::autoclean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
7
|
3
|
|
|
3
|
|
215
|
use Carp qw(croak); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
190
|
|
8
|
3
|
|
|
3
|
|
1265
|
use MooseX::Types::URI qw(Uri); |
|
3
|
|
|
|
|
514743
|
|
|
3
|
|
|
|
|
17
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: A JSON API Links object |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has uri => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => Uri, |
15
|
|
|
|
|
|
|
predicate => 'has_uri', |
16
|
|
|
|
|
|
|
coerce => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has related => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => 'JSON::API::v1::Links', |
22
|
|
|
|
|
|
|
predicate => 'has_related', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub TO_JSON { |
26
|
11
|
|
|
11
|
0
|
94
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
11
|
50
|
66
|
|
|
283
|
if (!$self->has_uri && !$self->has_related) { |
29
|
0
|
|
|
|
|
0
|
croak( |
30
|
|
|
|
|
|
|
"Unable to represent a link data object, both related" |
31
|
|
|
|
|
|
|
. "and uri are missing", |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
11
|
100
|
|
|
|
328
|
if ($self->has_meta_object) { |
35
|
|
|
|
|
|
|
return { |
36
|
3
|
50
|
|
|
|
73
|
meta => $self->meta_object, |
37
|
|
|
|
|
|
|
href => $self->uri, |
38
|
|
|
|
|
|
|
$self->has_related |
39
|
|
|
|
|
|
|
? (related => $self->related) |
40
|
|
|
|
|
|
|
: (), |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
return { |
44
|
8
|
100
|
|
|
|
196
|
$self->has_uri ? (self => $self->uri) : (), |
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->has_related |
46
|
|
|
|
|
|
|
? (related => $self->related) |
47
|
|
|
|
|
|
|
: (), |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Make sure we stringify the URI |
52
|
|
|
|
|
|
|
around uri => sub { |
53
|
|
|
|
|
|
|
my ($orig, $self) = @_; |
54
|
|
|
|
|
|
|
return $self->$orig . ""; |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
with qw( |
58
|
|
|
|
|
|
|
JSON::API::v1::Roles::TO_JSON |
59
|
|
|
|
|
|
|
JSON::API::v1::Roles::MetaObject |
60
|
|
|
|
|
|
|
); |
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::Links - A JSON API Links object |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 0.002 |
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 |