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

NAME

Build::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 Build::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.

_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(-scope=>$scope[, other options])

$scope is required, and must be a Build::Hopen::Scope or subclass. Other options are as "run" in Build::Hopen::Runnable.

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 a passthrough operation representing the goal. Any inputs passed into that operation are provided as outputs of the DAG under the corresponding name.

     TODO integrate
     A C<hopen> file with no C<main:goal()> calls will result in nothing
     happening when C<hopen> is run.

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<Build::Hopen::G::Link> C<< Link >>.

Returns 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 = Build::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 = Build::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 "root" node. All outputs have edges from the root node. The traversal order is reverse topological from the root node, but is not constrained beyond that. Generators can ask for the nodes in root-first or root-last order.

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

The following is in flux:

 - C<DAG>: A class representing a DAG.  An instance called C<main> represents
   what will be generated.

   - C<DAG:set_default(<goal>)>: make C<< goal >> the default goal of this DAG
     (default target).
   - 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.