(PUP-1220) apply proper scoping rules to scope#to_hash

The fix for #1427 added an instance method to the scope class
for exporting all variables from the local scope. This method
apparently re-implemented the dynamic scoping rules.

When those were removed, the #to_hash method was left as was.
As a result, dynamic scoping still worked from within templates,
when using the @variable syntax in the erb code.

Fix this by using the new #enclosing_scope method so that proper
scoping rules are used instead.
(PUP-1220) make the dynamic scoping fix for #22800 flexible

As suggested by Henrik Lindberg, make the parser only behave correctly
when parser=future is configured. If working manifests rely on the
regression, the next point release won't break them. Instead, users can
test for this using the configuration setting.

The next major release should adopt the fix as standard behavior and
the legacy support should be removed. Since the variable lookups in
templates relies on the accessing of local attributes, there is no
way to issue deprecation warnings to users.
(PUP-1220) optimize template scoping fix

Following enhancements as suggested by Erik Dalen, Andy Parker et al.
* prefer Puppet[:parser] over Puppet['parser']
* cache the config value of Puppet[:parser]
* pick the future vs. legacy branch only once per template
Merge pull request #2117 from ffrank/ticket/master/22800-dynamic-lookup-in-templates

(PUP-1220) apply proper scoping rules to scope#to_hash