cfengine/core — pull request #615 by tzz (2013-05-04 01:08:55+00:00)
Title: Add optional scalar arguments to functions by adding a scalar_default field to FnCallArg.  Show usage with iprange().

Here's an example of the usage. Note that in this pull request `iprange()` ignores its optional argument (the code to make use of the optional argument is in #613).

This essentially synthesizes the function call's arguments (in `ArgTemplate:realargs`) if they are scalar and if the `scalar_default` fiels of `FnCallArg` is not NULL. This is just a proposal and needs thorough review and understanding before any consideration of a merge.

```
body common control
{
bundlesequence => { run};
}

bundle agent run
{
vars:
"addresses" slist => { "127.0.0.1", "1.2.3.4" };
"ranges" slist => { "127.0.0.1", "1.2.3.0/24", "1.2.3.0", "1.2.3.0-255" };
"canon[$(addresses)]" string => canonify($(addresses));
"canon[$(ranges)]" string => canonify($(ranges));

classes:
"self_inrange_$(canon[$(ranges)])" expression => iprange($(ranges));
"not_self_inrange_$(canon[$(ranges)])" not => iprange($(ranges));
"inrange_$(canon[$(addresses)])_$(canon[$(ranges)])" expression => iprange($(ranges), $(addresses));
"not_inrange_$(canon[$(addresses)])_$(canon[$(ranges)])" not => iprange($(ranges), $(addresses));

reports:
"YES: inrange_$(canon[$(addresses)])_$(canon[$(ranges)]) says $(addresses) is in $(ranges)"
ifvarclass => "inrange_$(canon[$(addresses)])_$(canon[$(ranges)])";

"NO: not_inrange_$(canon[$(addresses)])_$(canon[$(ranges)]) says $(addresses) is NOT in $(ranges)"
ifvarclass => "not_inrange_$(canon[$(addresses)])_$(canon[$(ranges)])";

"YES: self_inrange_$(canon[$(ranges)]) says my addresses are in $(ranges)"
ifvarclass => "self_inrange_$(canon[$(ranges)])";

"NO: not_self_inrange_$(canon[$(ranges)]) says my addresses are NOT in $(ranges)"
ifvarclass => "not_self_inrange_$(canon[$(ranges)])";
}
```