Neo4j.pm

filter: Statementstmt 90.0% 18 / 20 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.5% 25 / 27 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Neo4j/Relationship.pm ↑ Summary
1 package Neo4j;
2  
3 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Neo4j::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶use Neo4j::Node;
Subroutine BEGIN: called CC=1 SCAR=2.6
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__
« Neo4j/Relationship.pm ↑ Summary