HomePhorge

Refactor en route to #5027 -- remove usestring parameter from lookupvar
31f8e660c8f4Unpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

Refactor en route to #5027 -- remove usestring parameter from lookupvar

The usestring parameter to lookupvar was objectionable for several reasons;
first, it performed a function orthogonal to the main purpose of the method,
second its default was the least common value, and third it was causing other
code to work for reasons that were not obvious (extlookup).

This refactor breaks the value-transforming function out into a seperate
method which allows the user to specify the value to be used in lieu of :undef
and removes the parameter. The function, Scope#undef_as(default,exp) is
written so that it can be used in user code (templates, functions, etc.) if
needed.

This refactor will introduce a user-visible behaviour change in the case where
users were counting on lookupvar to return "" for undefined variables. The
best solution is to have them use undef_as, replacing:

lookupvar('myvar')

with

undef_as('',lookupvar('myvar'))

(with the option to specify another default value if desired). If this is too
objectionable, we could rename the existing lookupvar as raw_lookupvar and
define

def lookupvar(v)
  undef_as('',raw_lookupvar(v))
end

to restore the present behaviour.

Details

Provenance
Markus Roberts <Markus@reality.com>Authored on
Nick Lewis <nick@puppetlabs.com>Committed on Apr 12 2011, 9:47 PM
vanmeeuwenPushed on Jun 2 2015, 2:22 PM
Parents
rPUd5dc3036eda2: Fix for #5063 -- explicitly scope internal variable lookups
Branches
Unknown
Tags
Unknown

Event Timeline

Nick Lewis <nick@puppetlabs.com> committed rPU31f8e660c8f4: Refactor en route to #5027 -- remove usestring parameter from lookupvar (authored by Markus Roberts <Markus@reality.com>).Apr 12 2011, 9:47 PM