On 27 January 2014 04:00, Pawel Tomulik <[email protected]> wrote:

> Hi,
>
> macros in puppets -> http://forge.puppetlabs.com/ptomulik/macro
>
> They're similar to parser functions with three differences:
>
>    - macro names may resemble names of puppet variables/bindings, e.g.
>    'foo::bar::geez'
>    - stored in a hierarchy of directories, that is (for macro
>    'foo::bar::geez'):
>
>       + lib/puppet/parser/macros/
>         + foo/
>           + bar/
>             + geez.rb
>
>    - they're a little bit easier to implement than functions, because
>    arity checking is provided out of the box
>
> While I think that block parameters is nicer than the current puppet
method of putting all arguments in an array, there is builtin support for
arity checking in puppet 3.x. You specify the arity in the function
definition, like :arity => 2.

I think it should be possible for you to do strict arity checking even with
just regular blocks as well, not only with lambdas. The block parameter has
a arity method that you can use to find out the arity and then have
something that runs before the macro in question that checks the parameters
given against that, kind of like how the puppet 3.x function calling does
it.


> In some cases these macros may be more handy than 'params' classes when
> defining defaults for parameters. For example defaults for defined types
> which vary from instance to instance, or values which are hard to be
> computed in puppet DSL may be easily handled with macros.
>
> Leave a comment, if you find it useful or useless.
>

Cool stuff. I like the simpler definition of them with less boilerplate
than the current functions.

One thought though when me and others and discussed a new function API for
puppet we considered just having a module with methods on it instead. So to
define a new function you would just need to open that module and define a
new method. I think that would be more straightforward for people that
already know Ruby. And probably a lot easier to write unit tests for as
they would work just like a unit test for any other method. What do you
think about doing something like that to define functions/macros?


>
> Regards!
> --
> Pawel Tomulik
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-dev/1f08465e-0386-4045-8399-26d00888618e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Erik Dalén

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/CAAAzDLcU%3Db9hMpbDXWxmb4pzk1WFbdF5_PeT%3Dif%3D5y4Z%3DA1kyw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to