Package DE_EPAGES::TLE::API::Processor
This class module includes a basic tle processor. This processor can
replace simple scalar tle values and provides the possibility to add
handler for different opportunities, see new or registerHandler
to add more functionalities on a processor.
Hint: The DE_EPAGES::TLE::API::BaseProcessor is a tle processor
with the most used functions (LOOP,JOIN,...).
Functions
- callFormatHandler
- existsTLE
- formatTLE
- getContext
- getTLE
- new
- registerHandler
- replaceTLEs
- setContext
- tle
callFormatHandler
Calls the apropriate format handler for the given format string and returns the formatted value.
Syntax |
$Value = $TLEProcessor->callFormatHandler( $Value, $FormatString, $Name, $aFormatParameter ); |
Input |
|
Return |
|
existsTLE
Returns true if the TLE variable exists.
Syntax |
$Exists = $TLEProcessor->existsTLE( $Name ); |
Input |
|
Return |
|
formatTLE
The value will be formatted according to the format parameters.
Syntax |
$Value = $TLEProcessor->formatTLE( $Name, $Format, $Value ); |
Input |
|
Return |
|
getContext
Return copy of context. The entries of context can be set via functions new or setContext.
Syntax |
$hContext = $TLEProcessor->getContext(); |
Input |
|
getTLE
Returns the value of a TLE variable. This procedure takes care about the current context. The value will NOT be formatted according to the format parameters. If the value read by form error then the formatting will be replaced by the default formatting. This function needs a previous run of existsTLE to find the value at stack. $rFormat will be set with default formatter in case the value is set via form error.
Syntax |
$Value = $TLEProcessor->getTLE( $Name, $rFormat ); |
Input |
|
Return |
|
new
This method is used to create a new tle processor. The initial context defined by $hContext can be overwritten by setContext.
Syntax |
$TLEProcessor = new DE_EPAGES::TLE::API::Processor($hContext); |
Input |
|
Return |
|
registerHandler
Register handler to add more functionality to the tle processor, you can add four different types:
- 'VariableHandler' - is a variable not defined at the 'TemplateVars' then the variable handlers will be asked. If the $Name is given then this handler will only be registered for this TLEVariable. The handler has to implement the functions tle and existsTLE, see the additional example DE_EPAGES::TLE::API::LoopHandler::tle
- 'FunctionHandler' - all functions and blocks are not included in the processor, you can use the placeholder BLOCK and FUNCTION to implement your own function without changing the tle compiler. At the template you can write: #FUNCTION("MyFunction", #ProductName) or with a template part: #BLOCK("MyFunction", #ProductName) some text #SomeTLEs #ENDBLOCK, see the examples for loops at package DE_EPAGES::TLE::API::LoopHandler
- 'FormatHandler' - functions to format each TLE value ( [] in template)
- 'EncodingHandler' - functions to format the result
Syntax |
$ReturnValue = $TLEProcessor->registerHandler( $HandlerType, $Handler, $Name); |
Example |
my $PriceHandler = new ProductPriceHandler; $TLEProcessor->registerHandler('VariableHandler', $PriceHandler, 'MyPrice'); $TLEProcessor->registerHandler('FormatHandler', DE_EPAGES::TLE::API::SpaceFormatter->new); my $LoopHandler = new DE_EPAGES::TLE::API::LoopHandler; $TLEProcessor->registerHandler('FunctionHandler', $LoopHandler, 'JOIN'); $TLEProcessor->registerHandler('FunctionHandler', $LoopHandler, 'LOOP'); |
Input |
|
replaceTLEs
Replaces placeholder in template with dynamic variables. The rVars can be used from template. The existing variables will be saved on stack. Note: the block function which is registered with registerHandler also gets the byte code as parameter, see DE_EPAGES::TLE::API::LoopHandler::LOOP.
Syntax |
$Content = $TLEProcessor->replaceTLEs( $aByteCode, $hVars); |
Example |
sub WITH { my $self = shift; my ($Processor, $raParams, $cTemplate) = @_; my $Parameter = $raParams->[0]; return join('', @{$Processor->replaceTLEs($cTemplate, $Parameter)}); } |
Input |
|
Return |
|
setContext
Adds data to the processor to save process information. If a value of this hash isn't defined then the entry will be deleted.
Syntax |
$TLEProcessor->setContext( $hContext ); |
Example |
$TLEProcessor->setContext( { 'FileName'=>$FileName }); |
Input |
|
tle
Returns the value of a TLE variable. This procedure takes care about the current context. The value will be formatted according to the format parameters.
Syntax |
$Value = $TLEProcessor->tle( $Name, $Format ); |
Input |
|
Return |
|