summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-10-24 14:08:14 -0700
committerNick Lewis <nick@puppetlabs.com>2011-04-12 12:47:32 -0700
commit10230cfc28e77dde127c157b7238fee2fc378969 (patch)
tree2553d228a877ddc3b912bfb25bee9b8c70338878 /lib
parente5609ffefb4132049a969d88f74138058fe78694 (diff)
downloadpuppet-10230cfc28e77dde127c157b7238fee2fc378969.tar.gz
puppet-10230cfc28e77dde127c157b7238fee2fc378969.tar.xz
puppet-10230cfc28e77dde127c157b7238fee2fc378969.zip
Step towards #5027 -- scopes should know if they are dynamic
The logic for distinguishing dynamic / static scopes was borrowed from Nick & Paul's patch, the main differences here being 1) calling it "dynamic" (true/ false) rather than "parent_relationship" (:inherited/:dynamic) 2) aligning the default so that it only needs to get set in one place (the one that will eventually go away) and 3) setting it on createion rather than with a setter. Setting it in one place, on creation, also makes it easier to see that anytime we access a scope it will have the correct setting of Scope#dynamic and that this does not change. This commit also contains a minor refactor (removing Type#subscope) that is not strictly tied to the main purpose but lies in the direction we are needing to go and it simplified things to do it now.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/scope.rb2
-rw-r--r--lib/puppet/resource/type.rb13
2 files changed, 4 insertions, 11 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 77032992c..f7a0134fc 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -21,7 +21,7 @@ class Puppet::Parser::Scope
attr_accessor :source, :resource
attr_accessor :base, :keyword
attr_accessor :top, :translated, :compiler
- attr_accessor :parent
+ attr_accessor :parent, :dynamic
attr_reader :namespaces
# thin wrapper around an ephemeral
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index 48d8c1f48..f8d820b77 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -62,13 +62,11 @@ class Puppet::Resource::Type
# Now evaluate the code associated with this class or definition.
def evaluate_code(resource)
- scope = resource.scope
- if tmp = evaluate_parent_type(resource)
- scope = tmp
- end
+ static_parent = evaluate_parent_type(resource)
+ scope = static_parent || resource.scope
- scope = subscope(scope, resource) unless resource.title == :main
+ scope = scope.newscope(:namespace => namespace, :source => self, :resource => resource, :dynamic => !static_parent) unless resource.title == :main
scope.compiler.add_class(name) unless definition?
set_resource_parameters(resource, scope)
@@ -263,11 +261,6 @@ class Puppet::Resource::Type
end
- # Create a new subscope in which to evaluate our code.
- def subscope(scope, resource)
- scope.newscope :resource => resource, :namespace => self.namespace, :source => self
- end
-
# Check whether a given argument is valid.
def valid_parameter?(param)
param = param.to_s