| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Neo4j::Bolt; |
|
2
|
4
|
|
|
4
|
|
85203
|
use Cwd qw/realpath getcwd/; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
334
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
|
5
|
4
|
|
|
4
|
|
14
|
our $VERSION = "0.4203"; |
|
6
|
4
|
|
|
|
|
1531
|
require Neo4j::Bolt::Cxn; |
|
7
|
4
|
|
|
|
|
1412
|
require Neo4j::Bolt::Txn; |
|
8
|
4
|
|
|
|
|
26
|
require Neo4j::Bolt::ResultStream; |
|
9
|
4
|
|
|
|
|
12
|
require Neo4j::Bolt::CTypeHandlers; |
|
10
|
4
|
|
|
|
|
12
|
require XSLoader; |
|
11
|
4
|
|
|
|
|
9725
|
XSLoader::load(); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
our $DEFAULT_DB = "neo4j"; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub connect { |
|
17
|
0
|
|
0
|
0
|
1
|
|
$_[0]->connect_( $_[1], $_[2] // 0, 0, "", "", "", "" ); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub connect_tls { |
|
21
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
22
|
0
|
|
|
|
|
|
my ($url, $tls) = @_; |
|
23
|
0
|
0
|
0
|
|
|
|
unless ($tls && (ref($tls) == 'HASH')) { |
|
24
|
0
|
|
|
|
|
|
die "Arg 1 should URL and Arg 2 a hashref with keys 'ca_dir','ca_file','pk_file','pk_pass'" |
|
25
|
|
|
|
|
|
|
} |
|
26
|
0
|
|
|
|
|
|
my %default_ca = (); |
|
27
|
0
|
|
|
|
|
|
eval { |
|
28
|
0
|
|
|
|
|
|
require IO::Socket::SSL; |
|
29
|
0
|
|
|
|
|
|
%default_ca = IO::Socket::SSL::default_ca(); |
|
30
|
|
|
|
|
|
|
}; |
|
31
|
0
|
0
|
|
|
|
|
eval { |
|
32
|
0
|
|
|
|
|
|
require Mozilla::CA; |
|
33
|
0
|
|
|
|
|
|
$default_ca{SSL_ca_file} = Mozilla::CA::SSL_ca_file(); |
|
34
|
|
|
|
|
|
|
} unless %default_ca; |
|
35
|
|
|
|
|
|
|
return $self->connect_( |
|
36
|
|
|
|
|
|
|
$url, |
|
37
|
|
|
|
|
|
|
$tls->{timeout}, |
|
38
|
|
|
|
|
|
|
1, # encrypt |
|
39
|
|
|
|
|
|
|
$tls->{ca_dir} // $default_ca{SSL_ca_path} // "", |
|
40
|
|
|
|
|
|
|
$tls->{ca_file} // $default_ca{SSL_ca_file} // "", |
|
41
|
|
|
|
|
|
|
$tls->{pk_file} || "", |
|
42
|
0
|
|
0
|
|
|
|
$tls->{pk_pass} || "" |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Neo4j::Bolt - query Neo4j using Bolt protocol |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=for markdown [](https://travis-ci.org/majensen/perlbolt) |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Neo4j::Bolt; |
|
57
|
|
|
|
|
|
|
$cxn = Neo4j::Bolt->connect("bolt://localhost:7687"); |
|
58
|
|
|
|
|
|
|
$stream = $cxn->run_query( |
|
59
|
|
|
|
|
|
|
"MATCH (a) RETURN head(labels(a)) as lbl, count(a) as ct", |
|
60
|
|
|
|
|
|
|
{} # parameter hash required |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
@names = $stream->field_names; |
|
63
|
|
|
|
|
|
|
while ( my @row = $stream->fetch_next ) { |
|
64
|
|
|
|
|
|
|
print "For label '$row[0]' there are $row[1] nodes.\n"; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
$stream = $cxn->run_query( |
|
67
|
|
|
|
|
|
|
"MATCH (a) RETURN labels(a) as lbls, count(a) as ct", |
|
68
|
|
|
|
|
|
|
{} # parameter hash required |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
while ( my @row = $stream->fetch_next ) { |
|
71
|
|
|
|
|
|
|
print "For label set [".join(',',@{$row[0]})."] there are $row[1] nodes.\n"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L is a Perl wrapper around Chris Leishmann's excellent |
|
77
|
|
|
|
|
|
|
L library |
|
78
|
|
|
|
|
|
|
implementing the Neo4j L network |
|
79
|
|
|
|
|
|
|
protocol. It uses Ingy's L to do all the hard XS work. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 Return Types |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L returns rows resulting from queries made |
|
84
|
|
|
|
|
|
|
via a L. These rows are simple arrays of scalars and/or |
|
85
|
|
|
|
|
|
|
references. These represent Neo4j types according to the following: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Neo4j type Perl representation |
|
88
|
|
|
|
|
|
|
----- ---- ---- -------------- |
|
89
|
|
|
|
|
|
|
Null undef |
|
90
|
|
|
|
|
|
|
Bool JSON::PP::Boolean (acts like 0 or 1) |
|
91
|
|
|
|
|
|
|
Int scalar |
|
92
|
|
|
|
|
|
|
Float scalar |
|
93
|
|
|
|
|
|
|
String scalar |
|
94
|
|
|
|
|
|
|
Bytes scalar |
|
95
|
|
|
|
|
|
|
List arrayref |
|
96
|
|
|
|
|
|
|
Map hashref |
|
97
|
|
|
|
|
|
|
Node hashref (Neo4j::Bolt::Node) |
|
98
|
|
|
|
|
|
|
Relationship hashref (Neo4j::Bolt::Relationship) |
|
99
|
|
|
|
|
|
|
Path arrayref (Neo4j::Bolt::Path) |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L, L and |
|
102
|
|
|
|
|
|
|
L are represented in the following formats: |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Node: |
|
105
|
|
|
|
|
|
|
bless { |
|
106
|
|
|
|
|
|
|
id => $node_id, labels => [$label1, $label2, ...], |
|
107
|
|
|
|
|
|
|
properties => {prop1 => $value1, prop2 => $value2, ...} |
|
108
|
|
|
|
|
|
|
}, 'Neo4j::Bolt::Node' |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Relationship: |
|
111
|
|
|
|
|
|
|
bless { |
|
112
|
|
|
|
|
|
|
id => $reln_id, type => $reln_type, |
|
113
|
|
|
|
|
|
|
start => $start_node_id, end => $end_node_id, |
|
114
|
|
|
|
|
|
|
properties => {prop1 => $value1, prop2 => $value2, ...} |
|
115
|
|
|
|
|
|
|
}, 'Neo4j::Bolt::Relationship' |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Path: |
|
118
|
|
|
|
|
|
|
bless [ |
|
119
|
|
|
|
|
|
|
$node1, $reln12, $node2, $reln23, $node3, ... |
|
120
|
|
|
|
|
|
|
], 'Neo4j::Bolt::Path' |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHODS |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=over |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item connect($url), connect_tls($url,$tls_hash) |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Class method, connect to Neo4j server. The URL scheme must be C<'bolt'>, as in |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$url = 'bolt://localhost:7687'; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns object of type L, which accepts Cypher queries and |
|
133
|
|
|
|
|
|
|
returns a L. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
To connect by SSL/TLS, use connect_tls, with a hashref with keys as follows |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
ca_dir =>
|
|
138
|
|
|
|
|
|
|
ca_file =>
|
|
139
|
|
|
|
|
|
|
pk_file =>
|
|
140
|
|
|
|
|
|
|
pk_pass => |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Example: |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$cxn = Neo4j::Bolt->connect_tls('bolt://all-the-young-dudes.us:7687', { ca_cert => '/etc/ssl/cert.pem' }); |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
When neither C nor C are specified, an attempt will |
|
147
|
|
|
|
|
|
|
be made to use the default trust store instead. |
|
148
|
|
|
|
|
|
|
This requires L or L to be installed. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item set_log_level($LEVEL) |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
When $LEVEL is set to one of the strings C or C, |
|
153
|
|
|
|
|
|
|
libneo4j-client native logger will emit log messages at or above the given |
|
154
|
|
|
|
|
|
|
level, on STDERR. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Set to C to turn off completely (the default). |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L, L. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHOR |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Mark A. Jensen |
|
167
|
|
|
|
|
|
|
CPAN: MAJENSEN |
|
168
|
|
|
|
|
|
|
majensen -at- cpan -dot- org |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=over |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item Arne Johannessen (@johannessen) |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 LICENSE |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This software is Copyright (c) 2019-2021 by Mark A. Jensen. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This is free software, licensed under: |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |