File Coverage

lib/Neo4j/Driver/Type/Node.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 5 5 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1 20     20   262 use v5.12;
  20         75  
2 20     20   148 use warnings;
  20         32  
  20         1683  
3              
4             package Neo4j::Driver::Type::Node 1.02;
5             # ABSTRACT: Describes a node from a Neo4j graph
6              
7              
8             # For documentation, see Neo4j::Driver::Types.
9              
10             # Jolt node: [ node_id, [node_labels], {properties} ]
11              
12              
13 20     20   187 use parent 'Neo4j::Types::Node';
  20         50  
  20         155  
14              
15              
16             sub get {
17 13     13 1 10040 my ($self, $property) = @_;
18            
19 13         85 return $self->[2]->{$property};
20             }
21              
22              
23             sub labels {
24 18     18 1 16096 my ($self) = @_;
25            
26 18         35 return @{ $self->[1] };
  18         137  
27             }
28              
29              
30             sub properties {
31 9     9 1 7694 my ($self) = @_;
32            
33 9         58 return $self->[2];
34             }
35              
36              
37             sub element_id {
38 6     6 1 6286 my ($self) = @_;
39            
40 6         41 return $self->[0];
41             }
42              
43              
44             sub id {
45 6     6 1 7499 my ($self) = @_;
46            
47 6         191 warnings::warnif deprecated => "Node->id() is deprecated since Neo4j 5; use element_id()";
48 6         2790 my ($id) = $self->[0] =~ m/^4:[^:]*:([0-9]+)/;
49 6 100       32 $id = 0 + $id if defined $id;
50 6         25 return $id;
51             }
52             # Unlike Bolt v5, the Jolt v2 format regrettably removes the legacy
53             # numeric ID from the response entirely. Therefore we generate it
54             # here using the algorithm from Neo4j's DefaultElementIdMapperV1;
55             # the final part of the element ID is identical to the legacy ID
56             # according to CypherFunctions in Neo4j 5.0-5.25.
57             # But this may break with future Neo4j versions.
58             # https://github.com/neo4j/neo4j/blob/5.25/community/values/src/main/java/org/neo4j/values/DefaultElementIdMapperV1.java#L61-L67
59             # https://github.com/neo4j/neo4j/blob/5.25/community/cypher/runtime-util/src/main/java/org/neo4j/cypher/operations/CypherFunctions.java#L1024-L1062
60             # https://community.neo4j.com/t/id-function-deprecated-how-to-replace-easily/62554/17
61              
62              
63             1;