diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-27 16:30:53 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-27 16:30:53 +0000 |
commit | 789b786d24ab83e963b802b81c6f8254c4b4e08c (patch) | |
tree | cc57b97ab958e6d7ad3be1f5fd94898b2f66cc3b /lib/puppet/parser | |
parent | 4c885b7aa48746b6b946c7b2b0cd0abc50216ecf (diff) | |
download | puppet-789b786d24ab83e963b802b81c6f8254c4b4e08c.tar.gz puppet-789b786d24ab83e963b802b81c6f8254c4b4e08c.tar.xz puppet-789b786d24ab83e963b802b81c6f8254c4b4e08c.zip |
More code related to #517. Oops.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2227 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/functions.rb | 16 | ||||
-rw-r--r-- | lib/puppet/parser/grammar.ra | 2 | ||||
-rw-r--r-- | lib/puppet/parser/parser.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 36 |
4 files changed, 48 insertions, 12 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 47c5ff110..288a3bd68 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -213,16 +213,24 @@ module Functions # This is just syntactic sugar for a collection, although it will generally # be a good bit faster. newfunction(:realize, :doc => "Make a virtual object real. This is useful - when you want to know the name of the virtual object and don't want to - bother with a full collection. It is slightly faster than a collection, - and, of course, is a bit shorter. You must pass the object using a - reference; e.g.: ``realize User[luke]``." ) do |vals| + when you want to know the name of the virtual object and don't want to + bother with a full collection. It is slightly faster than a collection, + and, of course, is a bit shorter. You must pass the object using a + reference; e.g.: ``realize User[luke]``." ) do |vals| coll = Puppet::Parser::Collector.new(self, :nomatter, nil, nil, :virtual) vals = [vals] unless vals.is_a?(Array) coll.resources = vals newcollection(coll) end + + newfunction(:search, :doc => "Add another namespace for this class to search. + This allows you to create classes with sets of definitions and add + those classes to another class's search path.") do |vals| + vals.each do |val| + add_namespace(val) + end + end end end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 9ecae8869..6ff75d384 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -712,7 +712,7 @@ def file=(file) if @files.detect { |f| f.file == file } raise Puppet::ImportError.new("Import loop detected") else - @files << Puppet::LoadedFile.new(file) + @files << Puppet::Util::LoadedFile.new(file) @lexer.file = file end end diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 8004b5604..785d12547 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -29,7 +29,7 @@ module Puppet class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id10042e1e81', 'grammar.ra', 644 +module_eval <<'..end grammar.ra modeval..id05e5ea581f', 'grammar.ra', 644 require 'puppet/parser/functions' attr_reader :file, :interp @@ -101,7 +101,7 @@ def file=(file) if @files.detect { |f| f.file == file } raise Puppet::ImportError.new("Import loop detected") else - @files << Puppet::LoadedFile.new(file) + @files << Puppet::Util::LoadedFile.new(file) @lexer.file = file end end @@ -199,7 +199,7 @@ end # $Id$ -..end grammar.ra modeval..id10042e1e81 +..end grammar.ra modeval..id05e5ea581f ##### racc 1.4.5 generates ### diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 83a8d8d7f..6b6e31373 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -23,7 +23,7 @@ class Puppet::Parser::Scope include Enumerable include Puppet::Util::Errors attr_accessor :parent, :level, :interp, :source, :host - attr_accessor :name, :type, :topscope, :base, :keyword, :namespace + attr_accessor :name, :type, :topscope, :base, :keyword attr_accessor :top, :translated, :exported # Whether we behave declaratively. Note that it's a class variable, @@ -62,6 +62,16 @@ class Puppet::Parser::Scope end end + # Add to our list of namespaces. + def add_namespace(ns) + return false if @namespaces.include?(ns) + if @namespaces == [""] + @namespaces = [ns] + else + @namespaces << ns + end + end + # Is the type a builtin type? def builtintype?(type) if typeklass = Puppet::Type.type(type) @@ -191,11 +201,21 @@ class Puppet::Parser::Scope end def findclass(name) - interp.findclass(namespace, name) + @namespaces.each do |namespace| + if r = interp.findclass(namespace, name) + return r + end + end + return nil end def finddefine(name) - interp.finddefine(namespace, name) + @namespaces.each do |namespace| + if r = interp.finddefine(namespace, name) + return r + end + end + return nil end def findresource(string, name = nil) @@ -221,6 +241,10 @@ class Puppet::Parser::Scope @type = nil @name = nil @finished = false + if n = hash[:namespace] + @namespaces = [n] + hash.delete(:namespace) + end hash.each { |name, val| method = name.to_s + "=" if self.respond_to? method @@ -311,7 +335,7 @@ class Puppet::Parser::Scope # the top-level scope is always the only site scope. @sitescope = true - @namespace = "" + @namespaces = [""] # The list of collections that have been created. This is a global list, # but they each refer back to the scope that created them. @@ -382,6 +406,10 @@ class Puppet::Parser::Scope end end + def namespaces + @namespaces.dup + end + # Add a collection to the global list. def newcollection(coll) @collecttable << coll |