NAME
CodeGen::Cpppp::Output - Collect text output into named sections
DESCRIPTION
C code usually needs generated in different parts, like a public header, private-to-the-project header, the forward declarations of static function, and finally the function definitions themselves. This object encapsulates that concept by storing different "sections" of generated code that you can later direct to the files where they need to go.
The default sections are:
- public
-
Lines of code for the public header. Maybe also inline functions.
priority=100
- protected
-
Lines of code for consumption by other related modules, exposing more data structures and macros than are appropriate for the public header.
priority=200
- private
-
The implementation of the compilation unit, and declarations of things that will only affect this compilation unit.
priority=10000
You can append or prepend blocks of code to any of these sections, or define additional sections of your own. The sections you define should be assigned a priority
to help sort them into the list above. You may use floating point numbers.
METHODS
new
Standard constructor, accpeting key/val list or hashref.
declare_sections
$out->declare_sections($name1, $name2, ...);
$out->declare_sections($name1 => $priority, $name2 => ..);
Declare one or more new sections. If you omit the priority values, they will be automatically selected counting upward from the last section before 'private'
.
section_priority
A hashref of { $section_name => $priority }
.
section_list
Returns a list of output section names, in the order that they would need compiled.
append
$out->append($section, @code_block);
Add one or more blocks of code to the end of the named section. The section must be declared.
prepend
$out->prepend($section, @code_block);
Add one or more blocks of code to the beginning of the named section. The section must be declared.
expand_section_selector
Expands the following patterns:
'public', ['protected'] => ( 'public', 'protected' )
"public,private" => ( 'public', 'private' )
"public..private" => ( 'public', 'protected', 'private' )
returning the list in priority order.
get
$all= $out->get;
$header= $out->get('public','protected');
$unit= $out->get('protected..private');
Collect the output from all or specified sections. An empty list returns all sections. The special notation '..' returns a range of sections, inclusive.
consume
Same as "get" but removes the content it returns. The sections remain defined, but empty.
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.