Hopen/G/DAG.pm

filter: Statementstmt 100% 185 / 185 Branchbran 96.6% 58 / 60 Conditioncond 85.7% 6 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 33 / 33 Podpod 100% 6 / 6 totaltotal 98.3% 290 / 295 CC 39 SCAR 21.5
CC
39
Cov
99%
_run
22.0
connect
6.0
init
5.0
CRAP 8.6
« Hopen/G/GraphBuilder.pm ↑ Summary Hopen/Util/Data.pm »
1 # Data::Hopen::G::DAG - hopen build graph
2 package Data::Hopen::G::DAG;
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use Data::Hopen::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 our $VERSION = '0.000021';
7  
8 9 ▶use parent 'Data::Hopen::G::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Class::Tiny {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶ goals => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
11 9 default_goal => undef,
12 winner => undef,
13  
14 # Private attributes with simple defaults
15 #_node_by_name => sub { +{} }, # map from node names to nodes in either
16 # # _init_graph or _graph
17  
18 # Private attributes - initialized by BUILD()
19 _graph => undef, # L<Data::Hopen::OrderedPredecessorGraph> instance
20 _final => undef, # The graph sink - all goals have edges to this
21  
22 #Initialization operations
23 _init_graph => undef, # L<Data::Hopen::OrderedPredecessorGraph>
24 # for initializations
25 _init_first => undef, # Graph node for initialization - the first
26 # init operation to be performed.
27  
28 # TODO? also support fini to run operations after _graph runs?
29 9 };
30  
31 9 ▶use Data::Hopen qw(hlog getparameters *QUIET);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 ▶use Data::Hopen::G::Goal;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use Data::Hopen::G::Link;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use Data::Hopen::G::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 9 ▶use Data::Hopen::G::CollectOp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 9 ▶use Data::Hopen::Util::Data qw(forward_opts);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 9 ▶use Data::Hopen::OrderedPredecessorGraph;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 9 ▶use Getargs::Mixed; # parameters, which doesn't permit undef
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use Hash::Merge;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 9 ▶use Regexp::Assemble;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 9 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 9 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 # Class data {{{1
45  
46 9 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
47 9 LINKS => 'link_list', # Graph edge attr: array of DHG::Link instances
48 9 };
49  
50 # A counter used for making unique names
51 9 my $_id_counter = 0; # threads: make shared
52  
53 # }}}1
54 # Docs {{{1
55  
56 =head1 NAME
57  
58 Data::Hopen::G::DAG - A hopen build graph
59  
60 =head1 SYNOPSIS
61  
62 This class encapsulates the DAG for a particular set of one or more goals.
63 It is itself a L<Data::Hopen::G::Op> so that it can be composed into
64 other DAGs.
65  
66 =head1 ATTRIBUTES
67  
68 =head2 goals
69  
70 Arrayref of the goals for this DAG.
71  
72 =head2 default_goal
73  
74 The default goal for this DAG.
75  
76 =head2 winner
77  
78 When a node has multiple predecessors, their outputs are combined using
79 L<Hash::Merge> to form the input to that node. This sets the C<Hash::Merge>
80 precedence. Valid values (case-insensitive) are:
81  
82 =over
83  
84 =item C<undef> or C<'combine'>
85  
86 (the default): L<Hash::Merge/Retainment Precedence>. Same-name keys
87 are merged, so no data is lost.
88  
89 =item C<'first'> or C<'keep'>
90  
91 L<Hash::Merge/Left Precedence>. The first predecessor to add a value
92 under a particular key will win.
93  
94 =item C<'last'> or C<'replace'>
95  
96 L<Hash::Merge/Right Precedence>. The last predecessor to add a value
97 under a particular key will win.
98  
99 =back
100  
101 =head2 _graph
102  
103 The actual L<Graph>. If you find that you have to use it, please open an
104 issue so we can see about providing a documented API for your use case!
105  
106 =head2 _final
107  
108 The node to which all goals are connected.
109  
110 =head2 _init_graph
111  
112 A separate L<Graph> of operations that will run before all the operations
113 in L</_graph>. This is because I don't want to add an edge to every
114 single node just to force the topological sort to work out.
115  
116 =head2 _init_first
117  
118 The first node to be run in _init_graph.
119  
120 =head1 FUNCTIONS
121  
122 =cut
123  
124 # }}}1
125  
126 =head2 _run
127  
128 Traverses the graph. The DAG is similar to a subroutine in this respect. The
129 outputs from all the goals of the DAG are aggregated and provided as the
130 outputs of the DAG. The output is a hash keyed by the name of each goal, with
131 each goal's outputs as the values under that name. Usage:
132  
133 my $hrOutputs = $dag->run([-context=>$scope][, other options])
134  
135 C<$scope> must be a L<Data::Hopen::Scope> or subclass if provided.
136 Other options are as L<Data::Hopen::G::Runnable/run>.
137  
138 When evaluating a node, the edges from its predecessors are traversed in
139 the order those predecessors were added to the graph.
140  
141 =cut
142  
143 # The implementation of run(). $self->scope has already been linked to the context.
144 30 ▶sub _run {
Subroutine _run: called CC=22 SCAR=30.9
145 30 my ($self, %args) = getparameters('self', [qw(; visitor)], @_);
146 30 my $retval = {};
147  
148 # --- Get the initialization ops ---
149  
150 30 my @init_order = eval { $self->_init_graph->toposort };
151 30 ▶ die "Initializations contain a cycle!" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 29 30
152 29 ▶ @init_order = () if $self->_init_graph->vertices == 1; # no init nodes => skip
Branch: 1 branch
BranchTrueFalseTotal
if $self->_init_graph->vertices == 1 28 1 29
153  
154 # --- Get the runtime ops ---
155  
156 29 my @order = eval { $self->_graph->toposort };
157 # TODO someday support multi-core-friendly topo-sort, so nodes can run
158 # in parallel until they block each other.
159 29 ▶ die "Graph contains a cycle!" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 28 29
160  
161 # Remove _final from the order for now - I don't yet know what it means
162 # to traverse _final.
163 28 ▶ warn "Last item in order isn't _final! This might indicate a bug in hopen, or that some graph edges are missing."
Branch: 1 branch
BranchTrueFalseTotal
unless $Data::Hopen::G::DAG::QUIET or builtin::refaddr($order[$#order]) == builtin::refaddr($self->_final) 0 28 28
Condition66%2/3
$Data::Hopen::G::DAG::QUIET or builtin::refaddr($order[$#order]) == builtin::refaddr($self->_final)
l!l&&r!l&&!r
1270
MC/DC0%0/2
$Data::Hopen::G::DAG::QUIET or builtin::refaddr($order[$#order]) == builtin::refaddr($self->_final)
$Data::Hopen::G::DAG::QUIET builtin::refaddr($order[$#order]) == builtin::refaddr($self->_final)
Truth table66%2/3
A or B
A= $Data::Hopen::G::DAG::QUIETB= builtin::refaddr($order[$#order]) == builtin::refaddr($self->_final)
ABresult
1X1
011
000
164 unless $QUIET or refaddr $order[$#order] == refaddr $self->_final;
165  
166 28 @order = grep { refaddr $_ != refaddr $self->_final } @order;
167  
168 # --- Check for non-connected ops, and goals with no inputs ---
169  
170 28 ▶ unless($QUIET) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Data::Hopen::G::DAG::QUIET) 27 1 28
171 27 foreach my $node ($self->_graph->isolated_vertices) {
172 1 warn "Node @{[$node->name]} is not connected to any other nodes";
173 }
174  
175 27 foreach my $goal (@{$self->goals}) {
176 27 ▶ warn "Goal @{[$goal->name]} has no inputs"
Branch: 1 branch
BranchTrueFalseTotal
if $self->_graph->is_predecessorless_vertex($goal) 1 26 27
177 if $self->_graph->is_predecessorless_vertex($goal);
178 }
179 }
180  
181 # --- Set up for the merge ---
182  
183 28 state $STRATEGIES = { # regex => strategy
184 '(<undef>|combine)' => 'combine',
185 '(first|keep)' => 'keep',
186 '(last|replace)' => 'replace',
187 };
188 28 state $STRATEGY_MAP = Regexp::Assemble->new->flags('i')->track(1)
189 ->anchor_string_begin->anchor_string_end
190 ->add(keys %$STRATEGIES);
191  
192 28 ▶ my $merge_strategy_idx = $STRATEGY_MAP->match($self->winner // '<undef>');
Condition100%2/2
$self->winner // "<undef>"
l!l
1513
MC/DC100%1/1
$self->winner // "<undef>"
$self->winner
Truth table100%2/2
A
A= $self->winner
Aresult
11
00
193 28 ▶ die "Invalid winner value @{[$self->winner]}" unless defined $merge_strategy_idx;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $merge_strategy_idx 5 23 28
194 23 my $merge_strategy = $STRATEGIES->{$merge_strategy_idx};
195  
196 # --- Traverse ---
197  
198 # Note: while hacking, please make sure Goal nodes can appear
199 # anywhere in the graph.
200  
201 23 ▶ hlog { my $x = 'Traversing DAG ' . $self->name; $x, '*' x (76-length($x)) };
Subroutine __ANON__: called CC=1 SCAR=0.0
202  
203 23 my $graph = $self->_init_graph;
204 23 foreach my $node (@init_order, undef, @order) {
205  
206 84 ▶ if(!defined($node)) { # undef is the marker between init and run
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $node) 23 61 84
207 23 $graph = $self->_graph;
208 23 next;
209 }
210  
211 # Inputs to this node. These are different from the DAG's inputs.
212 # The scope stack is (outer to inner) DAG's inputs, DAG's overrides,
213 # then $node_inputs, then the individual node's overrides.
214 61 my $node_inputs = Data::Hopen::Scope::Hash->new;
215 # TODO make this a DH::Scope::Inputs once it's implemented
216 61 $node_inputs->outer($self->scope);
217 # Data specifically being provided to the current node, e.g.,
218 # on input edges, beats the scope of the DAG as a whole.
219 61 $node_inputs->local(true);
220 # A CollectOp won't reach above the node's inputs by default.
221 61 $node_inputs->merge_strategy($merge_strategy);
222  
223 # Iterate over each node's edges and process any Links
224 61 foreach my $pred ($graph->ordered_predecessors($node)) {
225 35 ▶ hlog { ('From', $pred->name, 'to', $node->name) };
Subroutine __ANON__: called CC=1 SCAR=0.0
226  
227 # Goals do not feed outputs to other Goals. This is so you can
228 # add edges between Goals to set their order while keeping the
229 # data for each Goal separate.
230 # TODO add tests for this. Also TODO decide whether this is
231 # actually the Right Thing!
232 35 ▶ next if eval { $pred->DOES('Data::Hopen::G::Goal') };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $pred->DOES("Data::Hopen::G::Goal") } } 0 35 35
233  
234 35 my $links = $graph->get_edge_attribute($pred, $node, LINKS);
235  
236 # Simple case (no links): predecessor's outputs become our inputs
237 35 ▶ unless($links) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($links) 27 8 35
238 27 ▶ hlog { ' -- no links' };
Subroutine __ANON__: called CC=1 SCAR=0.0
239 27 $node_inputs->merge(%{$pred->outputs});
240 # TODO specify which set these are.
241 # Use the predecessor's identity as the set.
242 27 next;
243 }
244  
245 # More complex case: Process all the links
246  
247 # Helper function to wrap a hashref in the right scope for a link input
248 19 ▶ local *make_link_inputs = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
249 19 my $hrIn = shift;
250 19 my $scLinkInputs = Data::Hopen::Scope::Hash->new->put(%$hrIn);
251 # All links get the same outer scope --- they are parallel,
252 # not in series.
253 # TODO? use the predecessor's identity as the set.
254 19 $scLinkInputs->outer($self->scope);
255 # The links run at the same scope level as the node.
256 19 $scLinkInputs->local(true);
257 19 return $scLinkInputs;
258 8 };
259  
260 # Make the first link's input scope
261 8 my $hrPredOutputs = $pred->outputs;
262 # In one test, outputs was undef if not on its own line.
263 8 my $scLinkInputs = make_link_inputs($hrPredOutputs);
264  
265 # Run the links in series - not parallel!
266 8 my $hrLinkOutputs = $scLinkInputs->as_hashref(-levels=>'local');
267 8 foreach my $link (@$links) {
268 11 ▶ hlog { ('From', $pred->name, 'via', $link->name, 'to', $node->name) };
Subroutine __ANON__: called CC=1 SCAR=0.0
269  
270 11 $hrLinkOutputs = $link->run(
271 -context=>$scLinkInputs,
272 # visitor not passed to links.
273 );
274 11 $scLinkInputs = make_link_inputs($hrLinkOutputs);
275 } #foreach incoming link
276  
277 8 $node_inputs->merge(%$hrLinkOutputs);
278 # TODO specify which set these are.
279  
280 } #foreach predecessor node
281  
282 61 my $step_output = $node->run(-context=>$node_inputs,
283 forward_opts(\%args, {'-'=>1}, 'visitor')
284 );
285 61 $node->outputs($step_output);
286  
287 # Give the visitor a chance, and stash the results if necessary.
288 61 ▶ if(eval { $node->DOES('Data::Hopen::G::Goal') }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $node->DOES('Data::Hopen::G::Goal') } }) { } 23 38 61
289 23 ▶ $args{visitor}->visit_goal($node, $node_inputs) if $args{visitor};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"visitor"} 1 22 23
290  
291 # Save the result if there is one. Don't save {}.
292 # use $node->outputs, not $step_output, since the visitor may
293 # alter $node->outputs.
294 23 ▶ $retval->{$node->name} = $node->outputs if keys %{$node->outputs};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$node->outputs;} 20 3 23
295 } else {
296 38 ▶ $args{visitor}->visit_node($node, $node_inputs) if $args{visitor};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"visitor"} 1 37 38
297 }
298  
299 47 ▶ hlog { 'Finished node', $node->name, 'with outputs',
Subroutine __ANON__: called CC=1 SCAR=0.0
300 61 Dumper $node->outputs } 10;
301  
302 } #foreach node in topo-sort order
303  
304 23 return $retval;
305 } #run()
306  
307 =head1 ADDING DATA
308  
309 =head2 goal
310  
311 Creates a goal of the DAG. Goals are names for sequences of operations,
312 akin to top-level Makefile targets. Usage:
313  
314 my $goalOp = $dag->goal('name')
315  
316 Returns the L<Data::Hopen::G::Goal> node that is the goal. By default, any
317 inputs passed into a goal are provided as outputs of that goal, and are
318 saved as outputs of the DAG under the goal's name.
319  
320 The first call to C<goal()> also sets L</default_goal>.
321  
322 =cut
323  
324 17 ▶sub goal {
Subroutine goal: called CC=4 SCAR=13.9
Pod documented
325 17 ▶ my $self = shift or croak 'Need an instance';
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Need an instance") 16 1 17
326 16 ▶ my $name = shift or croak 'Need a goal name';
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift() or croak("Need a goal name") 15 1 16
327 15 my $goal = Data::Hopen::G::Goal->new(name => $name);
328 15 $self->_graph->add_vertex($goal);
329 #$self->_node_by_name->{$name} = $goal;
330 15 $self->_graph->add_edge($goal, $self->_final);
331 15 ▶ $self->default_goal($goal) unless $self->default_goal;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->default_goal 14 1 15
332 15 push @{$self->goals}, $goal;
333 15 return $goal;
334 } #goal()
335  
336 =head2 connect
337  
338 =over 4
339  
340 =item - C<< DAG:connect(<op1>, <out-edge>, <in-edge>, <op2>) >>
341  
342 B<Not yet implemented>.
343 Connects output C<out-edge> of operation C<op1> as input C<in-edge> of
344 operation C<op2>. No processing is done between output and input.
345 C<out-edge> and C<in-edge> can be anything usable as a table index, provided
346 that table index appears in the corresponding operation's descriptor.
347  
348 =item - C<< DAG:connect(<op1>, <op2>) >>
349  
350 Creates a dependency edge from C<op1> to C<op2>, indicating that C<op1> must be
351 run before C<op2>. Does not transfer any data from C<op1> to C<op2>.
352  
353 =item - C<< DAG:connect(<op1>, <Link>, <op2>) >>
354  
355 Connects C<op1> to C<op2> via L<Data::Hopen::G::Link> C<Link>.
356 C<Link> may be undef, in which case this is treated as the two-parameter form.
357  
358 If there are already link(s) on the edge from C<op1> to C<op2>, the new link
359 is added after the last existing link.
360  
361 =back
362  
363 TODO return the name of the edge? The edge instance itself? Maybe a
364 fluent interface to the DAG for chaining C<connect> calls?
365  
366 TODO remove the out-edge and in-edge parameters?
367  
368 =cut
369  
370 21 ▶sub connect {
Subroutine connect: called CC=6 SCAR=17.9
Pod documented
371 21 ▶ my $self = shift or croak 'Need an instance';
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Need an instance") 20 1 21
372 20 my ($op1, $out_edge, $in_edge, $op2, $link);
373  
374 # Unpack args
375 #if(@_ == 4) {
376 # ($op2, $out_edge, $in_edge, $op2) = @_;
377 #} else the following
378 20 ▶ if(@_ == 3) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 3) { } 12 8 20
elsif (@_ == 2) { } 5 3 8
379 12 ($op1, $link, $op2) = @_;
380 } elsif(@_ == 2) {
381 5 ($op1, $op2) = @_;
382 } else {
383 3 die "Invalid arguments";
384 }
385  
386 #my $out_edge = false; # No outputs TODO use these?
387 #my $in_edge = false; # No inputs
388  
389 13 ▶ hlog { 'DAG::connect(): Edge from', $op1->name,
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$link ? : 9 4 13
390 'via', $link ? $link->name : '(no link)',
391 17 'to', $op2->name };
392  
393 # Add it to the graph (idempotent)
394 17 $self->_graph->add_edge($op1, $op2);
395 # $self->_node_by_name->{$_->name} = $_ foreach ($op1, $op2);
396  
397 # Save the DHG::Link as an edge attribute (not idempotent!)
398 17 ▶ if($link) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link) 11 6 17
399 11 ▶ my $attrs = $self->_graph->get_edge_attribute($op1, $op2, LINKS) || [];
Condition100%2/2
$self->_graph->get_edge_attribute($op1, $op2, 'link_list') || []
l!l
38
MC/DC100%1/1
$self->_graph->get_edge_attribute($op1, $op2, 'link_list') || []
$self->_graph->get_edge_attribute($op1, $op2, 'link_list')
Truth table100%2/2
A
A= $self->_graph->get_edge_attribute($op1, $op2, 'link_list')
Aresult
11
00
400 11 push @$attrs, $link;
401 11 $self->_graph->set_edge_attribute($op1, $op2, LINKS, $attrs);
402 }
403  
404 17 return undef; # TODO decide what to return
405 } #connect()
406  
407 =head2 add
408  
409 Add a regular node to the graph. An attempt to add the same node twice will be
410 ignored. Usage:
411  
412 my $node = Data::Hopen::G::Op->new(name=>"whatever");
413 $dag->add($node);
414  
415 Returns the node, for the sake of chaining.
416  
417 =cut
418  
419 4 ▶sub add {
Subroutine add: called CC=2 SCAR=6.9
Pod documented
420 4 my ($self, undef, $node) = parameters('self', ['node'], @_);
421 2 ▶ return if $self->_graph->has_vertex($node);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_graph->has_vertex($node) 1 1 2
422 1 ▶ hlog { __PACKAGE__, $self->name, 'adding', Dumper($node) } 2;
Subroutine __ANON__: called CC=1 SCAR=0.0
423  
424 1 $self->_graph->add_vertex($node);
425 #$self->_node_by_name->{$node->name} = $node if $node->name;
426  
427 1 return $node;
428 } #add()
429  
430 =head2 init
431  
432 Add an initialization operation to the graph. Initialization operations run
433 before all other operations. An attempt to add the same initialization
434 operation twice will be ignored. Usage:
435  
436 my $op = Data::Hopen::G::Op->new(name=>"whatever");
437 $dag->init($op[, $first]);
438  
439 If C<$first> is truthy, the op will be run before anything already in the
440 graph. However, later calls to C<init()> with C<$first> set will push
441 operations even before C<$op>.
442  
443 Returns the node, for the sake of chaining.
444  
445 =cut
446  
447 6 ▶sub init {
Subroutine init: called CC=5 SCAR=16.1
Pod documented
448 6 ▶ my $self = shift or croak 'Need an instance';
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Need an instance") 5 1 6
449 5 ▶ my $op = shift or croak 'Need an op';
Branch: 1 branch
BranchTrueFalseTotal
my $op = shift() or croak("Need an op") 4 1 5
450 4 my $first = shift;
451 4 ▶ return if $self->_init_graph->has_vertex($op);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_init_graph->has_vertex($op) 1 3 4
452  
453 3 $self->_init_graph->add_vertex($op);
454 #$self->_node_by_name->{$op->name} = $op;
455  
456 3 ▶ if($first) { # $op becomes the new _init_first node
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 1 2 3
457 1 $self->_init_graph->add_edge($op, $self->_init_first);
458 1 $self->_init_first($op);
459 } else { # Not first, so can happen anytime. Add it after the
460 # current first node.
461 2 $self->_init_graph->add_edge($self->_init_first, $op);
462 }
463  
464 3 return $op;
465 } #init()
466  
467 =head1 ACCESSORS
468  
469 =head2 empty
470  
471 Returns truthy if the only nodes in the graph are internal nodes.
472 Intended for use by hopen files.
473  
474 =cut
475  
476 3 ▶sub empty {
Subroutine empty: called CC=2 SCAR=6.9
Pod documented
477 3 ▶ my $self = shift or croak 'Need an instance';
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Need an instance") 2 1 3
478 2 return ($self->_graph->vertices == 1);
479 # _final is the node in an empty() graph.
480 # We don't check the _init_graph since empty() is intended
481 # for use by hopen files, not toolsets.
482 } #empty()
483  
484 =head1 OTHER
485  
486 =head2 BUILD
487  
488 Initialize the instance.
489  
490 =cut
491  
492 17 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod documented
493 #use Data::Dumper;
494 #say Dumper(\@_);
495 17 ▶ my $self = shift or croak 'Need an instance';
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Need an instance") 16 1 17
496 16 my $hrArgs = shift;
497  
498 # DAGs always have names
499 16 ▶ $self->name('__R_DAG_' . $_id_counter++) unless $self->has_custom_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_custom_name 1 15 16
500  
501 # Graph of normal operations
502 16 my $graph = Data::Hopen::OrderedPredecessorGraph->new( directed => true,
503 refvertexed => true);
504 16 my $final = Data::Hopen::G::Node->new(
505 name => '__R_DAG_ROOT' . $_id_counter++);
506 16 $graph->add_vertex($final);
507 16 $self->_graph($graph);
508 16 $self->_final($final);
509  
510 # Graph of initialization operations
511 16 my $init_graph = Data::Hopen::OrderedPredecessorGraph->new( directed => true,
512 refvertexed => true);
513 16 my $init = Data::Hopen::G::CollectOp->new(
514 name => '__R_DAG_INIT' . $_id_counter++);
515 16 $init_graph->add_vertex($init);
516  
517 16 $self->_init_graph($init_graph);
518 16 $self->_init_first($init);
519 } #BUILD()
520  
521 9 1;
522 # Rest of the docs {{{1
523 __END__
« Hopen/G/GraphBuilder.pm ↑ Summary Hopen/Util/Data.pm »