NAME
CCM::TextRender - Class for rendering structured text using Element instances
DESCRIPTION
This class is an extension of the CAF::TextRender class; with the main
difference the support of a EDG::WP4::CCM::CacheManager::Element instance as contents.
Private methods
-
_initializeInitialize the process object. Arguments:
-
module
The rendering module to use (see CAF::TextRender for details).
CCM provides following additional builtin modules:
-
general
using TT to render a
Config::Generalcompatible file. (This is an alias for theCCM/generalTT module).Contents is a hashref (does not require a
Elementinstance), with key/value pairs generated according to the basetype of the value as follows:-
scalar
converted in a single line <key> <value>
-
arrayref of scalars
converted in multiple lines as follows <key> <scalar element0> <key> <scalar element1> ...
-
hashref
generates a block with format <"key"> <recursive rendering of the value> </"key">
-
arrayref of hashref
generates series of blocks <"key"> <recursive rendering of the element0> </"key"> <"key"> <recursive rendering of the element1> </"key"> ...
(Whitespace in the block name is enforced with double quotes.)
-
-
-
contents
contentsis either a hash reference holding the contents to pass to the rendering module; or aEDG::WP4::CCM::CacheManager::Elementinstance, on whichgetTreeis called with anyelementoptions.
All optional arguments from
CAF::TextRenderare supported unmodified:- log
- includepath
- relpath
- eol
- usecache
- ttoptions
Extra optional arguments:
-
element
A hashref holding any
getTreeoptions to pass. These can be the anonymous convert methodsconvert_boolean,convert_string,convert_longandconvert_double; or one of the predefined convert methods (key is the name, value a boolean wheter or not to use them).The
convert_methods are added as last methods.The predefined convert methods are:
-
cast
Convert the scalar values to a more exact internal representation. The internal representaiton is important when passed on to other non-pure perl code, in particular the
XSmodules likeJSON::XSandYAML::XS. -
json
Enable JSON output, in particular JSON boolean (
castis implied, so the other types should already be in proper format). This is automatically enabled when the json module is used (and not explicitly set). -
yaml
Enable YAML output, in particular YAML boolean (
castis implied, so the other types should already be in proper format). This is automatically enabled when the yaml module is used (and not explicitly set). -
yesno
Convert boolean to (lowercase) 'yes' and 'no'.
-
YESNO
Convert boolean to (uppercase) 'YES' and 'NO'.
-
truefalse
Convert boolean to (lowercase) 'true' and 'false'.
-
TRUEFALSE
Convert boolean to (uppercase) 'TRUE' and 'FALSE'.
-
doublequote
Convert string to doublequoted string.
-
singlequote
Convert string to singlequoted string.
-
joincomma
Convert list of scalars in comma-separated list of strings (if first element is scalar). List where first element is non-scalar is not converted (but any of the nested list could).
-
joinspace
Convert list of scalars in space-separated list of strings (if first element is scalar). List where first element is non-scalar is not converted (but any of the nested list could).
Caveat: is preceded by
joincommaoption.
Other
getTreeoptions-
depth
Only return the next
depthlevels of nesting (and use the Element instances as values). Adepth == 0is the element itself,depth == 1is the first level, ...Default or depth
undefreturns all levels.
-
-
-
ccm_format
Returns the CCM::TextRender instance for predefined
formatandelement. Returns undef incase the format is not defined. An array with valid formats is exported via@CCM_FORMATS.Supported formats are:
- json
- pan
- pancxml
- query
- yaml
Usage example:
use EDG::WP4::CCM::TextRender qw(ccm_format); my $format = 'json'; my $element = $config->getElement("/"); my $trd = ccm_format($format, $element); if (defined $trd->get_text()) { print "$trd"; } else { $logger->error("Failed to textrender format $format: $trd->{fail}") }