diff options
author | Luke Kanies <luke@reductivelabs.com> | 2010-03-16 08:17:49 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | bc90df6e7c0ea194f46ecc3c1753226b8da648c8 (patch) | |
tree | 5f68fde4f1f9bb39897da0e480b41ebfed31d441 /lib/puppet/parser/functions.rb | |
parent | 17e40e745157b538d19800618584d19f8d29226e (diff) | |
download | puppet-bc90df6e7c0ea194f46ecc3c1753226b8da648c8.tar.gz puppet-bc90df6e7c0ea194f46ecc3c1753226b8da648c8.tar.xz puppet-bc90df6e7c0ea194f46ecc3c1753226b8da648c8.zip |
Functions are added to a module instead of Scope
We were previously adding them directly to Scope, but
now they're in a module that Scope includes.
This is the first half of #1175 - we can now maintain
environment-specific collections of functions. We need
some way of tracking which environment a given function
is loaded from.
Well, maybe it's the first third - the core functions
probably need to be added to all of these modules,
or there needs to be a 'common' module that is included by
all of them.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/parser/functions.rb')
-rw-r--r-- | lib/puppet/parser/functions.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 38bb2eb42..4179cb81d 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -2,10 +2,12 @@ require 'puppet/util/autoload' require 'puppet/parser/scope' # A module for managing parser functions. Each specified function -# becomes an instance method on the Scope class. +# is added to a central module that then gets included into the Scope +# class. module Puppet::Parser::Functions @functions = {} + @modules = {} class << self include Puppet::Util @@ -22,6 +24,10 @@ module Puppet::Parser::Functions @autoloader end + def self.environment_module(env = nil) + @module ||= Module.new + end + # Create a new function type. def self.newfunction(name, options = {}, &block) name = symbolize(name) @@ -43,7 +49,7 @@ module Puppet::Parser::Functions end fname = "function_" + name.to_s - Puppet::Parser::Scope.send(:define_method, fname, &block) + environment_module.send(:define_method, fname, &block) # Someday we'll support specifying an arity, but for now, nope #@functions[name] = {:arity => arity, :type => ftype} @@ -64,7 +70,7 @@ module Puppet::Parser::Functions @functions.delete(name) fname = "function_" + name.to_s - Puppet::Parser::Scope.send(:remove_method, fname) + environment_module.send(:remove_method, fname) end # Determine if a given name is a function |