Skip to content
Prev Previous commit
Next Next commit
(PUP-2176) Loading functions via new loaders should use code's loader
Without this change, loading functions is always done from the
perspective of the environment, not the perspective of the loader
that loaded the code that makes the call. This is an important feature
not only for modularity, but also for being able to conveniently
test with a test specific loader with test specific functions.

This change simply searches for a LoaderAdapter and favors that
loader over the environment loader. This mechanism will be used
for everything loaded, but is not yet implemented in the loaders).

This fix was on master, but was lost in a merge conflict.
  • Loading branch information
hlindberg committed Apr 17, 2014
commit 3fbdd26bce474821661b33cf1d5ac16b8350fcb8
5 changes: 4 additions & 1 deletion lib/puppet/pops/evaluator/runtime3_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def call_function(name, args, o, scope)
# Call via 4x API if it is available, and the function exists
#
if loaders = Puppet.lookup(:loaders) {nil}
if loaders && func = loaders.environment_loader.load(:function, name)
# find the loader that loaded the code, or use the system loader
adapter = Puppet::Pops::Utils.find_adapter(o, Puppet::Pops::Adapters::LoaderAdapter)
loader = adapter.nil? ? loaders.puppet_system_loader : adapter.loader
if loader && func = loader.load(:function, name)
return func.call(scope, *args)
end
end
Expand Down