NAME
Text::MustacheTemplate::Evaluator - [INTERNAL] Context evaluation for Mustache templates
SYNOPSIS
use Text::MustacheTemplate::Evaluator qw/
retrieve_variable
evaluate_section
evaluate_section_variable
/;
my @context = ({ name => 'World', items => [1, 2, 3] });
# Get a variable value
my $value = retrieve_variable(\@context, 'name');
# Evaluate if a section should be rendered
my @section_ctx = evaluate_section_variable(\@context, 'items');
# Evaluate a direct value
my @items_ctx = evaluate_section($context[-1]->{items});
DESCRIPTION
Text::MustacheTemplate::Evaluator provides functions for evaluating Mustache template contexts and retrieving values from nested context structures according to the Mustache specification.
This is internal interface for Text::MustacheTemplate. The APIs may change without notice.
FUNCTIONS
- retrieve_variable(\@context, @path)
-
Retrieves a value from the context stack by following the given path. Returns the value if found, otherwise undef.
Parameters:
- evaluate_section($value)
-
Evaluates whether a section should be rendered and how it should be processed. Returns an array of context objects for iteration.
Parameters:
For different value types:
Undefined or falsy values: Returns an empty array (section not rendered)
Array references: Returns the array elements for iteration
Hash references: Returns the hash reference itself for context
Code references: Returns the code reference for lambda processing
True scalar values: Returns the value as a single-element array
- evaluate_section_variable(\@context, @path)
-
Retrieves a variable by path and evaluates it as a section. Combines retrieve_variable and evaluate_section.
Parameters:
LAMBDA SUPPORT
When a section value is a code reference (lambda), the Evaluator provides special handling:
The lambda receives the raw section content as its first argument
If $LAMBDA_RENDERER is defined, the lambda's result will be processed by this renderer
This enables dynamic template generation within templates