line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: document builder - relationship |
2
|
|
|
|
|
|
|
package PONAPI::Builder::Relationship; |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
902049
|
use Moose; |
|
33
|
|
|
|
|
1741754
|
|
|
33
|
|
|
|
|
216
|
|
5
|
|
|
|
|
|
|
|
6
|
33
|
|
|
33
|
|
232113
|
use PONAPI::Builder::Resource::Identifier; |
|
33
|
|
|
|
|
133
|
|
|
33
|
|
|
|
|
20034
|
|
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
|
14
|
my $self = $_[0]; |
41
|
2
|
50
|
|
|
|
135
|
$self->_has_resource_id_builders && $self->_num_resource_id_builders > 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub has_resources { |
45
|
243
|
|
|
243
|
0
|
426
|
my $self = $_[0]; |
46
|
243
|
50
|
|
|
|
12638
|
$self->_has_resource_id_builders && $self->_num_resource_id_builders > 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub add_resource { |
50
|
143
|
|
|
143
|
0
|
5303
|
my ( $self, $resource ) = @_; |
51
|
143
|
|
|
|
|
7206
|
my $b = PONAPI::Builder::Resource::Identifier->new( parent => $self, %$resource ); |
52
|
143
|
100
|
|
|
|
534
|
$b->add_meta( %{ $resource->{meta} } ) if $resource->{meta}; |
|
1
|
|
|
|
|
7
|
|
53
|
143
|
|
|
|
|
8342
|
$self->_add_resource_id_builder( $b ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
119
|
|
|
119
|
0
|
391
|
sub add_self_link { $_[0]->_add_relationship_link('self') } |
57
|
119
|
|
|
119
|
0
|
350
|
sub add_related_link { $_[0]->_add_relationship_link('related') } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _add_relationship_link { |
60
|
238
|
|
|
238
|
|
442
|
my ( $self, $key ) = @_; |
61
|
238
|
|
|
|
|
10357
|
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
|
|
|
|
10321
|
. ( $key eq 'self' ? '/relationships' : '' ) |
68
|
|
|
|
|
|
|
. '/' . $self->name |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
238
|
|
|
|
|
2255
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub build { |
75
|
418
|
|
|
418
|
0
|
640
|
my $self = $_[0]; |
76
|
418
|
|
|
|
|
689
|
my $result = {}; |
77
|
|
|
|
|
|
|
|
78
|
418
|
100
|
100
|
|
|
16891
|
if ( $self->collection || $self->has_resources ) { |
79
|
|
|
|
|
|
|
# if it is a collection, then |
80
|
|
|
|
|
|
|
# call build on each one ... |
81
|
182
|
|
|
|
|
284
|
$result->{data} = [ map { $_->build } @{ $self->_resource_id_builders } ]; |
|
282
|
|
|
|
|
996
|
|
|
182
|
|
|
|
|
7857
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
|
|
|
|
|
|
# if it is a single resource, |
85
|
|
|
|
|
|
|
# just use that one |
86
|
236
|
|
|
|
|
13015
|
$result->{data} = $self->_get_resource_id_builder(0)->build; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
418
|
100
|
|
|
|
21431
|
$result->{links} = $self->links_builder->build if $self->has_links_builder; |
90
|
418
|
100
|
|
|
|
20683
|
$result->{meta} = $self->_meta if $self->has_meta; |
91
|
|
|
|
|
|
|
|
92
|
418
|
|
|
|
|
2166
|
return $result; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
96
|
33
|
|
|
33
|
|
375
|
no Moose; 1; |
|
33
|
|
|
|
|
75
|
|
|
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.002005 |
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 |