HTML::EmbeddedPerl - The Perl embeddings for HTML.
automatic.
option is 0-1
<$ my $test = 1; $> <$ print $test $> # OK
option is 2-3
<$ my $test = 1; $> <$ print $test $> # NG <$ use vars qw($test); $test = 1; $ev::test = 1; $> <$ print $test $> # OK <$ print $ev::test $> # OK
passing of instanced object $ep. that are reference of Apache::RequestRec(modperl) or __PACKAGE__(cgi). example of use in the code tags.
# set output header ($key,$value) $ep->header_out('Content-Create','foo'); # set of contents type, default is 'text/html', output forcing. $ep->content_type('text/plain');
if you want not use of global variables, please use $ev. destruct $ev after execute. but it can use between multiple tags too.
$htm = something; use HTML::EmbeddedPerl; $e = HTML::EmbeddedPerl->new(); # set output header ($key,$value) $e->header_out('Content-Create','foo'); # set of contents type, default is 'text/html' $e->content_type('text/plain'); # flushing header and contents. (example 1) $e->ep(\$htm); # not flushing header, return contents to $r. $r = $e->ep(\$htm); # flushing HTTP header. $e->flush; # same above. (example 1) print $r;
The Perl-Code embeddings for HTML, it is simple and easy.
adding <$ Perl-Code $> to your HTML.
write httpd.conf or .htaccess.
<FilesMatch ".*\.phtml?$"> # Output Mode - 0..5, see OPTIONS section. PerlSetEnv OUTMODE 0 # Template Mode - 0..1, see OPTIONS section. PerlSetEnv USEFEAT 0 SetHandler modperl PerlResponseHandler HTML::EmbeddedPerl PerlOptions +ParseHeaders </FilesMatch>
needs most compatibility, use PerlResponseHandler perl-script. *please do not use CORE::print. (or call $ep-rflush()> needed)
inserting first line to
#!/your/path/twepl
if you cannot use twepl? but wrapper.pl is available. write .htaccess.
AddType application/x-embedded-perl .phtml AddHandler application/x-embedded-perl .phtml Action application/x-embedded-perl /your/path/wrapper
force exiting over the timeout for loop detection. $TIMEOUT is global, please change it overwritten.
# default is "2" seconds. $TIMEOUT = 2;
already executing under alarm, cannot change that timeout.
# set as new timeout. alarm(X); # cancelling timeout. alarm(0);
# set as new timeout. alarm(($TIMEOUT=X)); # cancelling timeout and unset timeout. alarm(($TIMEOUT=0));
# set as new timeout. alarm(X);
before calling sub ep()
$HTML::EmbeddedPerl::TIMEOUT = X;
_coloring _extract_hash _extract_array _extract_bool _extract_bool_unless _extract_tags _get_crlf _ignore_comments _init _run handler
ep($string,$option);
$ep = HTML::EmbeddedPerl->new();
flushing HTTP header.
$ep->flush;
PHP like method.
header("$key: $val");
echo $string;
it tiny-tiny solving cgi-modperl compatibility methods.
$ep->header_out($key,$val);
$ep->content-type($type);
$ep->print($string);
$ep->print($format,$string);
other methods define it freely.
depends Apache::RequestRec and more.
ep(string,option1,option2)
0 = default, execute only once. 1 = -- with coloring source. 2 = older version compatible, every tags execute. 3 = -- with coloring source. 4 = output internal code. 5 = -- with coloring source. 6 = output internal code to multiple-tags. 7 = -- with coloring source.
0 = default, not template mode. 1 = template mode.(use beta features)
# comments // comments /* comments */
case of extract scalar in non-code blocks.
<$ my $scalar = 'this is scalar'; $> <p>$scalar</p> ... <p>this is scalar</p> <$ my @array = (1..3); $> <p>@array</p> ... <p>1 2 3</p>
if you want not extract vars, please use escape sequence '\'.
<p>\$scalar</p> <p>\@array</p> ... <p>$scalar</p> <p>@array</p>
and available simple template.
use this beta features needs set option. or insert as first element in non-code blocks it.
<!--Y--> <!--N-->
default is off, because it was very slow.
<@ARRAYNAME>...</@> or <\@ARRAYREFNAME>...</@>, extract value is $_.
X is nested depth.
$nX = current array name. $iX = current position. $cX = equals scalar @array;
and $XXX = want vars.
<$ my @array = ('a'..'c'); $> <@array><p>$i: $_</p>\n</@> ... <p>0: a</p> <p>1: b</p> <p>2: c</p>
<%HASHNAME>...</%> or <\%HASHREFNAME>...</%>, extract key is $kX, value is $vX.
$nX = current hash name. $cX = equals scalar keys %hash;
<$ my %hash = ('a'=>1,'b'=>2,'c'=>3); $> <table> <%hash><tr><th>$k0</th><td>$v0</td></tr>\n</%> </table> ... <table> <tr><th>a</th><td>1</td><tr> <tr><th>b</th><td>2</td><tr> <tr><th>c</th><td>3</td><tr> </table>
<EXPRESSION>...</=> or unless <!EXPRESSION>...</!> replace inner <!> to else, <!EXPRESSION> to elsif.
<$ my $flag = 1; my $oops = 'oops!'; $> <=$flag><p>$flag</p><!><p>$oops</p></=> ... <p>1</p>
> is same a tag-closer, try ($a > $b) in compilation errors.
TWINKLE COMPUTING <twinkle@cpan.org>
Copyright (c) 2010 TWINKLE COMPUTING All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTML::EmbeddedPerl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::EmbeddedPerl
CPAN shell
perl -MCPAN -e shell install HTML::EmbeddedPerl
For more information on module installation, please visit the detailed CPAN module installation guide.