Template Toolkit’s DEFAULT does not do short-circuit evaluation like you might think it would.
If you have
Then the results of the method call
user.calculate_foo are assigned to
foo already has a true value.
However, whether or not foo already has a true value,
user.calculcate_foo is always invoked.
You might expect the code to look like this:
But it’s really like this;
user.calculate_foo is an expensive function that you don’t want to invoke unless you have to, you’ll have to resort to an explicit
It’s also worth noting that
DEFAULT is not for checking if a variable is set, but for checking if it is true.