From 50a626daa1bef956ea63c405fddeaeab8a9a0756 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Jun 2010 19:21:05 -0700 Subject: Fixing #1545 - Adding 'caller_module_name' variable This will produce the name of the module that a given resource is defined in, rather than the module that the resource type itself is defined in. For instance: # in one/manifests/onedef.pp define one::onedef { notice "Called $name from $caller_module_name" } # in two/manifests/init.pp class two { one::onedef { yay: } } produces: Called yay from two This could obviously be extended to actually build a caller stack, as frightening as that seems. Signed-off-by: Luke Kanies --- lib/puppet/parser/scope.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 140c8c1b5..c974aee78 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -306,6 +306,12 @@ class Puppet::Parser::Scope self.nodescope end + def parent_module_name + return nil unless @parent + return nil unless @parent.source + @parent.source.module_name + end + # Return the list of scopes up to the top scope, ordered with our own first. # This is used for looking up variables and defaults. def scope_path -- cgit