This would be a nice elegant solution, however we have not turned the future 
parser on quite yet.  I will certainly keep this function in mind though in the 
future.

> On Jun 3, 2015, at 5:56 AM, Henrik Lindberg <henrik.lindb...@cloudsmith.com> 
> wrote:
> 
> On 2015-03-06 6:26, Jacob McCoy Wade wrote:
>> I am trying to find out how I can validate more than one type of data
>> structure for a given value in a manifest?  In particular I would like
>> to be able to have either a string or a hash be a valid data structure.
>> Something like:
>> if ($myvar != false) {
>> validate_string($myvar) || validate_hash($myvar)
>> }
>> Does anybody know if this is possible to do?
>> 
> If you are using version >= 4.0.0 or >= 3.6 with future parser you can use 
> the type system to do this.
> 
> It looks like you want the value to be false (a boolean), a string (including 
> an empty string), or a hash (including an empty hash, you do not care what 
> the keys and values are).
> 
> if $myvar =~ Variant[Boolean, String, Hash] {
>  # it is one of those
> }
> 
> Note that the above does not accept undef values (which is what I think the 
> intention was).
> 
> You can also use the function assert_type if you want a simple assertion (or 
> an error) rather than just having conditional logic.
> 
> assert_type(Variant[Boolean, String, Hash], $myvar)
> 
> Hope that helps.
> - henrik
> 
>> --
>> 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
>> <mailto:puppet-users+unsubscr...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/puppet-users/732c0ec6-d9bb-4f32-9eae-4667037a0e87%40googlegroups.com
>> <https://groups.google.com/d/msgid/puppet-users/732c0ec6-d9bb-4f32-9eae-4667037a0e87%40googlegroups..com?utm_medium=email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> 
> Visit my Blog "Puppet on the Edge"
> http://puppet-on-the-edge.blogspot.se/
> 
> -- 
> 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/mkmtig%24f5i%241%40ger.gmane.org.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/E0C188FE-416C-480A-A1E8-E2A27D441C4A%40mccoywade.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to