line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#$Id$ |
2
|
|
|
|
|
|
|
package REST::Neo4p::Relationship; |
3
|
36
|
|
|
36
|
|
246
|
use base 'REST::Neo4p::Entity'; |
|
36
|
|
|
|
|
74
|
|
|
36
|
|
|
|
|
2594
|
|
4
|
36
|
|
|
36
|
|
224
|
use REST::Neo4p::Exceptions; |
|
36
|
|
|
|
|
62
|
|
|
36
|
|
|
|
|
793
|
|
5
|
36
|
|
|
36
|
|
262
|
use Carp qw(croak carp); |
|
36
|
|
|
|
|
117
|
|
|
36
|
|
|
|
|
1912
|
|
6
|
36
|
|
|
36
|
|
227
|
use strict; |
|
36
|
|
|
|
|
87
|
|
|
36
|
|
|
|
|
1075
|
|
7
|
36
|
|
|
36
|
|
228
|
use warnings; |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
1817
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
36
|
|
|
36
|
|
23203
|
$REST::Neo4p::Relationship::VERSION = '0.4000'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
14
|
0
|
|
|
|
|
|
my ($from_node, $to_node, $type, $rel_props) = @_; |
15
|
0
|
0
|
0
|
|
|
|
unless (ref $from_node && $from_node->isa('REST::Neo4p::Node') && |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
16
|
|
|
|
|
|
|
ref $to_node && $to_node->isa('REST::Neo4p::Node') && |
17
|
|
|
|
|
|
|
defined $type) { |
18
|
0
|
|
|
|
|
|
REST::Neo4p::LocalException->throw("Requires 2 REST::Neo4p::Node objects and a relationship type\n"); |
19
|
|
|
|
|
|
|
} |
20
|
0
|
|
|
|
|
|
return $from_node->relate_to($to_node, $type, $rel_props); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub type { |
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
return $self->_entry->{type}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub start_node { |
29
|
0
|
|
|
0
|
1
|
|
return REST::Neo4p->get_node_by_id(shift->_entry->{start_id}); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub end_node { |
33
|
0
|
|
|
0
|
1
|
|
return REST::Neo4p->get_node_by_id(shift->_entry->{end_id}); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub as_simple { |
37
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
38
|
0
|
|
|
|
|
|
my $ret; |
39
|
0
|
|
|
|
|
|
my $props = $self->get_properties; |
40
|
0
|
|
|
|
|
|
$ret->{_relationship} = $$self + 0; |
41
|
0
|
|
|
|
|
|
$ret->{_type} = $self->type; |
42
|
0
|
|
|
|
|
|
$ret->{_start} = ${$self->start_node}; |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$ret->{_end} = ${$self->end_node}; |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$ret->{$_} = $props->{$_} for keys %$props; |
45
|
0
|
|
|
|
|
|
return $ret; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub simple_from_json_response { |
49
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
50
|
0
|
|
|
|
|
|
my ($decoded_resp) = @_; |
51
|
0
|
|
|
|
|
|
my $ret; |
52
|
0
|
|
|
|
|
|
for (ref $decoded_resp) { |
53
|
0
|
0
|
|
|
|
|
/HASH/ && do { |
54
|
|
|
|
|
|
|
# reln id |
55
|
0
|
|
|
|
|
|
($ret->{_relationship}) = $decoded_resp->{self} =~ m{.*/([0-9]+)$}; |
56
|
|
|
|
|
|
|
# reln type |
57
|
0
|
|
|
|
|
|
$ret->{_type} = $decoded_resp->{type}; |
58
|
|
|
|
|
|
|
# reln properties |
59
|
0
|
|
|
|
|
|
$ret->{$_} = $decoded_resp->{data}->{$_} for keys %{$decoded_resp->{data}}; |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# start and end nodes (by id) |
61
|
0
|
|
|
|
|
|
($ret->{_start}) = $decoded_resp->{start} =~ m{.*/([0-9]+)$}; |
62
|
0
|
|
|
|
|
|
($ret->{_end}) = $decoded_resp->{end} =~ m{.*/([0-9]+)$}; |
63
|
0
|
|
|
|
|
|
last; |
64
|
|
|
|
|
|
|
}; |
65
|
0
|
0
|
|
|
|
|
/Driver/ && do { |
66
|
0
|
|
|
|
|
|
$ret->{_relationship} = $decoded_resp->id; |
67
|
0
|
|
|
|
|
|
$ret->{_type} = $decoded_resp->type; |
68
|
0
|
|
|
|
|
|
$ret->{$_} = $decoded_resp->properties->{$_} for keys %{$decoded_resp->properties}; |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$ret->{_start} = $decoded_resp->start_id; |
70
|
0
|
|
|
|
|
|
$ret->{_end} = $decoded_resp->end_id; |
71
|
0
|
|
|
|
|
|
last; |
72
|
|
|
|
|
|
|
}; |
73
|
0
|
|
|
|
|
|
do { |
74
|
0
|
|
|
|
|
|
die "?"; |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
return $ret; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
REST::Neo4p::Relationship - Neo4j relationship object |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SYNOPSIS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$n1 = REST::Neo4p::Node->new( {name => 'Harry'} ); |
87
|
|
|
|
|
|
|
$n2 = REST::Neo4p::Node->new( {name => 'Sally'} ); |
88
|
|
|
|
|
|
|
$r1 = $n1->relate_to($n2, 'met'); |
89
|
|
|
|
|
|
|
$r1->set_property({ when => 'July' }); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$r2 = REST::Neo4p::Relationship->new( $n2 => $n1, 'dropped' ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
REST::Neo4p::Relationship objects represent Neo4j relationships. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item new() |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$r1 = REST::Neo4p::Relationship->new($node1, $node2, 'ingratiates'); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Creates the relationship given by the scalar third argument between |
106
|
|
|
|
|
|
|
the first argument and second argument, both C |
107
|
|
|
|
|
|
|
objects. An optional fourth argument is a hashref of I |
108
|
|
|
|
|
|
|
properties. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item remove() |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$reln->remove() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Removes the relationship from the database. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item get_property() |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$status = $reln->get_property('status'); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Get the values of properties on nodes and relationships. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item set_property() |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$node1->relate_to($node2,"is_pal_of")->set_property( {duration => 'old pal'} ); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Sets values of properties on nodes and relationships. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item get_properties() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$props = $relationship->get_properties; |
131
|
|
|
|
|
|
|
print "Come here often?" if ($props->{status} eq 'not_currently_seeing'); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Get all the properties of relationship as a hashref. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item remove_property() |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$relationship->remove_property('name'); |
138
|
|
|
|
|
|
|
$relationship->remove_property(@property_names); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Remove properties from relationship. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item start_node(), end_node() |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$fred_node = $married_to->start_node; |
145
|
|
|
|
|
|
|
$wilma_node = $married_to->end_node; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Get the start and end nodes of the relationship. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item type() |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$rel = $node->relate_to($node2, 'my_type'); |
152
|
|
|
|
|
|
|
print "This is my_type of relationship" if $rel->type eq 'my_type'; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Gets a relationship's type. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item Property auto-accessors |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
See L. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item as_simple() |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
$simple_reln = $reln1->as_simple |
163
|
|
|
|
|
|
|
$rel_id = $simple_reln->{_relationship}; |
164
|
|
|
|
|
|
|
$value = $simple_reln->{$property_name}; |
165
|
|
|
|
|
|
|
$type = $simple_reln->{_type}; |
166
|
|
|
|
|
|
|
$start_node_id = $simple_reln->{_start}; |
167
|
|
|
|
|
|
|
$end_node_id = $simple_reln->{_end}; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Get relationship as a simple hashref. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L, L, L. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Mark A. Jensen |
180
|
|
|
|
|
|
|
CPAN ID: MAJENSEN |
181
|
|
|
|
|
|
|
majensen -at- cpan -dot- org |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 LICENSE |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Copyright (c) 2012-2020 Mark A. Jensen. This program is free software; you |
186
|
|
|
|
|
|
|
can redistribute it and/or modify it under the same terms as Perl |
187
|
|
|
|
|
|
|
itself. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |