diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet.rb | 2 | ||||
-rw-r--r-- | lib/puppet/module.rb (renamed from lib/puppet/modules.rb) | 2 | ||||
-rw-r--r-- | lib/puppet/parser/interpreter.rb | 64 |
3 files changed, 61 insertions, 7 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 52e7d49d1..eccf4dbcb 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -421,7 +421,7 @@ module Puppet end require 'puppet/type' -require 'puppet/modules' +require 'puppet/module' require 'puppet/util/storage' require 'puppet/parser/interpreter' if Puppet[:storeconfigs] diff --git a/lib/puppet/modules.rb b/lib/puppet/module.rb index aa2f75d03..87f849d17 100644 --- a/lib/puppet/modules.rb +++ b/lib/puppet/module.rb @@ -111,3 +111,5 @@ class Puppet::Module private :initialize end + +# $Id$ diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 3a719e03c..11f5aa15d 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -1,7 +1,3 @@ -# The interepreter's job is to convert from a parsed file to the configuration -# for a given client. It really doesn't do any work on its own, it just collects -# and calls out to other objects. - require 'puppet' require 'timeout' require 'puppet/rails' @@ -9,6 +5,9 @@ require 'puppet/util/methodhelper' require 'puppet/parser/parser' require 'puppet/parser/scope' +# The interpreter's job is to convert from a parsed file to the configuration +# for a given client. It really doesn't do any work on its own, it just collects +# and calls out to other objects. class Puppet::Parser::Interpreter class NodeDef include Puppet::Util::MethodHelper @@ -267,12 +266,65 @@ class Puppet::Parser::Interpreter # Find a class definition, relative to the current namespace. def findclass(namespace, name) - fqfind namespace, name, @classtable + find_or_load namespace, name, @classtable end # Find a component definition, relative to the current namespace. def finddefine(namespace, name) - fqfind namespace, name, @definetable + find_or_load namespace, name, @definetable + end + + # Attempt to find the requested object. If it's not yet loaded, + # attempt to load it. + def find_or_load(namespace, name, table) + if namespace == "" + fullname = name.gsub("::", File::SEPARATOR) + else + fullname = ("%s::%s" % [namespace, name]).gsub("::", File::SEPARATOR) + end + + # See if it's already loaded + if result = fqfind(namespace, name, table) + return result + end + + if fullname == "" + return nil + end + + # Nope. Try to load the module itself, to see if that + # loads it. + mod = fullname.scan(/^[\w-]+/).shift + # We couldn't find it, so try to load the base module + begin + @parser.import(mod) + Puppet.info "Autoloaded module %s" % mod + if result = fqfind(namespace, name, table) + return result + end + rescue Puppet::ImportError => detail + # We couldn't load the module + end + + + # If they haven't specified a subclass, then there's no point in looking for + # a separate file. + if ! fullname.include?("/") + return nil + end + + # Nope. Try to load the individual file + begin + @parser.import(fullname) + Puppet.info "Autloaded file %s from module %s" % [fullname, mod] + if result = fqfind(namespace, name, table) + return result + end + rescue Puppet::ImportError => detail + # We couldn't load the file + end + + return nil end # The recursive method used to actually look these objects up. |