Object::Dependency - maintain a dependency graph
use Object::Dependency; my $graph = Object::Dependency->new() $graph->add($object, @objects_the_first_object_depends_upon) $graph->remove_dependency(@objects_that_are_no_longer_relevant) @objects_without_dependencies = $graph->independent;
This module maintains a simple dependency graph. Items can be added more than once to note additional depenencies. Dependency relationships cannot be removed except by removing objects entirely.
add
We do not currently check for cycles so please be careful!
Items are expected to be objects, but do not have to be. Objects are identified by their refadd() so if you combine objects and other scalers, there is some chance of a collision between large intetgers and the refaddr(). The undef value will cause warnings.
undef
Construction is easy: no parameters are expected.
Adds an item ($object) to the dependency graph and notes which items it depends upon. The same object may be added multiple times so if you want to declare what object depends upon an object, just use add in reverse multiple times.
$object
The @depends_upon_objects are the prerequisites for $object. $object is blocked by its @depends_upon_objects.
Removes the @objects from the dependency graph. All objects dependent on @objects will also be removed.
@objects
Removes the @objects from the dependency graph. Dependencies upon these objects will be considered to be satisfied. Objects that had been dependent upon @objects will no longer be dependent upon them.
Mark that the $object will never be removed from the dependency graph because there is some problem with it. All objects that depend upon $object will now be considered "stuck". Behavior of removing a stuck dependency is not defined.
Returns a list of objects that do not depend upon other objects. Mark the returned objects as active and locked.
Options are:
Return at most COUNT items.
Normally active objects are included in the returned list. With active => 1, active objects are not returned. Yes, this is backwards. Sorry.
active => 1
Locked objects are not included in the returned list. With lock => 1, objects are locked when they are returned.
lock => 1
Normally items that have been marked as "stuck" are not returned. With stuck => 1, stuck objects are returned. Stuck objects are not indpendent of the rest of the graph. This capability is simply to provide a way to find out what is stuck. With stuck => 1, normal independent objects are not returned -- only stuck ones are returned.
stuck => 1
If the graph is not empty but there are no independent objects then there is a loop in the graph and independent() will die. Wrap it in an eval() if you care.
independent()
eval()
Returns true if there are no non-stuck objects in the dependency graph.
Sets the description of the object (if $description is defined).
$description
Returns the description of the object, annotated by it's dependency graph status: LOCKED, INDEPENDENT, ACTIVE, or STUCK.
Special handling is done for Proc::JobQueue::Job and Proc::JobQueue::DependencyTask objects.
Prints/returns the dependency graph (described objects with the dependencies).
Returns true if $object is in the dependency graph.
Proc::JobQueue::DependencyQueue
Copyright (C) 2007-2008 SearchMe, Inc. Copyright (C) 2009-2010 David Muir Sharnoff Copyright (C) 2011-2014 Google, Inc. This package may be used and redistributed under the terms of either the Artistic 2.0 or LGPL 2.1 license.
To install Object::Dependency, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Object::Dependency
CPAN shell
perl -MCPAN -e shell install Object::Dependency
For more information on module installation, please visit the detailed CPAN module installation guide.