Puppet 4 function dispatch

18 views
Skip to first unread message

Dean Wilson

unread,
May 23, 2017, 2:21:21 PM5/23/17
to puppe...@googlegroups.com
Hi,
I'm currently trying to write a Puppet 4, EPP, version of
https://forge.puppet.com/deanwilson/multitemplate but I'm having an
issue with the dispatch rules I'd like to use.

In order to support multiple template file names, and provide values
for the templates, I think I want something like this (but with a
better Pattern):

dispatch :template_data do
scope_param
repeated_param 'String', :templates
param 'Hash[Pattern[/^\w+$/], Any]', :parameters
end

But that's not allowed as repeated patterns have to be the last thing
(excluding blocks.) I know in modern rubies you can have a 'splat' in
the middle and unpack the first and last params so I was wondering if
it'd be considered for puppet function dispatch too.

I can currently get around this with a call like
multi_epp_template(['file', 'file2'], { }) but that extra bit of array
syntax feels unwieldy.

In general the puppet 4 function dispatch stuff has been quite nice to
work with, so congrats on that.

Dean
--
Dean Wilson http://www.unixdaemon.net

Henrik Lindberg

unread,
May 23, 2017, 3:48:36 PM5/23/17
to puppe...@googlegroups.com
On 23/05/17 20:21, Dean Wilson wrote:
> Hi,
> I'm currently trying to write a Puppet 4, EPP, version of
> https://forge.puppet.com/deanwilson/multitemplate but I'm having an
> issue with the dispatch rules I'd like to use.
>
> In order to support multiple template file names, and provide values
> for the templates, I think I want something like this (but with a
> better Pattern):
>
> dispatch :template_data do
> scope_param
> repeated_param 'String', :templates
> param 'Hash[Pattern[/^\w+$/], Any]', :parameters
> end
>
> But that's not allowed as repeated patterns have to be the last thing
> (excluding blocks.) I know in modern rubies you can have a 'splat' in
> the middle and unpack the first and last params so I was wondering if
> it'd be considered for puppet function dispatch too.
>

We did consider adding that but rejected the idea. Mostly because the
varargs concept exists in most languages (as last param), but not
somewhere in the middle.

Why not simply switch the arguments around so you have the list of files
at the end of the list?

- henrik

> I can currently get around this with a call like
> multi_epp_template(['file', 'file2'], { }) but that extra bit of array
> syntax feels unwieldy.
>
> In general the puppet 4 function dispatch stuff has been quite nice to
> work with, so congrats on that.
>
Glad you like it.

- henrik

> Dean
>


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Dean Wilson

unread,
May 23, 2017, 3:56:04 PM5/23/17
to puppe...@googlegroups.com
On Tue, 23 May 2017 at 20:48, Henrik Lindberg <henrik....@puppet.com> wrote:

We did consider adding that but rejected the idea.

That was the confirmation I was hoping for. Means I can stop trying to work around it now.

Why not simply switch the arguments around so you have the list of files
at the end of the list?

It is an option, but it means that the calling syntax is the opposite of calling the current epp function which is less than ideal.

Thanks for the answer.

--
Dean Wilson               http://www.unixdaemon.net
Profanity is the one language all programmers understand
--- Anon
Reply all
Reply to author
Forward
0 new messages