summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-07-05 16:32:03 -0700
committerLuke Kanies <luke@puppetlabs.com>2011-07-15 11:52:41 -0700
commitbdc0f8716ae8ccb2b2657dfab591afe9589d8902 (patch)
tree6f6b25251f0a581c878b833a90e5b3bab0ac5d11 /lib/puppet/parser
parent9662045bfe551821823b38fe6511e621998aef0b (diff)
downloadpuppet-bdc0f8716ae8ccb2b2657dfab591afe9589d8902.tar.gz
puppet-bdc0f8716ae8ccb2b2657dfab591afe9589d8902.tar.xz
puppet-bdc0f8716ae8ccb2b2657dfab591afe9589d8902.zip
Scope[] now returns nil for undefined variables
Given that we have the 'include?' method, this feature is unnecessary, and it makes sense to convert to more ruby-like behavior. Any code that previously checked whether lookupvar (or the new []) returned :undefined should now check whether 'scope.include?(var)'. Thus, you can have the same behavior, but it takes a bit different code to get it. Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com>
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast/leaf.rb7
-rw-r--r--lib/puppet/parser/resource.rb3
-rw-r--r--lib/puppet/parser/scope.rb12
-rw-r--r--lib/puppet/parser/templatewrapper.rb7
4 files changed, 17 insertions, 12 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 64a197492..3efb52f63 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -124,10 +124,11 @@ class Puppet::Parser::AST
# not include syntactical constructs, like '$' and '{}').
def evaluate(scope)
parsewrap do
- if (var = scope[@value, {:file => file, :line => line}]) == :undefined
- var = :undef
+ if ! scope.include?(@value)
+ :undef
+ else
+ scope[@value, {:file => file, :line => line}]
end
- var
end
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 6b072bd90..56887c357 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -258,7 +258,8 @@ class Puppet::Parser::Resource < Puppet::Resource
def add_backward_compatible_relationship_param(name)
# Skip metaparams for which we get no value.
- return unless val = scope[name.to_s] and val != :undefined
+ return unless scope.include?(name.to_s)
+ val = scope[name.to_s]
# The default case: just set the value
set_parameter(name, val) and return unless @parameters[name]
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 3a87f964b..9d84c7e65 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -57,7 +57,7 @@ class Puppet::Parser::Scope
rescue RuntimeError => e
location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : ''
warning "Could not look up qualified variable '#{name}'; #{e.message}#{location}"
- :undefined
+ nil
end
elsif ephemeral_include?(name) or table.include?(name)
# We can't use "if table[name]" here because the value might be false
@@ -69,7 +69,7 @@ class Puppet::Parser::Scope
elsif parent
parent[name,options.merge(:dynamic => (dynamic || options[:dynamic]))]
else
- :undefined
+ nil
end
end
@@ -92,7 +92,7 @@ class Puppet::Parser::Scope
end
def include?(name)
- self[name] != :undefined
+ ! self[name].nil?
end
# Is the value true? This allows us to control the definition of truth
@@ -244,7 +244,11 @@ class Puppet::Parser::Scope
end
def undef_as(x,v)
- (v == :undefined) ? x : (v == :undef) ? x : v
+ if v.nil? or v == :undef
+ x
+ else
+ v
+ end
end
def qualified_scope(classname)
diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 83d18cc3f..9336e704d 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -25,7 +25,7 @@ class Puppet::Parser::TemplateWrapper
# Should return true if a variable is defined, false if it is not
def has_variable?(name)
- scope[name.to_s, {:file => file, :line => script_line}] != :undefined
+ scope.include?(name.to_s)
end
# Allow templates to access the defined classes
@@ -56,9 +56,8 @@ class Puppet::Parser::TemplateWrapper
# the missing_method definition here until we declare the syntax finally
# dead.
def method_missing(name, *args)
- value = scope[name.to_s, {:file => file,:line => script_line}]
- if value != :undefined
- return value
+ if scope.include?(name.to_s)
+ return scope[name.to_s, {:file => file,:line => script_line}]
else
# Just throw an error immediately, instead of searching for
# other missingmethod things or whatever.