NAME
HTML::EmbeddedPerl - The Perl embeddings for HTML.
SYNOPSYS
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
run in the automatically
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.
using in the script
$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;
DESCRIPTION
The Perl-Code embeddings for HTML, it is simple and easy.
adding <$ Perl-Code $> to your HTML.
mod_perl2
write httpd.conf or .htaccess.
<FilesMatch ".*\.phtml?$">
# Output Mode - 0..5, see OPTIONS section.
PerlSetEnv OUTMODE 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)
CGI
inserting first line to
#!/your/path/twepl
Wrapper
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
TIMEOUT
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);
mod_perl2
# set as new timeout.
alarm(($TIMEOUT=X));
# cancelling timeout and unset timeout.
alarm(($TIMEOUT=0));
CGI
# set as new timeout.
alarm(X);
Wrapper
before calling sub ep()
$HTML::EmbeddedPerl::TIMEOUT = X;
INTERNAL METHODS
_coloring
_extract_hash
_extract_array
_init
_run
handler
BASIC METHODS
ep
ep($string,$option);
new
$ep = HTML::EmbeddedPerl->new();
FOR CGI METHODS
flush
flushing HTTP header.
$ep->flush;
COMPATIBLE METHODS
it tiny-tiny solving cgi-modperl compatibility methods. use that $ep->method *inner code tags only.
header_out
$ep->header_out($key,$val);
content_type
$ep->content-type($type);
$ep->print($string);
OTHER METHODS
other methods define it freely.
mod_perl2
depends Apache::RequestRec and more.
EXPORTS
ep(string,option)
OPTIONS
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.
COMMENTS
# comments // comments /* comments */
please do not put comments if possible.
BETA Features
case of extract scalar in non-code blocks.
<$ my $scalar = 'this is scalar'; $>
<p>$scalar</p>
...
<p>this is scalar</p>
if you want not extract vars, please use escape sequence '\'.
<p>\$scalar</p>
...
<p>$scalar</p>
and available simple template.
Boolean Expression
<!=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-close, try ($a > $b) in compilation errors.
Extract Array
<@=ARRAYNAME>...</@>, extract value is $_. ARRAYNAME can use reference {ARRAYNAME} or \ARRAYNAME.
$n = current array name. $i = current position. $c = 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>
Extract Hash
<%=HASHNAME>...</%>, extract key is $k, value is $v. HASHNAME can use reference {HASHNAME} or \HASHNAME.
$n = current hash name. $c = equals scalar keys %hash;
and $XXX = want vars.
<$ my %hash = ('a'=>1,'b'=>2,'c'=>3); $>
<table>
<%=hash><tr><th>$k</th><td>$v</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>
AUTHOR
Twinkle Computing <twinkle@cpan.org>
COPYRIGHT
Copyright (c) 2010 Twinkle Computing All rights reserved.
LISENCE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.