# HTML::EmbeddedPerl - The Perl embeddings for HTML

## INDEX

NAME
SYNOPSYS
run in the automatically
using in the script
DESCRIPTION
mod_perl2
CGI
Wrapper
TIMEOUT
mod_perl2
CGI
Wrapper
INTERNAL METHODS
BASIC METHODS
ep
new
METHODS FOR CGI
flush
header
echo
COMPATIBLE METHODS
header_out
content_type
print
printf
OTHER METHODS
mod_perl2
EXPORTS
OPTIONS
OPTION 1
OPTION 2
COMMENTS
Extract Vars
BETA Features
Extract Array
Extract Hash
Boolean Expression
AUTHOR
COPYRIGHT
LISENCE

# 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
> # 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)

## 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
> _extract_bool
> _extract_bool_unless
> _extract_tags
> _get_crlf
> _ignore_comments
> _init
> _run
> handler

# BASIC METHODS ↑

## ep

> ep($string,$option);

## new

> $ep = HTML::EmbeddedPerl->new();

# METHODS FOR CGI↑

## flush

flushing HTTP header.

> $ep->flush;

## header

PHP like method.

> header("$key: $val");

## echo

PHP like method.

> echo $string;

# COMPATIBLE METHODS ↑

it tiny-tiny solving cgi-modperl compatibility methods.

## header_out

> $ep->header_out($key,$val);

## content_type

> $ep->content-type($type);

## print

> $ep->print($string);

## printf

> $ep->printf($format,$string);

# OTHER METHODS ↑

other methods define it freely.

## mod_perl2

depends Apache::RequestRec and more.

# EXPORTS ↑

ep(string,option1,option2)

# OPTIONS ↑

ep(string,option1,option2)

## OPTION 1

0 = default, execute only once.
1 = -- with coloring source.
2 = older version compatible, every tags every execute.
3 = -- with coloring source.
4 = output internal code.
5 = -- with coloring source.
6 = output internal code to multiple-tags.
7 = -- with coloring source.

## OPTION 2

0 = default, not template mode.
1 = template mode.(use beta features)

# COMMENTS ↑

# comments
// comments
/* comments */

# Extract Vars ↑

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.

# BETA Features ↑

use this beta features needs set option.
or insert as first element in non-code blocks it.

<!--Y--> is ON
<!--N--> is OFF

default is off, because it was very slow.

## Extract Array

<@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>

## Extract Hash

<%HASHNAME>...</%> or <\%HASHREFNAME>...</%>, extract key is $kX, value is $vX.

X is nested depth;

$nX = current hash name.
$cX = equals scalar keys %hash;

and $XXX = want vars.

> <$ 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>

## Boolean Expression

<=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.

# 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.