Hello,

I have a subclass which is attempting to append an item, or items, to an 
inherited array.

class foo {
  $baz = ["one"]
}

class foo::bar inherits foo {
  $foo::baz += ["two"]
  notice($foo::baz)
}

class foo::qux inherits foo {
  $foo::baz += "two"
  notice($foo::baz)
}

class { 'foo::bar': }
class { 'foo::qux': }


Results in:
notice: Scope(Class[Foo::Bar]): one
notice: Scope(Class[Foo::Qux]): one two

If I ignore the warnings in the documentation about not using fully 
qualified variables, it works:

class foo {
  $baz = ["one"]
}

class foo::bar inherits foo {
  $baz += ["two"]
  notice($baz)
}

class foo::qux inherits foo {
  $baz += "two"
  notice($baz)
}

class { 'foo::bar': }
class { 'foo::qux': }


Results in:
notice: Scope(Class[Foo::Bar]): one two
notice: Scope(Class[Foo::Qux]): one two

If I append an array to the fully qualified $foo::bar array, it fails. If I 
append a string to the fully qualified $foo::bar, it works. *Both* work if 
I use locally scoped $bar.

In the module I came across this issue I was originally used the locally 
scoped names, the reason I had attempted to change my module to use the 
fully qualified name was because puppet-lint returned the following warning:

WARNING: top-scope variable being used without an explicit namespace on 
line 17

I note that this message does *not* appear when running puppet-lint on my 
second example above, presumably because being all in one file rather than 
file-per-class in a module layout means puppet-lint can see the variable in 
scope.

So my questions are:
* Is this scope in my second example correct?
* Why is behaviour different in my first example when appending a string 
and an array?

Regards,
Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/xsG1gGb-gLIJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to