On Thursday, November 21, 2013 6:00:53 AM UTC-6, Felix.Frank wrote:
>
> On 11/21/2013 12:17 PM, Raj kumar V wrote: 
> > In my module folder, <module/mymodule> 
> > 
> > I have 2 files. 
> > 
> > init.pp 
> > params.pp 
> > 
> > My init code: 
> > 
> > class myclass($api_key=$myclass::params::myclassagent_APIkey) inherits 
> > myclass::params{ 
>
> No need to inherit the params class. I would get rid of that first. 
>


I'm afraid there *is* a reason: class myclass uses a variable from class 
myclass::params as the default value for its class parameter.  The only 
self-contained way to ensure that that variable's value is already set when 
class myclass is evaluated is to inherit from myclass::params.  I don't 
like that much, but it has become a widely-used pattern.

 

>
> > include myclass::params 
>
> This is likely needed, although I'm not sure wether 
> $myclass::params::myclassagent_APIkey will already be available when 
> puppet encounters the class declaration header. 
>


That's absolutely unneeded if the class inherits from myclass::params, as 
shown.  On the other hand, it would be needed and appropriate if the body 
of class myclass used any variables of class myclass::params and myclass 
did not inherit from myclass::params.
 


> > some code here... 
> > 
> > }include myclass 
>


I'm not very comfortable with putting that 'include' statement at top level 
of the module's init.pp.  I think I understand the idea, but it could lead 
to subtle errors.  In fact, it leaves you in the realm of undocumented 
behavior if you ever try to declare class myclass elsewhere via a 
parameterized-style declaration (not that I generally account 
parameterized-style class declarations a good idea, but that seems the 
direction this is heading).


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/d70b79a6-5130-41ac-b358-c4a6ea0e3bd5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to