On 19 September 2012 02:27, Eric Sorenson <[email protected]> wrote:
> On Friday, September 14, 2012 3:36:20 PM UTC-7, Stefan Schulte wrote:
>>
>>
>> I use this a lot to be able to have an optional parameter in a parent
>> class that is passed to an included class and the included class
>> determines the default value. Like:
>>
>>     class basic($puppet_cron = undef) {
>>       class { 'puppet::client':
>>         cron => $puppet_cron,
>>       }
>>     }
>>
>
> Stefan - This is exactly the case I'm concerned about.
>
> The simplest way to preserve this pattern would be putting the default value
> for cron in the `basic` typedef, where you now have `undef`.
>
> class basic($puppet_cron = "some_default") {
>    class { 'puppet::client':
>       cron => $puppet_cron,
>   }
> }
>
> The advantage is that if you want to really revert to the default for the
> `cron` parameter, you can actually invoke it with undef, just like a regular
> resource.
>
> The bad side is that you now have to move your defaults to the calling
> class, or worse, duplicate them.
>
> What do you think?
>

Another possibility is to use the pattern in puppetlabs-mysql where
mysql::server wraps the inner class mysql::config.
See 
https://github.com/puppetlabs/puppetlabs-mysql/blob/master/manifests/server.pp
lines 28-30.

Basically you pass the parameters as a hash to the outer class which
it then uses with the create_resources() function to create a inner
class.

Then you can use the parameter defaults feature of the
create_resources function to pass any extra parameters to the inner
class, or use the merge() function from stdlib to merge two hashes
together to pass some extra parameters.

Switching to this pattern might involve some refactoring though for people.

-- 
Erik Dalén

-- 
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