diff options
| -rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/parser/resource.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 12 | ||||
| -rw-r--r-- | lib/puppet/parser/templatewrapper.rb | 7 | ||||
| -rwxr-xr-x | spec/unit/parser/scope_spec.rb | 32 | ||||
| -rwxr-xr-x | test/language/scope.rb | 4 |
6 files changed, 35 insertions, 30 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. diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index d3ea8dfa8..3c0d15cd7 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -88,8 +88,8 @@ describe Puppet::Parser::Scope do @scope.lookupvar("var").should == "yep" end - it "should return ':undefined' for unset variables" do - @scope["var"].should == :undefined + it "should return nil for unset variables" do + @scope["var"].should be_nil end it "should be able to look up values" do @@ -180,32 +180,32 @@ describe Puppet::Parser::Scope do @scope["other::deep::klass::var"].should == "otherval" end - it "should return ':undefined' for qualified variables that cannot be found in other classes" do + it "should return nil for qualified variables that cannot be found in other classes" do other_scope = create_class_scope("other::deep::klass") - @scope["other::deep::klass::var"].should == :undefined + @scope["other::deep::klass::var"].should be_nil end - it "should warn and return ':undefined' for qualified variables whose classes have not been evaluated" do + it "should warn and return nil for qualified variables whose classes have not been evaluated" do klass = newclass("other::deep::klass") @scope.expects(:warning) - @scope["other::deep::klass::var"].should == :undefined + @scope["other::deep::klass::var"].should be_nil end - it "should warn and return ':undefined' for qualified variables whose classes do not exist" do + it "should warn and return nil for qualified variables whose classes do not exist" do @scope.expects(:warning) - @scope["other::deep::klass::var"].should == :undefined + @scope["other::deep::klass::var"].should be_nil end - it "should return ':undefined' when asked for a non-string qualified variable from a class that does not exist" do + it "should return nil when asked for a non-string qualified variable from a class that does not exist" do @scope.stubs(:warning) - @scope["other::deep::klass::var"].should == :undefined + @scope["other::deep::klass::var"].should be_nil end - it "should return ':undefined' when asked for a non-string qualified variable from a class that has not been evaluated" do + it "should return nil when asked for a non-string qualified variable from a class that has not been evaluated" do @scope.stubs(:warning) klass = newclass("other::deep::klass") - @scope["other::deep::klass::var"].should == :undefined + @scope["other::deep::klass::var"].should be_nil end end end @@ -320,7 +320,7 @@ describe Puppet::Parser::Scope do @scope.unset_ephemeral_var - @scope["1"].should == :undefined + @scope["1"].should be_nil end it "should not remove classic variables when unset_ephemeral_var is called" do @@ -393,7 +393,7 @@ describe Puppet::Parser::Scope do @scope.unset_ephemeral_var - @scope["1"].should == :undefined + @scope["1"].should be_nil end end @@ -449,13 +449,13 @@ describe Puppet::Parser::Scope do it "should be able to unset normal variables" do @scope["foo"] = "bar" @scope.unsetvar("foo") - @scope["foo"].should == :undefined + @scope["foo"].should be_nil end it "should be able to unset ephemeral variables" do @scope.setvar("0", "bar", :ephemeral => true) @scope.unsetvar("0") - @scope["0"].should == :undefined + @scope["0"].should be_nil end it "should not unset ephemeral variables in previous ephemeral scope" do diff --git a/test/language/scope.rb b/test/language/scope.rb index 57824d887..c80178e7b 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -47,7 +47,7 @@ class TestScope < Test::Unit::TestCase # Now set a var in the midscope and make sure the mid and bottom can see it but not the top midscope['second'] = "midval" - assert_equal(:undefined, scopes[:top]['second'], "Found child var in top scope") + assert_nil(scopes[:top]['second'], "Found child var in top scope") [:mid, :bot].each do |name| assert_equal("midval", scopes[name]['second'], "Could not find var in #{name}") end @@ -55,7 +55,7 @@ class TestScope < Test::Unit::TestCase # And set something in the bottom, and make sure we only find it there. botscope['third'] = "botval" [:top, :mid].each do |name| - assert_equal(:undefined, scopes[name]['third'], "Found child var in top scope") + assert_nil(scopes[name]['third'], "Found child var in top scope") end assert_equal("botval", scopes[:bot]['third'], "Could not find var in bottom scope") |
