package REST::Neo4p;
use Carp qw(croak carp);
use lib '../../lib';
use JSON;
use URI;
use URI::Escape;
use HTTP::Tiny;
use JSON::ize;
use Neo4j::Driver 0.1801;
use REST::Neo4p::Agent;
use REST::Neo4p
;
our $HANDLE = 0;
our $AGENT_MODULE = $ENV{REST_NEO4P_AGENT_MODULE} || 'LWP::UserAgent';
my $json = JSON->new->allow_nonref(1)->utf8;
$HANDLES[0]->{_q_endpoint} = 'cypher';
sub set_handle {
my $
nected\n") unless $neo4p->connected;
my $decoded_resp;
if ($value) {
$value = uri_escape($json->encode($value));
}
eval {
# following line should work, but doesn't yet (self-discovery iss
;
my @bricks = ($rq => $url => { @{$self->{_default_headers}}, @args});
push @bricks, json => $content if defined $content;
$tx = $self->build_tx(@bricks);
if (defined $content
$j)];
}
else {
# problem
return;
}
}
# generic parse array stream
# return decoded json entities at the top level
# opening [ must be removed
# handle empty array too
sub j_parse_array
($j->incr_text =~ m/^\]}\],/) { # JSON::XS <=3.04 transaction kludge
$j->incr_text =~ s/(\])(}\],)//;
$done=1;
}
elsif ($elt eq 'transaction') { # JSON::XS 4.02 transaction kludge
$j->
it the L<Neo4j|http://neo4j.org>
server's chunked transfer encoding of its JSON REST responses. It is
based on the fast L<JSON::XS> incremental parser and
L<MJD|https://metacpan.org/author/MJD>'s L<Hi
N = '0.4003';
}
sub new {
my $class = shift;
bless { _length => 0 }, $class;
}
sub new_from_json_response {
my $class = shift;
my ($decoded_resp) = @_;
return $class->new_from_driver_obj(@
if defined $r;
}
return $ret;
}
sub simple_from_json_response {
my $class = shift;
my ($decoded_resp) = @_;
return $class->new_from_json_response($decoded_resp)->as_simple;
}
sub nodes { @
#$Id$
use v5.10.1;
package REST::Neo4p::Batch;
use REST::Neo4p::Exceptions;
use JSON::XS;
use REST::Neo4p::ParseStream;
use HOP::Stream qw/drop head/;
require REST::Neo4p;
use base qw(Exporter);
use
= $agent->execute_batch_chunk;
my $jsonr = JSON::XS->new->utf8;
my $buf;
$tmpfh->read($buf, $BUFSIZE);
$jsonr->incr_parse($buf);
my $res = j_parse($jsonr);
die "j_parse: expecting BATCH s
j) if $action eq 'keep_objs';
}
}
when ('PENDING') {
$tmpfh->read($buf,$BUFSIZE);
$jsonr->incr_parse($buf)
}
when (!defined) {
last;
}
default {
die "j_parse:
;
use base 'REST::Neo4p::Entity';
use REST::Neo4p::Relationship;
use REST::Neo4p::Exceptions;
use JSON;
use Carp qw(croak carp);
use strict;
use warnings;
BEGIN {
$REST::Neo4p::Node::VERSION = '0.40
$@->rethrow : die $@;
}
return ref($decoded_resp) ?
REST::Neo4p::Relationship->new_from_json_response($decoded_resp) :
REST::Neo4p::Relationship->new_from_batch_response($decoded_resp);
}
}
for (@$decoded_resp) {
push @ret, ref($_) ?
REST::Neo4p::Relationship->new_from_json_response($_) :
REST::Neo4p::Relationship->new_from_batch_response($_);
}
return @ret;
}
s
$self->end_node};
$ret->{$_} = $props->{$_} for keys %$props;
return $ret;
}
sub simple_from_json_response {
my $class = shift;
my ($decoded_resp) = @_;
my $ret;
for (ref $decoded_resp) {
JSON;
use File::Temp;
use Carp qw(croak carp);
use strict;
use warnings;
our @ISA;
our $VERSION;
BEGIN {
$REST::Neo4p::Agent::VERSION = '0.4003';
}
our $AUTOLOAD;
our $JOB_CHUNK = 1024;
our $JSON
= JSON->new()->allow_nonref(1)->utf8;
our $RQ_RETRIES = 3;
our $RETRY_WAIT = 5;
sub new {
my $class = shift;
my %args = @_;
my $mod = delete $args{agent_module} || 'LWP::UserAgent';
die "No u
o4p/$VERSION");
$self->default_header( 'Accept' => 'application/json' );
$self->default_header( 'Content-Type' => 'application/json' );
$self->default_header( 'X-Stream' => 'true' );
$self->pr
class->SUPER::new($properties);
}
sub new_from_json_response {
my $class = shift;
my ($decoded_resp) = @_;
my $obj = $class->SUPER::new_from_json_response($decoded_resp);
$obj->_entry->{actio
Node' :
'REST::Neo4p::Relationship';
for (@$decoded_resp) {
push @ret, $class->new_from_json_response($_);
}
return @ret;
}
# create_unique : route to correct method
sub create_unique {
(ref $e && $e->can("rethrow")) ? $e->rethrow : die $e;
}
return REST::Neo4p::Node->new_from_json_response($decoded_resp);
}
sub create_unique_relationship {
my $self = shift;
my ($key, $val
use v5.10;
package REST::Neo4p::Query;
use REST::Neo4p::Path;
use REST::Neo4p::Exceptions;
use JSON::XS;
use REST::Neo4p::ParseStream;
use HOP::Stream qw/drop/;
use Tie::IxHash;
use File::Temp qw(:see
;
my $cls = "REST::Neo4p::$type";
return $as_object ? $cls->new_from_json_response($_[0]) :
$cls->simple_from_json_response($_[0]);
};
for (ref($elt)) {
/Driver/ && do {
$elt =
w, $elt;
}
}
};
if (my $e = Exception::Class->caught()) {
if ($e =~ /j_parse|json/i) {
$e = REST::Neo4p::StreamException->new(message => $e);
$self->{_error} = $e;
$e->throw if
ion.
# Each function returns a Perl data structure that corresponds to (possibly a subset of) the JSON that would
# have been returned by the old Neo4j REST endpoint.
$result_processors{get_node} = s
ocessed. If called in a non-void context, the result is processed (via ResultProcessors) into a
# json/Perl format suitable for parsing by REST::Neo4p
#
# data
sub available_actions {
my $self =
ib '../../../../../lib'; # testing
use base qw/REST::Neo4p::Agent/;
use Neo4j::Driver 0.1803;
use JSON::ize;
use REST::Neo4p::Agent::Neo4j::DriverActions;
use REST::Neo4p::Exceptions;
use Try::Tiny;
u
:Neo4p::StreamException' => {
isa => 'REST::Neo4p::LocalException',
description => 'Neo4j JSON response parsing error',
fields => ['message']
},
'REST::Neo4p::ConstraintException' =>
nstraint subclass objects directly
# - factory function create_constraint()
# - load from a file (JSON, XML)
require REST::Neo4p::Entity;
require REST::Neo4p::Node;
sub create_constraint {
my %par
hip type disallowed, ignoring...\n";
}
# serialize all constraints
open $f, ">my_constraints.json";
print $f serialize_constraints();
close $f;
# remove current constraints
while ( my ($tag
traint->drop;
}
# restore constraints
open $f, "my_constraints.json";
local $/ = undef;
$json = <$f>;
load_constraints($json);
=head1 DESCRIPTION
L<Neo4j|http://neo4j.org>, as a NoSQL databa
use v5.10;
package REST::Neo4p::Entity;
use REST::Neo4p::Exceptions;
use Carp qw(croak carp);
use JSON;
use URI::Escape;
use strict;
use warnings;
# base class for nodes, relationships, indexes...
BE
from_json_response($decoded_resp) :
$class->new_from_batch_response($decoded_resp, @$url_components);
}
# TODO: refactor for when response is from Neo4j::Driver (a Result)
sub new_from_json_res
row("new_from_json_response() called with undef argument\n");
}
my $is_json = !(ref($decoded_resp) =~ /Neo4j::Driver/);
unless ($ENTITY_TABLE->{$entity_type}{_actions} || !$is_json) {
# capt
e REST::Neo4p::Constraint;
use base 'Exporter';
use REST::Neo4p;
use REST::Neo4p::Exceptions;
use JSON;
use Data::Dumper;
use Scalar::Util qw(looks_like_number);
use strict;
use warnings;
our @EXPOR
[@EXPORT],
all => [@EXPORT,@EXPORT_OK]
);
our $jobj = JSON->new->utf8;
$jobj->allow_blessed(1);
$jobj->convert_blessed(1);
my $regex_to_json = sub {
my $qr = shift;
local $Data::Dumper::Terse=1
.__PACKAGE__."\n");
}
sub TO_JSON {
no warnings qw(redefine);
my $self = shift;
my $store;
my $old = *Regexp::TO_JSON{CODE};
*Regexp::TO_JSON = $regex_to_json;
$store = $self->constraint