summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-06 22:22:10 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-06 22:22:10 +0000
commitaa741354a75c0d3b4f4b7f37a736a0154d45234c (patch)
treef048ad40c86425eabe76fccd07345f1cc63b9fa8 /lib
parentd0680c8ed3f1e0df864c25a3f21e73383095629b (diff)
downloadpuppet-aa741354a75c0d3b4f4b7f37a736a0154d45234c.tar.gz
puppet-aa741354a75c0d3b4f4b7f37a736a0154d45234c.tar.xz
puppet-aa741354a75c0d3b4f4b7f37a736a0154d45234c.zip
Fixing #596 -- classes in modules now autoload
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2655 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb2
-rw-r--r--lib/puppet/module.rb (renamed from lib/puppet/modules.rb)2
-rw-r--r--lib/puppet/parser/interpreter.rb64
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.