On 2015-12-04 10:14, Alessandro Franceschi wrote:
Hi all,
I've started to make some future parser versions of the most useful Tiny
Puppet defines:
https://github.com/example42/puppet-tp/commit/78222a8e12542d0203b2bc600b7984fbf555a488
the main advantages I've seen, for this use case, is the neater and more
concise parameters validation, and, for the tp::install4 define
(https://github.com/example42/puppet-tp/blob/master/manifests/install4.pp)
, the ability to cope with arrays of packages and services.

Another small change is the usage of the + operator on hashes instead of
stdlib's merge().
There's probably more that can be done on them (any input or suggestions
  is welcomed) , but in particular I have a point I'd like to fix.

When Parameters are undef by default I didn't find anything better than
enforcing an "Any" type, which actually does not validate anything:

        definetp::conf4(
        String $ensure = present,
        
        Any $source = undef,
        Any $template = undef,
        Any $epp = undef,
        Any $content = undef,


is there a concise way (without other verbose conditionals in the code)
to validate a parameter type IF that parameter is passed when is undef
by default?

Use the type Optional[T] to enforce either the type T, or undef. In your example, say that $content must be a non empty string, or undef then you could type it like this:

    Optional[String[1]] $content = undef

Depending on what is accepted you can also use a Variant type with an explicit Undef, this means the same thing as above:

    Variant[Undef, String[1]] $content = undef

Hope that helps

- henrik

Any help appreciated,
al

--
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/66b016b6-0e1a-4623-9c1b-ab61ed179dcb%40googlegroups.com
<https://groups.google.com/d/msgid/puppet-users/66b016b6-0e1a-4623-9c1b-ab61ed179dcb%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/mgdl91%24clq%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to