# File lib/puppet/parser/ast/hostclass.rb, line 41
41:     def evaluate_code(resource)
42:         scope = resource.scope
43:         # Verify that we haven't already been evaluated.  This is
44:         # what provides the singleton aspect.
45:         if existing_scope = scope.compiler.class_scope(self)
46:             Puppet.debug "Class '%s' already evaluated; not evaluating again" % (classname == "" ? "main" : classname)
47:             return nil
48:         end
49: 
50:         pnames = nil
51:         if pklass = self.parentobj
52:             parent_resource = resource.scope.compiler.catalog.resource(self.class.name, pklass.classname)
53:             # This shouldn't evaluate if the class has already been evaluated.
54:             pklass.evaluate_code(parent_resource)
55: 
56:             scope = parent_scope(scope, pklass)
57:             pnames = scope.namespaces
58:         end
59: 
60:         # Don't create a subscope for the top-level class, since it already
61:         # has its own scope.
62:         unless resource.title == :main
63:             scope = subscope(scope, resource)
64: 
65:             scope.setvar("title", resource.title)
66:             scope.setvar("name", resource.name)
67:         end
68: 
69:         # Add the parent scope namespaces to our own.
70:         if pnames
71:             pnames.each do |ns|
72:                 scope.add_namespace(ns)
73:             end
74:         end
75: 
76:         # Set the class before we evaluate the code, so that it's set during
77:         # the evaluation and can be inspected.
78:         scope.compiler.class_set(self.classname, scope)
79: 
80:         # Now evaluate our code, yo.
81:         if self.code
82:             return self.code.safeevaluate(scope)
83:         else
84:             return nil
85:         end
86:     end