From 73556a8c71ee1f847f498a8b9db8ff810902dfee Mon Sep 17 00:00:00 2001 From: luke Date: Tue, 11 Jul 2006 20:17:59 +0000 Subject: Fixing templating so it immediately fails when a variable is not found, as opposed to passing up the method_missing heirarchy, which was causing a nasty memory leak and some kind of weird, long-running search git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1389 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/parser/scope.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 747645cbc..317776055 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -14,6 +14,7 @@ module Puppet::Parser # the scope objects. class TemplateWrapper attr_accessor :scope, :file + include Puppet::Util Puppet::Util.logmethods(self) def initialize(scope, file) @@ -39,14 +40,21 @@ module Puppet::Parser if value = @scope.lookupvar(name.to_s) and value != :undefined and value != "" return value else - info "Could not find value for %s" % name - return "" + # Just throw an error immediately, instead of searching for + # other missingmethod things or whatever. + raise Puppet::ParseError, + "Could not find value for '%s'" % name end end def result - template = ERB.new(File.read(@file)) - template.result(binding) + result = nil + benchmark(:info, "Interpolated template #{@file}") do + template = ERB.new(File.read(@file)) + result = template.result(binding) + end + + result end def to_s @@ -1102,6 +1110,13 @@ module Puppet::Parser end end + # Undefine a variable; only used for testing. + def unsetvar(var) + if @symtable.include?(var) + @symtable.delete(var) + end + end + protected # This method abstracts recursive searching. It accepts the type -- cgit