diff options
| author | Luke Kanies <luke@madstop.com> | 2009-08-18 18:14:19 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-08-24 11:38:19 +1000 |
| commit | 6fa9271a944f4167f82cb51affe1c0b795428b73 (patch) | |
| tree | f74716eb7c6dd4a1c6e3836d80bf4379625da665 | |
| parent | c7526808c9d2d7efbcc39f33112001bd9bd42b56 (diff) | |
| download | puppet-6fa9271a944f4167f82cb51affe1c0b795428b73.tar.gz puppet-6fa9271a944f4167f82cb51affe1c0b795428b73.tar.xz puppet-6fa9271a944f4167f82cb51affe1c0b795428b73.zip | |
Fixing #2549 - autoloading of top-level classes works again
This was broken in the recent refactor around autoloading,
which didn't special-case classes that specified that they
were top-level.
Signed-off-by: Luke Kanies <luke@madstop.com>
| -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 |
