NAME

Data::Hopen::G::GraphBuilder - fluent interface for building graphs

SYNOPSIS

A GraphBuilder wraps a Data::Hopen::G::DAG and a current Data::Hopen::G::Node. It permits building chains of nodes in a fluent way. For example, in an App::hopen hopen file:

    # $Build is a Data::Hopen::G::DAG created by App::hopen
    use language 'C';

    my $builder = $Build->C::compile(file => 'foo.c');
        # Now $builder holds $Build (the DAG) and a node created by
        # C::compile().

ATTRIBUTES

name

An optional name, in case you want to identify your Builder instances.

dag

The current Data::Hopen::G::DAG instance, if any.

node

The current Data::Hopen::G::Node instance, if any.

INSTANCE FUNCTIONS

add

Adds a node to the graph. Returns the node. Note that this does not change the builder's current node ("node").

default_goal

Links the most recent node in the chain to the default goal in the DAG. If the DAG does not have a default goal, adds one called "all".

As a side effect, calling this function clears the builder's record of the current node and returns undef. The idea is that this function will be used at the end of a chain of calls. Clearing state in this way reduces the chance of unintentionally connecting nodes.

goal

Links the most recent node in the chain to the given goal in the DAG. Clears the builder's record of the current node and returns undef.

to

Connect one node to another, where both are wrapped in GraphBuilders. Usage:

    $builder_1->to($builder_2);
        # No $builder_1->node has an edge to $builder_2->node

Returns undef, because chaining would be ambiguous. For example, in the snippet above, would the chain continue from $builder_1 or $builder_2?

Does not change the state of either GraphBuilder.

STATIC FUNCTIONS

make_GraphBuilder

Given the name of a subroutine, wrap the given subroutine for use in a GraphBuilder chain such as that shown in the "SYNOPSIS". Usage:

    sub worker {
        my $graphbuilder = shift;
        ...
        return $node;   # Will automatically be linked into the chain
    }

    make_GraphBuilder 'worker';
        # now worker can take a DAG or GraphBuilder, and the
        # return value will be the GraphBuilder.

The worker subroutine is called in scalar context.