The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Hopen::G::DAG - A hopen build graph

SYNOPSIS

This class encapsulates the DAG for a particular set of one or more goals. It is itself a Data::Hopen::G::Op so that it can be composed into other DAGs.

ATTRIBUTES

goals

Arrayref of the goals for this DAG.

default_goal

The default goal for this DAG.

winner

When a node has multiple predecessors, their outputs are combined using Hash::Merge to form the input to that node. This sets the Hash::Merge precedence. Valid values (case-insensitive) are:

undef

(the default): "Retainment Precedence" in Hash::Merge. Same-name keys are merged, so no data is lost.

_graph

The actual Graph. If you find that you have to use it, please open an issue so we can see about providing a documented API for your use case!

_final

The node to which all goals are connected.

_init_graph

A separate Graph of operations that will run before all the operations in "_graph". This is because I don't want to add an edge to every single node just to force the topological sort to work out.

_init_first

The first node to be run in _init_graph.

FUNCTIONS

_run

Traverses the graph. The DAG is similar to a subroutine in this respect. The outputs from all the goals of the DAG are aggregated and provided as the outputs of the DAG. The output is a hash keyed by the name of each goal, with each goal's outputs as the values under that name. Usage:

    my $hrOutputs = $dag->run([-context=>$scope][, other options])

$scope must be a Data::Hopen::Scope or subclass if provided. Other options are as "run" in Data::Hopen::Runnable.

When evaluating a node, the edges from its predecessors are traversed in the order those predecessors were added to the graph.

ADDING DATA

goal

Creates a goal of the DAG. Goals are names for sequences of operations, akin to top-level Makefile targets. Usage:

    my $goalOp = $dag->goal('name')

Returns the Data::Hopen::G::Goal node that is the goal. By default, any inputs passed into a goal are provided as outputs of that goal, and are saved as outputs of the DAG under the goal's name.

The first call to goal() also sets "default_goal".

connect

   - C<DAG:connect(<op1>, <out-edge>, <in-edge>, <op2>)>:
     connects output C<< out-edge >> of operation C<< op1 >> as input C<< in-edge >> of
     operation C<< op2 >>.  No processing is done between output and input.
     - C<< out-edge >> and C<< in-edge >> can be anything usable as a table index,
       provided that table index appears in the corresponding operation's
       descriptor.
   - C<DAG:connect(<op1>, <op2>)>: creates a dependency edge from C<< op1 >> to
     C<< op2 >>, indicating that C<< op1 >> must be run before C<< op2 >>.
     Does not transfer any data from C<< op1 >> to C<< op2 >>.
   - C<DAG:connect(<op1>, <Link>, <op2>)>: Connects C<< op1 >> to
     C<< op2 >> via L<Data::Hopen::G::Link> C<< Link >>.

TODO return the name of the edge? The edge instance itself? Maybe a fluent interface to the DAG for chaining connect calls?

add

Add a regular node to the graph. An attempt to add the same node twice will be ignored. Usage:

    my $node = Data::Hopen::G::Op->new(name=>"whatever");
    $dag->add($node);

Returns the node, for the sake of chaining.

init

Add an initialization operation to the graph. Initialization operations run before all other operations. An attempt to add the same initialization operation twice will be ignored. Usage:

    my $op = Data::Hopen::G::Op->new(name=>"whatever");
    $dag->init($op[, $first]);

If $first is truthy, the op will be run before anything already in the graph. However, later calls to init() with $first set will push operations even before $op.

Returns the node, for the sake of chaining.

ACCESSORS

empty

Returns truthy if the only nodes in the graph are internal nodes. Intended for use by hopen files.

OTHER

BUILD

Initialize the instance.

IMPLEMENTATION

Each DAG has a hidden "_final" node. All outputs have edges from the _final node. The traversal order is reverse topological from the root node, but is not constrained beyond that.

The DAG is built backwards from the outputs toward the inputs, although calls to "output" and "connect" can appear in any order as long as everything is hooked in before the DAG is run.

The following is TODO:

   - C<DAG::inject(<op1>,<op2>[, after/before'])>: Returns an operation that
     lives on the edge between C<op1> and C<op2>.  If the third parameter is
     false, C<'before'>, or omitted, the new operation will be the first
     operation on that edge.  If the third parameter is true or C<'after'>,
     the new operation will be the last operation on that edge.  Any number
     of operations can be injected on any edge.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 87:

=over should be: '=over' or '=over positive_number'

Around line 92:

=over should be: '=over' or '=over positive_number'

Around line 99:

You forgot a '=back' before '=head2'

You forgot a '=back' before '=head2'