From 03c76deb60927375e9b35c74a903130930ffddf2 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Fri, 18 Jul 2008 15:21:57 +1000 Subject: Expose all puppet variables as instance member variables of the template wrapper. This helps resolve redmine #1427, by providing a safe mechanism to access variables. * Implement Puppet::Parser::Scope#to_hash, which returns a hash containing all the variable bindings in the current and, optionally, parent scope. * Use that to set instance member variables into Puppet::Parser::Templatewrapper * Report the time taken for variable binding at debug level, to help identify any performance regression that is encountered in the real world. * Rename the @scope and @file members of the template wrapper, to avoid clashing with a scope variable exposed within puppet. Signed-off-by: Daniel Pittman (cherry picked from commit ba220b41e4f509f2632e2664d332e49b20a70ea7) --- lib/puppet/parser/scope.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/puppet/parser/scope.rb') diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index a6e43e7b3..32b127a6b 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -183,6 +183,25 @@ class Puppet::Parser::Scope end end + # Return a hash containing our variables and their values, optionally (and + # by default) including the values defined in our parent. Local values + # shadow parent values. + def to_hash(recursive = true) + if recursive and parent then + target = parent.to_hash(recursive) + end + target ||= Hash.new + @symtable.keys.each { |name| + value = @symtable[name] + if value == :undef then + target.delete(name) + else + target[name] = value + end + } + return target + end + def namespaces @namespaces.dup end -- cgit