On Jul 18, 2008, at 12:28 AM, Daniel Pittman wrote:
> * Implement Puppet::Parser::Scope#each_var to yield all variables
> and values within
> the current scope, and optionally into the parent.
> * Use that to set instance member variables into
> Puppet::Parser::Templatewrapper
> * Rename the @scope member of the template wrapper, to avoid
> clashing with a scope
> variable exposed within puppet.
Any idea of the performance implications of this?
Seems like it would be more expensive, but I don't know how much more.
As long as it's not 10x more expensive or anything, I'm not against
this basic patch, although I'd like to see tests.
I figure we can actually deprecate the current style as part of 0.25
(with warnings, for a while).
>
> + # Enumerate all variables, yielding their names and values.
> Used to
> + # expose variables to the ERB template system. By default,
> recursive, so
> + # returns all parent scope variables before current scope
> variables, but
> + # that can be disabled.
> + def each_var recursive = true
> + if recursive and parent then
> + parent.each_var(recursive) { |name, value| yield(name,
> value) }
> + end
> + @symtable.each { |name, value| yield(name, value) }
> + return self
> + end
> +
Plese try to match styles with the rest of the system. We always use
four spaces for indentation, and we put parans around method
definitions.
Also, I think it makes more sense to just support a to_hash method for
scopes, again with the optional 'recurse' option.
There's no point in yielding each in turn when you can just return a
hash, which should be much faster.
>
> # We'll only ever not have a parser in testing, but, eh.
> - if @scope.parser
> - @scope.parser.watch_file(@file)
> + if @__scope__.parser
> + @__scope__.parser.watch_file(@file)
> end
You should be able to modify (or make, if necessary) an accessor that
returns the value of @__scope__, to avoid always having to use the
underscores.
--
Susskind's Rule of Thumb:
Don't ask what they think. Ask what they do.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---