On Thu, Sep 16, 2010 at 12:49 PM, Jeff McCune <[email protected]> wrote:
> On Thu, Sep 16, 2010 at 3:36 PM, Luke Kanies <[email protected]> wrote:
>> On Sep 16, 2010, at 12:45 PM, Paul Berry wrote:
>>
>> I'm trying to get a better understanding of how variable scoping is
>> intended to work in Puppet.  Based on my reading of the code (and some
>> experiments), here's the behaviors that I think are intended:
>> 1. Variables defined at toplevel can be seen inside classes.  For example:
>> $var = "value"
>> class foo { notify { $var: } }
>> include foo
>>
>> This is a good idea and should stay, short and long term.
>
> Agreed.
>
> Also, please keep in mind this entire discussion applies to resource
> defaults as well.  Whatever behavior we implement for variables should
> also be implemented for resource defaults.

So the plan is that the only place you can reliably set global
resource defaults is directly in your site.pp or in an *import* from
site.pp ?

and thus not inside a class that may include all your other classes?
(we have a module 'base' that does all the logic for which other
classes should be included)

>
>> 2. Variables defined in a class can be seen inside the classes that it
>> includes (this is really a generalization of (1)).  Some might call
>> this "dynamic scoping".  For example:
>> class foo {
>>     $var = "value"
>>     include bar
>> }
>> class bar { notify { $var: } }
>> include foo
>>
>> From this on down, we're basically dealing with dynamic scoping, and in
>> general, I think it should be fixed, and by fixed, I essentially mean
>> removed.
>
> Yes, I think this behavior should be completely eliminated.  Many new
> people are extremely surprised by this behavior when the first learn
> of it.
>
> It also causes many, many problems and provides little benefit in my 
> experience.
>
> If a class includes another class and the child needs access to a
> variable in the default, if we must allow this behavior, we could do
> it with namespace notation rather than scoping.
>
> --
> Jeff McCune
> http://www.puppetlabs.com/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en.
>
>



-- 
nigel

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to