line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
14613
|
use utf8; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
22
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package JSON::API::v1::Links; |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
5
|
3
|
|
|
3
|
|
709
|
use Moose; |
|
3
|
|
|
|
|
469951
|
|
|
3
|
|
|
|
|
24
|
|
6
|
3
|
|
|
3
|
|
18503
|
use namespace::autoclean; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
33
|
|
7
|
3
|
|
|
3
|
|
252
|
use Carp qw(croak); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
215
|
|
8
|
3
|
|
|
3
|
|
1704
|
use MooseX::Types::URI qw(Uri); |
|
3
|
|
|
|
|
634524
|
|
|
3
|
|
|
|
|
20
|
|
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
|
120
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
11
|
50
|
66
|
|
|
347
|
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
|
|
|
|
390
|
if ($self->has_meta_object) { |
35
|
|
|
|
|
|
|
return { |
36
|
3
|
50
|
|
|
|
84
|
meta => $self->meta_object, |
37
|
|
|
|
|
|
|
href => $self->uri, |
38
|
|
|
|
|
|
|
$self->has_related |
39
|
|
|
|
|
|
|
? (related => $self->related) |
40
|
|
|
|
|
|
|
: (), |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
return { |
44
|
8
|
100
|
|
|
|
260
|
$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.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 |