summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-06-08 07:03:54 -0700
committerLuke Kanies <luke@puppetlabs.com>2011-07-15 11:51:49 -0700
commit0d2e0672eb516a1b1f2ced6b8c74bd2064dd205e (patch)
tree28d38def94814fcce50b4d82984265dcca7e0545 /lib/puppet/parser/functions
parent4ad404ee7e7244d94ff4d87effc1a041d65b3f73 (diff)
downloadpuppet-0d2e0672eb516a1b1f2ced6b8c74bd2064dd205e.tar.gz
puppet-0d2e0672eb516a1b1f2ced6b8c74bd2064dd205e.tar.xz
puppet-0d2e0672eb516a1b1f2ced6b8c74bd2064dd205e.zip
Adding []/[]= support to Scope
The interface to scope is much clearer this way anyway, but this is needed to integrate Puppet with Hiera[1]. It just provides hash-like behavior to Scope, which Hiera and others can now easily rely on. I also went through all of the code that used Scope#lookupvar and Scope#setvar and changed it if possible, and at the same time cleaned up a lot of tests that were unnecessarily stubbing (and thus making it difficult to tell if I had actually broken anything). 1 - https://github.com/ripienaar/hiera Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com>
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/extlookup.rb12
-rw-r--r--lib/puppet/parser/functions/fqdn_rand.rb2
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/puppet/parser/functions/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb
index 5fbf26cec..9ffca59a7 100644
--- a/lib/puppet/parser/functions/extlookup.rb
+++ b/lib/puppet/parser/functions/extlookup.rb
@@ -91,9 +91,9 @@ This is for back compatibility to interpolate variables with %. % interpolation
raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3
- extlookup_datadir = undef_as('',lookupvar('::extlookup_datadir'))
+ extlookup_datadir = undef_as('',self['::extlookup_datadir'])
- extlookup_precedence = undef_as([],lookupvar('::extlookup_precedence')).collect { |var| var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } }
+ extlookup_precedence = undef_as([],self['::extlookup_precedence']).collect { |var| var.gsub(/%\{(.+?)\}/) { self["::#{$1}"] } }
datafiles = Array.new
@@ -121,9 +121,9 @@ This is for back compatibility to interpolate variables with %. % interpolation
if result[0].length == 2
val = result[0][1].to_s
- # parse %{}'s in the CSV into local variables using lookupvar()
+ # parse %{}'s in the CSV into local variables using the current scope
while val =~ /%\{(.+?)\}/
- val.gsub!(/%\{#{$1}\}/, lookupvar($1))
+ val.gsub!(/%\{#{$1}\}/, self[$1])
end
desired = val
@@ -134,9 +134,9 @@ This is for back compatibility to interpolate variables with %. % interpolation
# Individual cells in a CSV result are a weird data type and throws
# puppets yaml parsing, so just map it all to plain old strings
desired = cells.map do |c|
- # parse %{}'s in the CSV into local variables using lookupvar()
+ # parse %{}'s in the CSV into local variables using the current scope
while c =~ /%\{(.+?)\}/
- c.gsub!(/%\{#{$1}\}/, lookupvar($1))
+ c.gsub!(/%\{#{$1}\}/, self[$1])
end
c.to_s
diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb
index 93ab98bcd..668802e73 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -7,6 +7,6 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
$random_number_seed = fqdn_rand(30,30)") do |args|
require 'digest/md5'
max = args.shift
- srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex)
+ srand(Digest::MD5.hexdigest([self['::fqdn'],args].join(':')).hex)
rand(max).to_s
end