On Friday, May 10, 2013 9:53:39 AM UTC-5, christian...@gmail.com wrote:
>
> Thx, maybe this was a little too straight from the hip... BTW: I've tried 
> it - it even worked... but I see that's probably caused by a lot of strange 
> luck...
>  
>
>> Subclasses can never 'override' ancestor class variables.  They can 
>> partially *hide* them within their own scope by declaring a same-named 
>> local variable, but that has no effect on what the parent class or any 
>> other sees as the value of the parent-class variable.
>>
>
> Interesting objection - that's actually what I meant saying "override". 
> Let's try something else: There's a module "module_x" and these 
> directories: $moduledir/module_x/manifests/ and there's an "init.pp" with 
> this content:
>
>    class module_x {
>     include module_x::child
> include module_x::another_child
> include module_x::another_child2
> include module_x::another_child3
> ...    
>    }
>
> There's also a file 'constant.pp' containing this
>
>     class module_x::constant {
>         $var = 'value'
>     }
>
> Class module_x::constant is not included. Classes like module_x::child 
> should be able to inherit the default value of $var but also be able to 
> hide it within their own scope by declaring a same-named local variable. 
> It would look like this:
>
> class module_x::child inherits module_x::constant {
> // wants to use a default value for $var but should be able to hide it 
> within their own scope.
> }
>
>
> Something wrong with that? 
>


There is nothing inherently wrong with it.  There is only a question of 
whether it means what you want it to mean.  There are two main questions to 
consider:

   1. in any given context of interest, what does the unqualified variable 
   reference $var mean?
   2. what does (for example) $module_x::child::var mean?

Suppose you have this version of module_x::child:

class module_x::child inherits module_x::common {
  # no local declaration of variable $var
}

Then,

   - in class module_x::child, $var resolves to $module_x::common::var, and
   - variable $module_x::child::var is undefined (everywhere)
   
On the other hand, if module_x::child looks like this:

class module_x::child inherits module_x::common {
  $var = 'my value'
}

then,

   - in class module_x::child, $var resolves to $module_x::child::var, and
   - variable $module_x::child::var is defined (everywhere, subject to 
   parse order), and has the specified value, which may or may not differ from 
   the value of $module_x::common::var

Classes other than module_x::child and any others that inherit from it see 
no difference between the two cases.


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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to