summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/scope.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-10-24 15:37:31 -0700
committerNick Lewis <nick@puppetlabs.com>2011-04-12 12:47:32 -0700
commitd7201ed38929f867d31bc9b916e90679606dc9f8 (patch)
tree17c753ee074b7d86fa5fd0490af9a77381b79ac1 /lib/puppet/parser/scope.rb
parent10230cfc28e77dde127c157b7238fee2fc378969 (diff)
downloadpuppet-d7201ed38929f867d31bc9b916e90679606dc9f8.tar.gz
puppet-d7201ed38929f867d31bc9b916e90679606dc9f8.tar.xz
puppet-d7201ed38929f867d31bc9b916e90679606dc9f8.zip
Refactor for 5027 -- get rid of lookup_qualified_var
Scope#lookup_qualified_var was a "magic bag" that took a qualified variable name apart and called back in to lookupvar with a new scope. This commit is a semantically neutral refactor that replaces it with a function to find the desired scope as a pure function (with error detection).
Diffstat (limited to 'lib/puppet/parser/scope.rb')
-rw-r--r--lib/puppet/parser/scope.rb29
1 files changed, 12 insertions, 17 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index f7a0134fc..95b765b52 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -214,30 +214,25 @@ class Puppet::Parser::Scope
(v == :undefined) ? x : (v == :undef) ? x : v
end
- def lookup_qualified_var(name)
- parts = name.split(/::/)
- shortname = parts.pop
- klassname = parts.join("::")
- klass = find_hostclass(klassname)
- unless klass
- warning "Could not look up qualified variable '#{name}'; class #{klassname} could not be found"
- return :undefined
- end
- unless kscope = class_scope(klass)
- warning "Could not look up qualified variable '#{name}'; class #{klassname} has not been evaluated"
- return :undefined
- end
- kscope.lookupvar(shortname)
+ def qualified_scope(classname)
+ raise "class #{classname} could not be found" unless klass = find_hostclass(classname)
+ raise "class #{classname} has not been evaluated" unless kscope = class_scope(klass)
+ kscope
end
- private :lookup_qualified_var
+ private :qualified_scope
# Look up a variable. The simplest value search we do.
def lookupvar(name)
table = ephemeral?(name) ? @ephemeral.last : @symtable
# If the variable is qualified, then find the specified scope and look the variable up there instead.
- if name =~ /::/
- lookup_qualified_var(name)
+ if name =~ /^(.*)::(.+)$/
+ begin
+ qualified_scope($1).lookupvar($2)
+ rescue RuntimeError => e
+ warning "Could not look up qualified variable '#{name}'; #{e.message}"
+ :undefined
+ end
elsif ephemeral_include?(name) or table.include?(name)
# We can't use "if table[name]" here because the value might be false
table[name]