Ask Your Question

Access parent class name from defined type

asked 2014-07-30 07:05:54 -0600

Sam gravatar image

I need to access the name of the class that calls a defined type. For example in

class my_class {
    my_define { "Hello World": }

define my_define {
    notify { "Called from ${parent_class_name}": }

It should notify

Called from my_class

The reasoning for this is I have a Puppet class that writes configuration for zcollective to associate a particular puppet class with a group, so in any class I want to be able to call

zabbix::group { "My Group In Zabbix": }

And it will create the association between the Puppet class name and the Zabbix template defined

Since $name gets re-defined in each class/define, I haven't found a way of accessing the name of the parent class. Is there a way to do that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-01 21:31:15 -0600

lavaman gravatar image

updated 2014-08-01 21:31:51 -0600

Generally you wouldn't want to do that, but instead pass it as a parameter to your defined type. If your module structure is simple, you may be able to get away with using $caller_module_name as described here.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-07-30 07:05:54 -0600

Seen: 711 times

Last updated: Aug 01 '14