line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: document builder - relationship |
2
|
|
|
|
|
|
|
package PONAPI::Builder::Relationship; |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
836485
|
use Moose; |
|
33
|
|
|
|
|
1654506
|
|
|
33
|
|
|
|
|
244
|
|
5
|
|
|
|
|
|
|
|
6
|
33
|
|
|
33
|
|
232933
|
use PONAPI::Builder::Resource::Identifier; |
|
33
|
|
|
|
|
129
|
|
|
33
|
|
|
|
|
20194
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'PONAPI::Builder', |
9
|
|
|
|
|
|
|
'PONAPI::Builder::Role::HasLinksBuilder', |
10
|
|
|
|
|
|
|
'PONAPI::Builder::Role::HasMeta'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has name => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'Str', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has _resource_id_builders => ( |
19
|
|
|
|
|
|
|
init_arg => undef, |
20
|
|
|
|
|
|
|
traits => [ 'Array' ], |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => 'ArrayRef[ PONAPI::Builder::Resource::Identifier ]', |
23
|
|
|
|
|
|
|
lazy => 1, |
24
|
|
|
|
|
|
|
default => sub { +[] }, |
25
|
|
|
|
|
|
|
predicate => '_has_resource_id_builders', |
26
|
|
|
|
|
|
|
handles => { |
27
|
|
|
|
|
|
|
'_num_resource_id_builders' => 'count', |
28
|
|
|
|
|
|
|
# private ... |
29
|
|
|
|
|
|
|
'_add_resource_id_builder' => 'push', |
30
|
|
|
|
|
|
|
'_get_resource_id_builder' => 'get', |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has collection => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => 'Bool', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub has_resource { |
40
|
2
|
|
|
2
|
0
|
15
|
my $self = $_[0]; |
41
|
2
|
50
|
|
|
|
101
|
$self->_has_resource_id_builders && $self->_num_resource_id_builders > 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub has_resources { |
45
|
259
|
|
|
259
|
0
|
425
|
my $self = $_[0]; |
46
|
259
|
50
|
|
|
|
12723
|
$self->_has_resource_id_builders && $self->_num_resource_id_builders > 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub add_resource { |
50
|
143
|
|
|
143
|
0
|
4911
|
my ( $self, $resource ) = @_; |
51
|
143
|
|
|
|
|
7062
|
my $b = PONAPI::Builder::Resource::Identifier->new( parent => $self, %$resource ); |
52
|
143
|
100
|
|
|
|
530
|
$b->add_meta( %{ $resource->{meta} } ) if $resource->{meta}; |
|
1
|
|
|
|
|
7
|
|
53
|
143
|
|
|
|
|
8097
|
$self->_add_resource_id_builder( $b ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
119
|
|
|
119
|
0
|
385
|
sub add_self_link { $_[0]->_add_relationship_link('self') } |
57
|
119
|
|
|
119
|
0
|
306
|
sub add_related_link { $_[0]->_add_relationship_link('related') } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _add_relationship_link { |
60
|
238
|
|
|
238
|
|
415
|
my ( $self, $key ) = @_; |
61
|
238
|
|
|
|
|
8760
|
my $rec = $self->parent->build; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->links_builder->add_link( |
64
|
|
|
|
|
|
|
$key => $self->find_root->req_base |
65
|
|
|
|
|
|
|
. $rec->{type} |
66
|
|
|
|
|
|
|
. '/' . $rec->{id} |
67
|
238
|
100
|
|
|
|
10123
|
. ( $key eq 'self' ? '/relationships' : '' ) |
68
|
|
|
|
|
|
|
. '/' . $self->name |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
238
|
|
|
|
|
1947
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub build { |
75
|
424
|
|
|
424
|
0
|
649
|
my $self = $_[0]; |
76
|
424
|
|
|
|
|
663
|
my $result = {}; |
77
|
|
|
|
|
|
|
|
78
|
424
|
100
|
100
|
|
|
16481
|
if ( $self->collection || $self->has_resources ) { |
79
|
|
|
|
|
|
|
# if it is a collection, then |
80
|
|
|
|
|
|
|
# call build on each one ... |
81
|
172
|
|
|
|
|
258
|
$result->{data} = [ map { $_->build } @{ $self->_resource_id_builders } ]; |
|
266
|
|
|
|
|
896
|
|
|
172
|
|
|
|
|
7004
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
|
|
|
|
|
|
# if it is a single resource, |
85
|
|
|
|
|
|
|
# just use that one |
86
|
252
|
|
|
|
|
13557
|
$result->{data} = $self->_get_resource_id_builder(0)->build; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
424
|
100
|
|
|
|
20751
|
$result->{links} = $self->links_builder->build if $self->has_links_builder; |
90
|
424
|
100
|
|
|
|
20145
|
$result->{meta} = $self->_meta if $self->has_meta; |
91
|
|
|
|
|
|
|
|
92
|
424
|
|
|
|
|
2197
|
return $result; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
96
|
33
|
|
|
33
|
|
357
|
no Moose; 1; |
|
33
|
|
|
|
|
91
|
|
|
33
|
|
|
|
|
301
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
PONAPI::Builder::Relationship - document builder - relationship |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 0.002006 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHORS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=over 4 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Mickey Nasriachi <mickey@cpan.org> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Brian Fraser <hugmeir@cpan.org> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |