Issue #16286 has been updated by Andrew McNaughton.
Here's an example (from the concat module) where && could be useful:
$source_real = $version ? {
24 => 'puppet:///concat/null',
default => undef,
}
This might become:
$source_real = ($version == 24) && 'puppet:///concat/null'
However, for it to be equivalent, the '&&' operator would have to return undef,
not false. That might make sense since it is not a boolean operator in the way
that 'and' is.
The following case also deserves some thought:
$val = undef
$real_val = $val || ''
I'd like the '||' operator not to evaluate the truth of the second operand,
just to return it in the case where the first operand evaluated as a boolean is
false.
----------------------------------------
Feature #16286: add || operator
https://projects.puppetlabs.com/issues/16286#change-70655
Author: Andrew McNaughton
Status: Unreviewed
Priority: Normal
Assignee:
Category:
Target version:
Affected Puppet version:
Keywords:
Branch:
There's a pattern in common usage that goes like this:
class foo ( $val = undef ) {
$real_val = $val ? {
undef => $name,
default => $val,
}
resource bar {baz: val => $realval}
}
It's an ugly hack. It would be a lot simpler like so:
class foo ( $val = undef ) {
$real_val = $val || $name
resource bar {baz: val => $realval}
}
Or, (where templates are not involved):
class foo ( $val = undef ) {
resource bar {baz: val => $val || $name}
}
The && and ||= operators common in other languages might also be useful at
times, and their meanings from other languages are well known and unambiguous.
However, || is the one I'm feeling the strongest need for.
The common need for $real_val as above grates a bit too. I imagine it would be
a more complex change to implement, but what if the values passed as parameters
could be overridden once in the same way as ones from an inherited class?
Presumably the externally provided parameters would get their own namespace.
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" 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-bugs?hl=en.