Konstrukt::Plugin::perl - Embedding perl code in your pages/templates
Usage:
<& perl &>print "foo"<& / &>
Result:
foo
With this plugin you may embed Perl code into the source code of an Konstrukt-webpage.
Those variables will be available to your code: $Konstrukt::Handler, $Konstrukt::Settings, $Konstrukt::Lib, $Konstrukt::Debug, $Konstrukt::File, $template_values.
The variable $template_values contains the template values passed to the file, which contains the perl tag. It can be used to produce output for these values. The structure of this data will look like described in "node" in Konstrukt::Plugin::template. The values may be scalars (strings) or Konstrukt::Parser::Nodes. You should not modify this data!
$template_values
Note that it would be wise in some cases to enclose the perl code within a comment to prevent parsing of the perl code by the Konstrukt-parser:
<& perl &> #<-- sub one { return 1; } if (0<&one()) { print "hi!"; } #--> <& / &>
Otherwise 0<&one() would lead into incorrect parsing as <& would get recognized as a plugin tag start.
0<&one()
<&
For more general information about plugins take a look at Konstrukt::Plugin.
You may configure the perl plugin to parse the printed output for new tags:
#per default the output won't be parsed again perl/parse_output_for_tags 0
Initialization. Will only be used internally.
The executed perl code may generate plaintext that will be parsed to new tag nodes.
If you plan to do it (although it is better to directly push the according tag nodes), you have to set the setting perl/parse_output_for_tags to 1.
Yes, this plugin will very likely generate new tags.
We cannot prepare anything as the perl code generally will be completely dynamic.
All the work is done in the execute step. The result of print-statements will be put into the page at the position of the perl-tag.
print
Accepts the printredirector_print-event and adds a plaintext node
printredirector_print
Parameters:
@data - The data passed to the print function
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software. It is distributed under the same terms as Perl itself.
Konstrukt::Plugin, Konstrukt
To install Konstrukt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Konstrukt
CPAN shell
perl -MCPAN -e shell install Konstrukt
For more information on module installation, please visit the detailed CPAN module installation guide.