Skip to content

Commit

Permalink
(PUP-2755) Remove special handling of iterative functions / cleanup
Browse files Browse the repository at this point in the history
This fixes comments from review. It also removes the special
handling of the iterative functions (special case to avoid
having their arguments transformed) as this is no longer needed.
  • Loading branch information
hlindberg committed Jun 17, 2014
1 parent d6fefce commit cda28c6
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/puppet/pops/evaluator/runtime3_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,17 @@ def coerce_numeric(v, o, scope)
n
end

# Horrible cheat while waiting for iterative functions to be 4x
FUNCTIONS_4x = { 'map' => true, 'each'=>true, 'filter' => true, 'reduce' => true, 'slice' => true }
def call_function(name, args, o, scope)
# Call via 4x API if it is available, and the function exists
#
if loaders = scope.compiler.loaders
# find the loader that loaded the code, or use the private_environment_loader (sees env + all modules)
adapter = Puppet::Pops::Utils.find_adapter(o, Puppet::Pops::Adapters::LoaderAdapter)
loader = adapter.nil? ? loaders.private_environment_loader : adapter.loader
if loader && func = loader.load(:function, name)
return func.call(scope, *args)
end
# Call via 4x API if the function exists there
loaders = scope.compiler.loaders
# find the loader that loaded the code, or use the private_environment_loader (sees env + all modules)
adapter = Puppet::Pops::Utils.find_adapter(o, Puppet::Pops::Adapters::LoaderAdapter)
loader = adapter.nil? ? loaders.private_environment_loader : adapter.loader
if loader && func = loader.load(:function, name)
return func.call(scope, *args)
end

# Call via 3x API if function exists there
fail(Puppet::Pops::Issues::UNKNOWN_FUNCTION, o, {:name => name}) unless Puppet::Parser::Functions.function(name)

# TODO: if Puppet[:biff] == true, then 3x functions should be called via loaders above
Expand All @@ -248,7 +245,7 @@ def call_function(name, args, o, scope)
# directly, when this has been done, this special filtering out can be removed

# NOTE: Passing an empty string last converts :undef to empty string
mapped_args = FUNCTIONS_4x[name] ? args : args.map {|a| convert(a, scope, '') }
mapped_args = args.map {|a| convert(a, scope, '') }
result = scope.send("function_#{name}", mapped_args)
# Prevent non r-value functions from leaking their result (they are not written to care about this)
Puppet::Parser::Functions.rvalue?(name) ? result : nil
Expand Down

0 comments on commit cda28c6

Please sign in to comment.