NAME

CodeGen::Cpppp::Template - Base class for template classes created by compiling cpppp

DESCRIPTION

This is the base class for all Template classes compiled from cpppp source. It also defines the exports that set up the scope for evaluating the template.

EXPORTS

-setup

Initializes @ISA to CodeGen::Cpppp::Template (unless it was already initialized) and sets the compiler flags for strict, warnings, utf8, lexical_subs, signatures, and postderef.

:v0

Exports symbols PUBLIC, PROTECTED, PRIVATE, compile_cpppp

ATTRIBUTES

context

Weak-reference to the instance of CodeGen::Cpppp which created this template, if any. This is automatically set by "new_template" in CodeGen::Cpppp. Read-only.

output

Instance of CodeGen::Cpppp::Output. Read-only.

current_output_section

Name of the section of output being written. Read-write.

autocolumn

Whether to look for column-alignment in the template source and try to preserve that column alignment after all variables have been substituted.

autocomma

Whether to automatically insert commas when interpolating an array into a template, based on context.

autoindent

Whether to guess what the proper indent should be when substituting content that contains a newline.

autostatementline

Whether to automatically insert newlines (and maybe indent) when substituting an array into a template, based on context.

indent

The per-block indent to use for generated code. This can be set to either a number (of spaces) or a literal string to be appended for each level of indent. If undefined, the indent will be detected from the change in leading whitespace from the first observed '{' in your template.

This setting does not re-format the existing indentation written in the template; you need a full code-formatting tool for that.

emit_POD

By default, Plain Old Documentation (POD) notation found in the template is assumed to document the template itself, and will be removed from the generated output. Set this to true to emit the POD as part of the output. (but a better idea is to declare variables like $head1= '=head1' and then use those to generate the output POD)

CONSTRUCTOR

$tpl= $template_class->new(%params, %attrs);

The constructor takes object attributes and user-defined template parameters. When specifying values for parameters, the type of the value must match the variable-type of the parameter, such as '@array' variables needing arrayref values.

Running the constructor immediately executes the body of the user's template, which may initialize variables and define subroutines, and likely also generate output. The subs declared in the template are then exposed as methods of this object. Calling those methods may generate additional output, which is all collected in the "output" object.

METHODS

coerce_parameters

my $params= $tpl_class->coerce_parameters(\%params);

Given a hashref of potential parameter values, select and coerce the ones to match the actual parameters of this template. The keys of this hashref may be either the bare name of the parameter, or the name-with-sigil. This allows you to specify { '$x' => $scalar, '@x' => \@arrayref } and for some parameter named 'x' this method will select the one whose type matches rather than attempting to coerce the value.

flush

Make sure all output is written to the "output" object. Some output is buffered internally so that formatting (like autoindent) can be applied when a code block is complete.

define_template_macro

This is called during the template constructor to bind a user-defined macro to the lexical sub that implements it for this template instance.

define_template_method

This is called during the template constructor to bind the lexical subs of the template to methods of the object being created.

AUTHOR

Michael Conrad <mike@nrdvana.net>

VERSION

version 0.005

COPYRIGHT AND LICENSE

This software is copyright (c) 2024 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.