NAME
REST::Neo4p::Constraint - Application-level Neo4j Constraints
SYNOPSIS
See REST::Neo4p::Constraint::Property, REST::Neo4p::Constraint::Relationship, REST::Neo4p::Constraint::RelationshipType for examples.
DESCRIPTION
Objects of class REST::Neo4p::Constraint are used to capture and organize REST::Neo4p application level constraints on Neo4j Node and Relationship content.
The REST::Neo4p::Constrain module provides a more convenient factory for REST::Neo4p::Constraint subclasses that specify node property, relationship property, relationship, and relationship type constraints.
FLAGS
$REST::Neo4p::Constraint::STRICT_RELN_TYPES
-
When true, relationships are disallowed if the relationship type does not meet any current relationship type constraint. Default is true.
$REST::Neo4p::Constraint::STRICT_RELN_PROPS
-
When true, relationships are disallowed if their relationship properties do not meet any current relationship property constraint.
Default is false. This is so relationships without properties can be made freely. When relationship property checking is strict, you can allow relationships without properties by setting the following constraint:
create_constraint( tag => 'free_reln_prop', type => 'relationship_property', rtype => '*', condition => 'all', constraints => {} );
METHODS
Class Methods
- new()
-
$reln_pc = REST::Neo4p::Constraint::RelationshipProperty->new($constraints);
Constructor. Construction also registers the constraint for validation. See subclass pod for details.
- get_constraint()
-
$c = REST::Neo4p::Constraint->get_constraint('spiffy_node');
Get a registered constraint by constraint tag. Returns false if none found.
- get_all_constraints()
-
%constraints = REST::Neo4p::Constraint->get_all_constraints();
Get a hash of all registered constraint objects, keyed by constraint tag.
Instance Methods
- tag()
- type()
- condition()
- set_condition()
-
$reln_c->set_condition('only');
Set the group condition for the constraint. See subclass pod for details.
- priority()
- set_priority()
-
$node_pc->set_priority(10);
Constraints with larger priority values are checked before those with smaller values by the
validate_*()
functions. - constraints()
-
Returns the hashref of constraints. Format depends on the subclass.
- add_constraint()
-
$node_pc->add_constraint( 'warning_level' => qr/^[0-9]$/ ); $reln_c->add_constraint( { 'species' => 'genus' } );
Add an individual constraint specification to an existing constraint object. See subclass pod for details.
- remove_constraint()
-
$node_pc->remove_constraint( 'warning_level' ); $reln_c->remove_constraint( { 'genus' => 'species' } );
Remove an individual constraint specification from an existing constraint object. See subclass pod for details.
Functional interface for validation
- validate_properties()
-
validate_properties( $node_object ) validate_properties( $relationship_object ); validate_properties( { name => 'Steve', instrument => 'banjo' } );
- validate_relationship()
-
validate_relationship ( $relationship_object ); validate_relationship ( $node_object1 => $node_object2, $reln_type ); validate_relationship ( { name => 'Steve', instrument => 'banjo' } => { name => 'Marcia', instrument => 'blunt' }, 'avoids' );
- validate_relationship_type()
-
validate_relationship_type( 'avoids' )
Functional interface. Returns the registered constraint object with the highest priority that the argument satisfies, or false if none is satisfied.
These methods can be exported as follows:
use REST::Neo4p::Constraint qw(:validate)
They can also be exported from REST::Neo4p::Constrain:
use REST::Neo4p::Constrain qw(:validate)
Serializing and loading constraints
- serialize_constraints()
-
open $f, ">constraints.json"; print $f serialize_constraints();
Returns a JSON-formatted representation of all currently registered constraints.
- load_constraints()
-
open $f, "constraints.json"; { local $/ = undef; load_constraints(<$f>); }
Creates and registers a list of constraints specified by a JSON string as produced by "serialize_constraints()".
SEE ALSO
REST::Neo4p,REST::Neo4p::Constrain, REST::Neo4p::Constraint::Property, REST::Neo4p::Constraint::Relationship, REST::Neo4p::Constraint::RelationshipType. REST::Neo4p::Node, REST::Neo4p::Relationship,
AUTHOR
Mark A. Jensen
CPAN ID: MAJENSEN
majensen -at- cpan -dot- org
LICENSE
Copyright (c) 2012-2015 Mark A. Jensen. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.