=head2 Why doesn't the following line work? [+ $var . "<b>". $foo . "</b>". $bar +] See what we mean? This is an Escaping & Unescaping problem for sure. You
need to escape <b> as ' <b> ' and you probably also need to read the
section on Escaping & Unescaping... =head2 I'm getting: "Glob not terminated at ..." This might be a problem with Escaping & Unescaping as well. =head2 My HTML is getting stripped out. Sounds like a problem with Escaping & Unescaping again! Unless, of course, you have already read the section on Escaping &
Unescaping, and it is still happening... Like if you are using optRawInput
and your HTML is _still_ being stripped out... =head2 I _am_ using optRawInput, and my HTML _is_ still being stripped out! Aha! Well that's different! Never mind.. It can be easy to accidentally set optRawInput too late in your code... Try setting it in an extra Perl block S<( [- $optRawInput = 1 -] )>
earlier in the code, or in the server config, and see if that doesn't
solve the problem... (optRawInput must be set before the block that
uses it begins, as the block which uses it shouldn't be translated). =head2 Help! I got a SIGSEGV! Ack! If Embperl is not compiled at server startup, it can cause error messages,
SEGfaults, core dumps, buffer overflow, etc - especially if you are
using another module inside an Embperl page. As far as anyone can tell,
this seems to be a Perl/mod_perl problem - but maybe not. If you have any
ideas, let me know. To see the steps for loading Embperl at server startup, please see the
section Downloading, Compiling & Installing. NOTE: When mod_perl is compiled with USE_DSO it behaves vice versa
and you may get SIGSEGVs when Embper is loaded at server startup time. =head2 I am having troubles with using Embperl in combination with
Apache::Include inside a Apache::Registry script. This is a known problem, but it is a problem with mod_perl rather than
with Embperl. It looks like mod_perl clears the request_rec after the
first subrequest, so that it later doesn't know which subrequest was
intended (unless it's explicitly specified). Try using: Apache::Include->virtual("test.epl", $r);(instead of just Apache::Include->virtual("test.epl");
where $r is the apache request rec) =head2 I can't get PerlSendHeader to work under Embperl? You don't need PerlSendHeader when using Embperl - Embperl always sends
its own httpd header. =head2 But how do I customize the header that Embperl is sending? You'll find the answer to this and many other header issues in
the Common Questions section. =head2 I can't figure out how to split a 'while' statement across
two [- -] segments That isn't surprising, as you cannot split Perl statements across multiple
[- -] blocks in Embperl :) You need to use a metacommand for that. The [$while$]
metacommand comes to mind... :) For a list of all possible metacommands, see the section on
Meta-Commands in the Embperl documentation. [$ while $st -> fetch $]
#some html or other Embperl blocks goes here
[$ endwhile $]Newer Embperl versions (1.2b3 and above) supports the [* *] which can be
used for such purposes. [* while ($st -> fetch) { *]
#some html or other Embperl blocks goes here
[* } *]While the later can use all Perl control structures, the first seems to
me more readable and is better debugable, because Embperl controls the
execution of the control structure it can do a quite better job in debug
logging. =head2 My HTML tags like '<' '>' and '"' are being translated to <, > !!! Hey! Not you again!? I thought we already sent you to the
Escaping & Unescaping section of the FAQ?!?! ;) =head2 Netscape asks to reload the document If you have something like this in your source, it may be the problem: <META HTTP-EQUIV="content-type" CONTENT="text/html;charset=iso-8859-1"> Netscape seems to have a problem in such cases, because the http header is
only content-type text/html, while the META HTTP-EQUIV has an additional
charset specified. If you turn optEarlyHttpHeader off, Embperl will
automatically set the http header to be the same as the META HTTP-EQUIV. =head2 I get "Stack underflow" The problem often occurs, when you have a <table> tag in one file and a </table>
tag in another file and you both include them in a main page (e.g. as header
and footer). There are two workarounds for this problem: | 1. Set optDisableTableScan | | | This will avoid that Embperl takes any action on tables. You can disable/enable
this (also multiple times) inside the page with [- $optDisableTableScan = 1 -] If you put this at the top of your header/footer which you include with Execute,
then the main page will still process dynamic tables. |  | | 2. Add a <table> as comment | | | Add the following to the top of
the footer document: <!-- <table><tr><td> --> This will work also, because Embperl (1.x) will not scan for html comments |  |
=head1 Common Questions The most common questions of all deal with Escaping
& Unescaping - they are so common that the whole next section is
devoted to them. Less common questions are addressed here: =head2 How can I get my HTML files to be converted into Perl code which, as a
whole, could then be compiled as function so that I could, for
instance, fetch Perl docs from the Formatter table and compile them the
way AUTOLOAD does. Embperl cannot covert your HTML into one piece of Perl-code, but you can
wrap the call to Execute into a Perl function and let AUTOLOAD call it. =head2 I have an HTML page which is dynamically generated at runtime
and should be post-processed by Embperl. How can I do this? | 1.) Generate the page within a normal CGI/Apache::Registry script and
put the result into a scalar - then you can call HTML::Embperl::Execute to
post-process your document. Execute can either send the document to the
browser or put it into another scalar for further processing. | | 2.) Use EMBPERL_INPUT_FUNC (1.1b1 and above). With this configuration
directive, you can specify a custom input function which reads the
HTML source from the disk or even from a database. Embperl also
provides the function ProxyInput, which allows you to get input from
another web server altogether. | | 3.) Look at the module Apache::EmbperlChain, which is able to chain
multiple modules, including Embperl, together. |
=head2 How can I customise the header that Embperl is sending? You can write it as <meta http-equiv="Content-Type" content="text/html"> (Embperl will automatically insert all meta http-equiv tags into the http
header) or use %http_headers_out [- $http_headers_out{'Content-Type'} = 'text/html' -]or (only when running under mod_perl) you can use [- $req_rec -> content_type ('text/html') -]=head2 Can I use Embperl to send cookies? Yes. Embperl sends its own headers, so all you have to do to send cookies
is to remember to print an additional header. Example Code: NOTE: You make also take a look at Embperls (1.2b2 and above) ability to
handle sessions for you inside the %udat and %mdat hashes. =head2 Can I do a Redirect with Embperl? The following way works with mod_perl and as cgi: [- $http_headers_out{'Location'} = "http://www.ecos.de/embperl/" -]the status of the request will automaticly set to 301. or use the mod_perl function Apache::header_out. Example Code: [-
use Apache;
use Apache::Constants qw(REDIRECT);
$req_rec->header_out("Location" => "http://$ENV{HTTP_HOST}/specials/");
$req_rec->status(REDIRECT);
-]If there is nothing more to do on this page, you may call exit directly
after setting the status. =head2 Can I serve random GIFs with Embperl?
(Will Lincoln Stein's GD.pm module work with Embperl??) As always, there is more than one way to do this - especially as this
is more of a question of how you are coding your HTML than how you
are coding your Embperl. Here are some ideas: | 1.) You could include an IMG tag which points to your cgi-bin, where
a regular CGI script serves the graphics. | | 2.) You could be running Apache::Registry, which can generate
on-the-fly GIFs using GD. (This is just the same as if you were including
the GD image from a static page or from another CGI script, but it allows
all of the appropriate logic to live in a single document, which might be
appropriate for some Embperl users). |
If you think of another way, or come up with some sample code, I'd
love to hear from you, so that I could add it to the FAQ... =head2 Can I use Embperl as a template for forms?
Can I make form values persist (like with "vanilla" CGI)?
Does Embperl rewrite my template file so that parameters of things like
INPUT/TEXTAREA/SELECT persist? Yes. Your page design staff should just be able to say <input name="foo">
and let the default attributes of "foo" be defined elsewhere - for
instance in a settings file. In this case, %fdat should be pre-set with
your default values. Setting $fdat{foo} = "abc" will cause Embperl to
change the above code to <input name="foo" value="abc">. =head2 Does Embperl automatically add HIDDEN fields? The [$hidden$] metacommand creates hidden fields for every entry in %fdat
which was not used by any other input tag so far. You can also try something like this: [-
$fdat{foo} = "abc" ;
$fdat{bar} = "xyz" ;
-] <input name="foo">
[$hidden$]and Embperl will create: <input name="foo" value="abc">
<input type=hidden name="bar" value="xyz">For a list of all possible metacommands, see the section on
Meta-Commands in the Embperl documentation. =head2 What about security? Is Embperl Secure? Just like anything else, Embperl is as secure as you make it. Embperl
incorporates Safe.pm, which will make it impossible to accidentally access
other Packages - it also permits the Administrator to disable Perl
opcodes, etc. For more on security, please see Embperl/(Safe-)Namespaces and opcode restrictions in the Embperl
documentation. =head2 Is there any plan to make Embperl an Object so someone could subclass it
and override certain of its methods? (For example, I'd like to let it
parse the file for me, but then let me control the manipulation of the
form tags.) Embperl is going to be an Object from version 1.2b1. This,
among other things, make it re-entrant, so that you will be able to
call Execute from within an Embperl page. It will also mean that
Embperl will come with hooks, which will allow you to alter or change
the way Embperl processes code. The details have not all been worked
out yet, but I'm working on it... :) =head2 Are Embperl routines currently pre-compiled or even cached, or are only
fragments cached? All embedded Perl code is compiled the first time it is executed and
cached for later use. The second time the code is executed, only the
precompiled p-code is called. Every code block is compiled as a single subroutine. The HTML text between
the Perl block is still read from the file. =head2 Why are Perl blocks broken up into single subroutines? | 1.) It makes it easier to process the HTML tags between the Perl blocks -
this gives you more control over what's happening | | 2.) If you compiled _everything_ to Perl, you would hold all of the
HTML text in memory, and your Apache child processes would grow and
grow... But often-accessed documents are still held in memory by
your os disk cache, which is much more memory-efficient. | | 3.) There is only so far that you can go with precompiling until you reach
the point of diminishing returns. My guess is that converting dynamic
tables and other HTML processing to Perl at this point in Embperl's
development would actually slow down operation. |
=head2 Can I pass QUERY_STRING information to an HTML::Embperl::Execute call? With Embperl 1.0 and higher, you can do this. QUERY_STRING is set as
$ENV{QUERY_STRING} by default. Alternatively, you can use the fdat
parameter to pass values to %fdat. =head2 How to include other files into Embperl pages? I am using embedded Perl on my site and am curious if I can use it for
server side includes. I want to embed the contents of file x.html into
file y.html such that whenever I change x.html, displaying y.html will
also reflect this change. How do I do it using embedded perl? You need Embperl 1.2b4 or above. Then you can say inside of y.html: [- Execute ('x.html') -]=head2 EmbPerl iteration without indexing I have a rather large table in a database which I'd like to display using
EmbPerl. All of the examples show a process of fetching all the data
first,
then iterating through it using $row and $col, like this: [-
$sth = $dbh -> prepare ("select * from $comptbl order by SubSystem");
$sth -> execute;
$dref = $sth -> fetchall_arrayref;
-]
<TABLE>
... $dref -> [$row][0] ...
</TABLE>I'd prefer to fetch the data one row at a time, how can I do this? For solution 1 you may write <table>
[$while $rref = $sth -> fetch $]
<tr>....</tr>
[$endwhile$]
</table>Solution 2 should work like this <table>
<tr> [- $dummy = $row ; $rref = $sth -> fetch -]
....
</tr>
</table>The table ends when the expression where $row is used in some way returns
<undef>. So also there is no releation between $row and the fetch, both
conditions are met. =head2 How to display arrays with undef values in it?
I'm doing a search on a table where some of the columns have NULL and
non-NULL values. DBIx::Recordset has no problem reading this values
The problem is that I then tried to print these values
out in a table using Embperl's table feature, like this.
<TABLE>
<TR>
<TD>$set[$row]{column_name1}</TD>
<TD>$set[$row]{column_nameN}</TD>
</TR>
The problem is that I got 5 rows instead of the 15 that I was expected. I
have been trying all kinds of tweaks to the arguments to the Search
function and getting nowwhere, until I re-read the Embperl docs. Embperl
will not print out a table row if one of the columns has an
expression that
is undefined. This is a problem since DBIx::Recordset (and DBI)
natually uses undef to represent a NULL value for a column. So I made a
slight modification to my embperl code.
<TABLE>
<TR>
<TD>defined($set[$row]{column_name1}) ? $set[$row]{column_name1} :
"UNDEF"</TD>
. . .
<TD>$set[$row]{column_nameN} ? $set[$row]{column_nameN} : "UNDEF"</TD>
</TR>
Now all 15 rows appear as expected, with "UNDEF" representing the NULL
values in the database.Another way top solve you problem may be: <TABLE>
<TR>
[- $r = $set[$row] -]
<TD> [+ $r -> {column_name1} +] </TD>
. . .
<TD> [+ $r -> {column_nameN} +] </TD>
</TR>This will only refer one time to $row and the expression is defined,
as long as the row could be fetched from the db. All NULL fields will
be displayed as empty table cells. =head1 Escaping & Unescaping =head2 Escaping & Unescaping Input By default, Embperl removes all HTML tags from the Perl source. It does
this because many high-end WYSIWYG HTML Editors (like MS Front Page)
insert HTML tags like <FONT> and <COLOR> in rather random places (like in
the middle of your Perl code). This Embperl feature keeps things like [- $var = 1; <br>
$foo = 2 -]permissable, so that you can enter Perl code while you mark up pages in an
editor, all at once. In this example, Embperl would remove the
unnecessary <br> tag and, therefore, make Perl happy. And if Perl is
happy, we are all happy. It is not difficult to change this behavior, if you are the kind
of person who codes HTML in an ascii editor (like vi or emacs). If you use a high-level HTML editor, you shouldn't have any problems
with input escaping, because the editor will, for example, write a '<' as
'<' in the HTML code. Embperl translates this back to '<' and therefore
it knows that this wasn't an HTML tag which should be removed. Problems with input escaping only occur if you use an ascii
editor. Then you will need to escape input (see the next section
for details on how to do this). To see the exact steps taken by Embperl to process a Perl-laden document,
please see the section Inside Embperl in the Embperl documentation. =head2 Ways To Escape Input: | 1. Escape it -> \<H1> | | | NOTE: Inside double quotes you will need to use \\ (double backslash),
since Perl will remove the first Escape itself. Example: In most cases '\<tr>' but inside double-quotes "\\<tr>" |  | | 2. Turn off Escaping for all input by setting the optRawInput in
EMBPERL_OPTIONS | | 3. Learn to avoid using HTML tags inside Perl code. Once you get the hang
of it, you'll love it. |
Here is one example of how to do it: [- $output = "<bold>Hello world</bold>" -]
[+ $output +]write [- $output = "Hello world<bold>" -] this outputs Hello world or <bold>[+ $output +]</bold> this outputs <bold>Hello world</bold> And here is another example of how to do it: [-
@a = ('a', 'b', 'c') ;
foreach $i (0..2)
{
$output. = "<tr><td>Row $a[$i]</td></tr>" ;
}
-]
<table>
[+ $output +]
</table>The output here would be: <table>Row aRow bRow c</table> The Embperl version is [-
@a = ('a', 'b', 'c') ;
-]
<table>
<tr><td>Row [+ $a[$row] +]</td></tr>" ;
</table>The output will be <table>
<tr><td>Row a</td></tr>" ;
<tr><td>Row b</td></tr>" ;
<tr><td>Row c</td></tr>" ;
</table>And another: This elegant solution shows you how to take advantage of
Embperl's ability to create dynamic tables: [-
use DBI;
my $dbh =
DBI->connect("DBI:mysql:database:localhost","Username","Password") ||
die($!);
$hstmt = $dbh->prepare("select ID, Heading from Shops order by Heading");
$hstmt->execute();
$dat = $hstmt->fetchall_arrayref() ;
$hstmt->finish();
$dbh->disconnect();
-]
<table border=1>
<tr><td>[+ $$dat[$row][$col] +]</td></tr>
</table>This HTML code will then display the contents of the whole array. =head2 Escaping & Unescaping Output Embperl will also escape the output - so <H1> will be translated to
<H1> To see the exact steps taken by Embperl to process a Perl-laden document,
please see Inside Embperl in the Embperl documentation. =head2 Ways To Escape Output: | 1.) Escape it -> \\<H1> | | | (You need a double backslash \\, because
the first one is removed by Perl and the second by Embperl. |  | | 2.) set $escmode = 0 -> [- $escmode = 0 ; -] | | 3.) set SetEnv EMBPERL_ESCMODE 0 in your srm.conf |
=head1 Debugging =head2 I am having a hard time debugging Embperl code Have you, umm, checked the error log? ;) Have you tried setting debug flags higher by resetting EMBPERL_DEBUG in
the server config files? (And still higher? :) dbgMem isn't usually very useful as it always outputs a lot of allocation.
dbgFlushLog and dbgFlushOutput should be used if (and only if) you are
debugging SIGSEGVs. For easy debugging, you can tell Embperl to display a link at the top of
each page to your log file. Then every error displayed in an error page is
a link to the corresponding position in the logfile, so you can easily
find the place where something is going wrong For more on using HTML links to the Embperl error log, see
Embperl/EMBPERL_DEBUG in the Embperldocs. =head2 Embperl is running slow. There are some debugging settings which may cause Embperl to drastically
slow down. If you are done with debugging, set debugging bits back
to normal. Also, using dbgFlushLog and dbgFlushOutput will make execution much
slower. These are only intended for debugging SIGSEGVs. Never set all debugging bits! =head2 How can I improve Embperl's performance? | 1.) Load Embperl at server startup. This will cause
UNIX systems to only allocate memory once, and not
for each child process. This reduces memory use,
especially the need to swap additional memory. | | 2.) Disable all unneeded debugging flags. You should never set
dbgFlushLog dbgFlushOutput, dbgMem and dbgEvalNoCache in a
production environment. | | 3.) You may also want to take a look at the available options
you can set via EMBPERL_OPTIONS. For example optDisableChdir, will
speed up processing because it avoid the change directory before
every request. |
=head1 Customizing =head2 How can I fiddle with the default values?
How can I override or alter this or that behavior? Usually, defaults are set in a way that is likely to make most sense for a
majority of users. As of version 1.0, Embperl allows much more flexibility
in tweaking your own default values than before. Take a look at EMBERPL_OPTIONS. =head2 I'd like to (temporarily) disable some of Embperl's features.
What can be customized? | 1.) Use optDisableHtmlScan to disable processing of html tags.
If this is set, Embperl will only pay attention to these types of
constructs: | | | S<[+/-/!/$ .... $/!/-/+]> |  | | 2.) optDisableTableScan, optDisableInputScan and optDisableMetaScan can be
used to disable individual parts of HTML processing. | | | You may set these flags in your server config, or at runtime: [+ $optDisableHtmlScan = 1 +]
<table> foo </table>
[+ $optDisableHtmlScan = 0 +] |  |
=head2 How can I disable auto-tables? Set optDisableTableScan in EMBPERL_OPTIONS =head2 How can I change predefined values like $escmode from my Toolbox module? $HTML::Embperl::escmode = 0 ; Predefined values in Embperl are simply aliases for $HTML::Embperl::foo
(for instance, $Z<>escmode is an alias for $HTML::Embperl::escmode) =head2 How can I customize the header that Embperl is sending? You'll find the answer to this and many other header issues in
the Common Questions section. =head2 How can I use a different character set?
ASCII values over 128 are showing up as ? (question marks)! This is caused by the translation of characters to HTML escapes. Embperl
translates them to escapes which are then sometimes not understood by the
browser, which may display a "?" instead, because it is using the wrong
character set. If you want to use the escaping features of Embperl in this case, you have
to adapt the file epchar.c to your character set. The distribution contain already an epchar.c.iso-latin-2 from Jiri Novak which
is an replacement for epchar.c for the iso-8859-2 (iso-latin-2) character set.
If you want to use iso-latin-2, simply renmae epchar.c.iso-latin-2 to epchar.c.
There is also an file epchar.c.min from Sangmook Yi, which leaves all
chars above 128 untouch, which is especialy usefull for two byte charsets. This file contains three tables: Char2Html [] Convert characters to html escape Char2Url [] Convert characters to url escapes (do not change this one!!) Html2Char [] Convert html escapes to characters You need to change the first and the last tables. Do not change the second
table!! Please make sure Char2Html contains one entry (and only one entry) for
each of the 256 ascii codes (with none left undefined) in
the right order, and that Html2Char is sorted by html escape. If somebody generates new tables for national character sets, please send
a copy to the author, so it can be included it in future versions of
Embperl. =head1 Optimizing & Fine-Tuning =head2 How can I be sure that Embperl is re-compiling my page template
(and the Perl blocks contained in it) only when needed, and not each time? As long as your input file's time stamp stays the same, Embperl will
only compile the script the first time it's called. When you use
the Execute function, Embperl will recompile the script only if
the input file and mtime paramenters have changed since the last
time the script was called. You can verfiy this by setting dbgDefEval. Now, every time a Perl block is
compiled, Embperl logs a line starting with DEF:. You will see this line
only on the first request. The cached Perl blocks are stored as a set of
subroutines in the namespace of the document. (HTML::Embperl::DOC::_<n> is
the default) Look at the logfile to see the actual name. =head2 How can I pre-compile pages, so that each httpd child doesn't
have to have its own separate copies of the pre-compiled pages? To pre-compile pages, just call Execute once for every file at server
startup in your startup.pl file. =head2 In what namespace does Embperl store pre-compiled data? The cached Perl blocks are stored as a set of subroutines in the namespace
of the document. (HTML::Embperl::DOC::_<n> for default) Look at the logfile
to see the actual name. =head2 I have both Embperl and ordinary Perl processes running. The docs
say that Embperl uses a CGI.pm instance in its own internal processing,
but they don't say how to control it. How can I get Embperl to use *my*
CGI.pm object instead of creating its own? Embperl only creates a CGI objects to process multipart form data (from
fileupload). In all other cases Embperl doesn't use CGI.pm. There is no
way to change this behaviour, or access the internal CGI object in case
of file-uploads. =head1 Additional Help =head2 Where can I get more help? You can get free support on the mod_perl mailing list. If you need
commercial support (with a guarantee for response time or a solution) for
Embperl, or if you want a web site where you can run your Embperl/mod_perl
scripts without setting up your own web server, please send email to
info@ecos.de. Please also see the section Embperl/Support in the Embperl documentation. =head1 SEE ALSO some links here =head1 AUTHOR Gerald Richter <richter@ecos.de> Edited by Nora Mikes <nora@radio.cz> |