Similar to Active Server Pages, or .asp files on Microsoft
Internet Information Server, the Embed
function of PerlEx brings the
functionality of Server Side Includes to your Perl CGI programs. Perl code
contained in an Embed
file is virtually "transparent" to your HTML editor,
so you can edit the HTML in the file with relative ease and immediately see
what the page will look like in a browser.
During installation, the following entries are created in your registry:
[HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PerlEx] CurrentVersion = <version> (REG_SZ) [HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PerlEx/<version>/Embed/.aspl] [HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PerlEx/<version>/Embed/.aspl] begin = "<%" (REG_SZ) [HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PerlEx/<version>/Embed/.aspl] end = "%>" (REG_SZ) [HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PerlEx/<version>/Embed/.aspl] decode = 0 (REG_DWORD)
In the following example, when the server encounters a file with the .aspl extension, it is passed to PerlEx for processing. The begin string value defines the characters which mark or tag the beginning of a segment of Perl code. The end string value defines the characters that indicate the end of a segment of Perl code. The decode DWORD value defines whether PerlEx decodes the files or not. This is useful if you are using an HTML editor that converts characters to their escaped equivalents. In the .aspl example, some editors may convert the ">" characters to ">" within the Perl code segments. The decode DWORD value can take the values of 0 and 1. In the .aspl example, the value is set to 0, or off.
.aspl is just an example. Using its structure as a basis, you can add your
own Embed
implementation to the registry, and have PerlEx process it similarly
to how it processes .aspl files.
All standard Perl constructs are allowed within the Perl sections. Also, the "="
character has a special function when it immediately follows the begin tag. In
the case of <%=$x+4%>
, the expression $x+4
is converted from
<%=$x+4%>
to print $x+4;
.
A short example of the Embed
function using the .aspl instance is listed
below:
# file embedTest.aspl <Html> <head><title>Embed Demo</title></head> <body bgcolor=ffffff> <bold>Counting from 0 to 4!</bold><br> <% # perl code foreach $i (0..4) { # starts a small loop %> <br> <%=$i%> #loop variable is printed for each number from 0 to 4 <% } # end of loop %> <br> <pre> Finished! </pre> </html>
The output of the above file will look like:
Counting from 0 to 4!
0 #loop variable is printed for each number from 0 to 4 1 #loop variable is printed for each number from 0 to 4 2 #loop variable is printed for each number from 0 to 4 3 #loop variable is printed for each number from 0 to 4 4 #loop variable is printed for each number from 0 to 4 Finished!
NOTE: Support for script embedding is currently not available when script caching is disabled by running PerlEx in zero interpreter mode.