diff options
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/compiler.rb | 44 | ||||
-rw-r--r-- | lib/puppet/parser/resource.rb | 20 |
2 files changed, 46 insertions, 18 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index fd7d9680b..ae4af7622 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -361,6 +361,50 @@ class Puppet::Parser::Compiler resource.finish if resource.respond_to?(:finish) end + + add_resource_metaparams + end + + def add_resource_metaparams + unless main = catalog.resource(:class, :main) + raise "Couldn't find main" + end + + names = [] + Puppet::Type.eachmetaparam do |name| + next if Puppet::Parser::Resource.relationship_parameter?(name) + names << name + end + + data = {} + catalog.walk(main, :out) do |source, target| + if source_data = data[source] || metaparams_as_data(source, names) + # only store anything in the data hash if we've actually got + # data + data[source] ||= source_data + source_data.each do |param, value| + target[param] = value if target[param].nil? + end + data[target] = source_data.merge(metaparams_as_data(target, names)) + end + + target.tag(*(source.tags)) + end + end + + def metaparams_as_data(resource, params) + data = nil + params.each do |param| + unless resource[param].nil? + # Because we could be creating a hash for every resource, + # and we actually probably don't often have any data here at all, + # we're optimizing a bit by only creating a hash if there's + # any data to put in it. + data ||= {} + data[param] = resource[param] + end + end + data end # Initialize the top-level scope, class, and resource. diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 3e012247b..a4587723e 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -100,7 +100,6 @@ class Puppet::Parser::Resource < Puppet::Resource @finished = true add_defaults() add_metaparams() - add_scope_tags() validate() end @@ -279,23 +278,8 @@ class Puppet::Parser::Resource < Puppet::Resource compat_mode = metaparam_compatibility_mode? Puppet::Type.eachmetaparam do |name| - if self.class.relationship_parameter?(name) - add_backward_compatible_relationship_param(name) if compat_mode - next - end - - next if @parameters[name] - - # Skip metaparams for which we get no value. - next unless val = scope.lookupvar(name.to_s, false) and val != :undefined - - set_parameter(name, val) - end - end - - def add_scope_tags - if scope_resource = scope.resource - tag(*scope_resource.tags) + next unless self.class.relationship_parameter?(name) + add_backward_compatible_relationship_param(name) if compat_mode end end |