line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Neo4j; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27038
|
use 5.10.0; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
29
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
845
|
use Try::Tiny; |
|
1
|
|
|
|
|
2525
|
|
|
1
|
|
|
|
|
48
|
|
8
|
1
|
|
|
1
|
|
571
|
use Neo4j::Types; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Moose; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Neo4j::Node; |
12
|
|
|
|
|
|
|
use Neo4j::Relationship; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Neo4j::REST::Client; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.01_01"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# TODO use key property for looking up a node or an edge |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'service_root' => ( |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'client' => ( |
27
|
|
|
|
|
|
|
isa => 'Neo4j::REST::Client', |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
lazy => 1, |
30
|
|
|
|
|
|
|
builder => '_build_client', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _build_client { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
return Neo4j::REST::Client->new( { root_URL => $self->service_root, } ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add_node { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $data = shift; |
41
|
|
|
|
|
|
|
my $new_node = |
42
|
|
|
|
|
|
|
Neo4j::Node->new( { client => $self->client, data => $data } ); |
43
|
|
|
|
|
|
|
return $new_node; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_node { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
my $id = shift; |
49
|
|
|
|
|
|
|
my $node = Neo4j::Node->new( { client => $self->client, id => $id } ); |
50
|
|
|
|
|
|
|
return $node; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub delete_node { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
my $id = shift; |
56
|
|
|
|
|
|
|
my $url = |
57
|
|
|
|
|
|
|
sprintf( '%s/%s', $self->client->root_endpoint('node'), $self->id ); |
58
|
|
|
|
|
|
|
$self->client->DELETE($url); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
for ( $self->client->status ) { |
61
|
|
|
|
|
|
|
when ('204') { |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# all good |
64
|
|
|
|
|
|
|
return undef; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
when ('409') { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# throw conflict, can't delete a node in a relation' |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
default { |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# throw exception |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub relationship_types { |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
$self->client->GET($self->client->root_endpoint('relationship_types')); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
for ( $self->client->status ) { |
82
|
|
|
|
|
|
|
when ('200') { |
83
|
|
|
|
|
|
|
# all good |
84
|
|
|
|
|
|
|
return decode_json($self->client->content); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
default { |
87
|
|
|
|
|
|
|
# throw exception |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub get_relationship { |
93
|
|
|
|
|
|
|
my $self = shift; |
94
|
|
|
|
|
|
|
my $id = shift; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return undef unless defined $id; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $relationship = Neo4j::Relationship->new( { client => $self->client, id => $id } ); |
99
|
|
|
|
|
|
|
return $relationship; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub add_relationship { |
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
my $args = shift; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $start = Neo4j::Node->new({_self_endpoint => $args->{start}, client => $self->client, }); |
107
|
|
|
|
|
|
|
my $end = Neo4j::Node->new({_self_endpoint => $args->{end}, client => $self->client }); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
try { |
110
|
|
|
|
|
|
|
my $new_relationship = Neo4j::Relationship->new({ |
111
|
|
|
|
|
|
|
start => $start, |
112
|
|
|
|
|
|
|
end => $end, |
113
|
|
|
|
|
|
|
direction => $args->{direction}, |
114
|
|
|
|
|
|
|
type => $args->{type}, |
115
|
|
|
|
|
|
|
data => $args->{data}, |
116
|
|
|
|
|
|
|
client => $self->client, |
117
|
|
|
|
|
|
|
}); |
118
|
|
|
|
|
|
|
return $new_relationship; |
119
|
|
|
|
|
|
|
} catch { |
120
|
|
|
|
|
|
|
# wow something went really wrong |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 NAME |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Neo4j - A client for the Neo4j graph database |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SYNOPSIS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
use Neo4j; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $n = Neo4j->new({ service_root => 'http://localhost:7474/db/data' }); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $node = $n->get_node(3); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$node->set_property('foo', ["bar baz", "bada bada"]); |
141
|
|
|
|
|
|
|
$node->save; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 METHODS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 add_node |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$neo4j->add_node({ foo => 'bar', baz => [1,2,3,...], .... }) |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 get_node |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 delete_node |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 add_relationship |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 get_relationship |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 relationship_types |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 TODO |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
More documentation |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Nuba Princigalli, C<< <nuba at stastu.com> >> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 BUGS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-neo4j at rt.cpan.org>, or through |
170
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Neo4j>. I will be notified, and then you'll |
171
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SUPPORT |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
perldoc Neo4j |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
You can also look for information at: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Neo4j> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Neo4j> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * CPAN Ratings |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Neo4j> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * Search CPAN |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Neo4j/> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=back |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Copyright 2012 Nuba Princigalli. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
206
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
207
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
210
|
|
|
|
|
|
|
|