Issue #7991 has been updated by Daniel Pittman.
> To use a custom function in a template, you must do something like the
> following:
>
> $var = inline_template("<%=
> Puppet::Parser::Functions::function('myfunction'); '' %><%=
> scope.function_myfunction(options) %>")
Ouch. The would be because we don't have auto-loading magic on the
scope, so you have to do something to trigger the autoloader to
actually attach that function. Nicely, we should probably extend
`Puppet::Parser::Scope` to handle missing methods in the style
`function_*` by trying to auto-load them and redispatch, only failing
when that can't be done.
> Furthermore, to make this work in any order, you must stick something like
> the following in your code:
>
> if false { myfunction('blah') }
>
> However, if you do this anywhere at all, you can no longer do the following:
>
> $var = myfunction('foo')
>
> Why? I have no idea! But it certainly doesn’t seem like it should work this
> way.
Yeah. Those two bits of puppet code ... well, they should trigger the
auto-loader, just like your call to `function` does, and they
shouldn't pollute anything else.
Thanks for this excellent bug report.
----------------------------------------
Bug #7991: Issue with using custom functions in templates.
https://projects.puppetlabs.com/issues/7991
Author: Trevor Vaughan
Status: Accepted
Priority: Normal
Assignee:
Category: parser
Target version:
Affected Puppet version: 2.6.0
Keywords: custom function, template
Branch:
To use a custom function in a template, you must do something like the
following:
`$var = inline_template("<%= Puppet::Parser::Functions::function('myfunction');
'' %><%= scope.function_myfunction(options) %>")`
Furthermore, to make this work in any order, you must stick something like the
following in your code:
`if false { myfunction('blah') }`
However, if you do this *anywhere at all*, you can no longer do the following:
`$var = myfunction('foo')`
Why? I have no idea! But it certainly doesn't seem like it should work this way.
Seems to affect all Puppet versions that I've tried. <= 2.6.6
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" 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-bugs?hl=en.