++ed by:

3 PAUSE users
3 non-PAUSE users.

Mark Allen Jensen
and 1 contributors


REST::Neo4p - Perl object bindings for a Neo4j database


  use REST::Neo4p;
  $i = REST::Neo4p::Index->new('node', 'my_node_index');
  $i->add_entry(REST::Neo4p::Node->new({ name => 'Fred Rogers' }),
                                       guy  => 'Fred Rogers');
  $index = REST::Neo4p->get_index_by_name('my_node_index','node');
 ($my_node) = $index->find_entries('guy' => 'Fred Rogers');
  $new_neighbor = REST::Neo4p::Node->new({'name' => 'Donkey Hoty'});
  $my_reln = $my_node->relate_to($new_neighbor, 'neighbor');

  $query = REST::Neo4p::Query->new("START n=node(".$my_node->id.")
                                    MATCH p = (n)-[]->()
                                    RETURN p");
  $path = $query->fetch->[0];
  @path_nodes = $path->nodes;
  @path_rels = $path->relationships;

Batch processing (see REST::Neo4p::Batch for more)

 # loader...
 use REST::Neo4p;
 use REST::Neo4p::Batch;
 open $f, shift() or die $!;
 batch {
   while (<$f>) {
    ($name, $value) = split /\t/;
    REST::Neo4p::Node->new({name => $name, value => $value});
   } 'discard_objs';


REST::Neo4p provides a Perl 5 object framework for accessing and manipulating a Neo4j graph database server via the Neo4j REST API. Its goals are

(1) to make the API as transparent as possible, allowing the user to work exclusively with Perl objects, and

(2) to exploit the API's self-discovery mechanisms, avoiding as much as possible internal hard-coding of URLs.

Neo4j entities are represented by corresponding classes:

Actions on class instances have a corresponding effect on the database (i.e., REST::Neo4p approximates an ORM).

The class REST::Neo4p::Query provides a DBIesqe Cypher query facility.

Property Auto-accessors

Depending on the application, it may be natural to think of properties as fields of your nodes and relationships. To create accessors named for the entity properties, set


Then, when set_property() is used to first create and set a property, accessors will be created on the class:

 $node1->set_property({ flavor => 'strange', spin => -0.5 });
 printf "Quark has flavor %s\n", $node1->flavor;

If your point of reference is the database, rather than the objects, auto-accessors may be confusing, since once the accessor is created for the class, it will exist for all future instances:

 print "Yes I can!\n" if REST::Neo4p::Node->new()->can('flavor');

but there is no fundamental reason why new nodes or relationships must have the property (it is NoSQL, after all). Therefore this is a choice for you to make; the default is no auto-accessors.

Application-level constraints

REST::Neo4p::Constrain provides a flexible means for creating, enforcing, serializing and loading property and relationship constraints on your database through REST::Neo4p. It allows you, for example, to specify "kinds" of nodes based on their properties, constrain properties and the values of properties for those nodes, and then specify allowable relationships between kinds of nodes.

Constraints can be enforced automatically, causing exceptions to be thrown when constraints are violated. Alternatively, you can use validation functions to test properties and relationships, including those already present in the database.

This is a mixin that is not used automatically by REST::Neo4p. For details and examples, see REST::Neo4p::Constrain and REST::Neo4p::Constraint.


 REST::Neo4p->connect( $server )
 $node = REST::Neo4p->get_node_by_id( $id );

Returns false if node $id does not exist in database.

get_nodes_by_label() Neo4j Server Version 2.0
 @nodes = REST::Neo4p->get_nodes_by_label( $label );

Returns false if no nodes with given label in database.

 $relationship = REST::Neo4p->get_relationship_by_id( $id );

Returns false if relationship $id does not exist in database.

 $node_index = REST::Neo4p->get_index_by_name( $name, 'node' );
 $relationship_index = REST::Neo4p->get_index_by_name( $name, 'relationship' );

Returns false if index $name does not exist in database.

 @all_relationship_types = REST::Neo4p->get_relationship_types;
get_indexes(), get_node_indexes(), get_relationship_indexes()
 @all_indexes = REST::Neo4p->get_indexes;
 @node_indexes = REST::Neo4p->get_node_indexes;
 @relationship_indexes = REST::Neo4p->get_relationship_indexes;


REST::Neo4p::Node,REST::Neo4p::Relationship,REST::Neo4p::Index, REST::Neo4p::Query, REST::Neo4p::Path, REST::Neo4p::Batch, REST::Neo4p::Constrain, REST::Neo4p::Constraint.


    Mark A. Jensen
    majensen -at- cpan -dot- org


Copyright (c) 2012 Mark A. Jensen. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.