diff options
-rw-r--r-- | lib/puppet/parser/parser_support.rb | 21 | ||||
-rwxr-xr-x | spec/unit/parser/parser.rb | 6 |
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index 68cd3825c..c32a69b3d 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -117,15 +117,21 @@ class Puppet::Parser::Parser namespace = namespace.downcase name = name.downcase fullname = (namespace + "::" + name).sub(/^::/, '') - names_to_try = [fullname] - # Try to load the module init file if we're a qualified name - names_to_try << fullname.split("::")[0] if fullname.include?("::") + if name =~ /^::/ + names_to_try = [name.sub(/^::/, '')] + else + names_to_try = [fullname] + + # Try to load the module init file if we're a qualified name + names_to_try << fullname.split("::")[0] if fullname.include?("::") - # Otherwise try to load the bare name on its own. This - # is appropriate if the class we're looking for is in a - # module that's different from our namespace. - names_to_try << name + # Otherwise try to load the bare name on its own. This + # is appropriate if the class we're looking for is in a + # module that's different from our namespace. + names_to_try << name + names_to_try.compact! + end until (result = @loaded_code.send(method, namespace, name)) or names_to_try.empty? do self.load(names_to_try.shift) @@ -151,6 +157,7 @@ class Puppet::Parser::Parser # We can't interpolate at this point since we don't have any # scopes set up. Warn the user if they use a variable reference + raise "Got no file" unless file pat = file if pat.index("$") Puppet.warning( diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb index ff14e205c..9127599df 100755 --- a/spec/unit/parser/parser.rb +++ b/spec/unit/parser/parser.rb @@ -387,6 +387,12 @@ describe Puppet::Parser do @parser.stubs(:load).returns(false) @parser.find_or_load("Bogus_namespace","Bogus_name",:my_type).should == false end + + it "should directly look for fully qualified classes" do + @loaded_code.stubs(:find_hostclass).with("foo_namespace","::foo_name").returns(false, true) + @parser.expects(:load).with("foo_name").returns true + @parser.find_or_load("foo_namespace","::foo_name",:hostclass) + end end end |