1
# Created by Luke Kanies on 2006-11-16.
2
# Copyright (c) 2006. All rights reserved.
5
require 'puppet/pgraph'
7
# A module that handles the small amount of graph stuff in Puppet.
8
module Puppet::Util::Graph
9
# Make a graph where each of our children gets converted to
10
# the receiving end of an edge. Call the same thing on all
11
# of our children, optionally using a block
12
def to_graph(graph = nil, &block)
13
# Allow our calling function to send in a graph, so that we
14
# can call this recursively with one graph.
15
graph ||= Puppet::PGraph.new
18
unless block_given? and ! yield(child)
19
graph.add_edge(self, child)
21
if child.respond_to?(:to_graph)
22
child.to_graph(graph, &block)
27
# Do a topsort, which will throw an exception if the graph is cyclic.