=head1 NAME
HTML::Embperl - Building dynamic Websites with Perl
=head1 SYNOPSIS
=head1 DESCRIPTION
Embperl is a Perl extension module which gives you the power to
embed Perl code directly in your HTML documents (like server-side
includes for shell commands).
If building more than a single page, you may also want to take a look
at L<"perldoc EmbperlObject"|"EmbperlObject.pod"> which
lets you build your website out of small reusable objects.
Additionally, L<"perldoc HTML::Embperl::Mail"|"Mail.pod"> allows
you to send the resulting page via email.
=head1 Operating-Modes
Embperl can operate in one of four modes:
=head2 Offline
Converts an HTML file with embedded Perl statements into a standard
HTML file.
B
B
Use embpexec.pl on Unix systems and embpexec.bat on Win32 systems.
=over 4
=item B
The full pathname of the HTML file which should be processed by
Embperl.
=item B
Optional. Has the same meaning as the environment variable
QUERY_STRING when invoked as a CGI script. That is, QUERY_STRING
contains everything following the first "?" in a URL.
should be URL-encoded. The default is no query string.
=item B<-o outputfile>
Optional. Gives the filename to which the output is written. The
default is stdout.
=item B<-l logfile>
Optional. Gives the filename of the logfile. The default is
/tmp/embperl.log.
=item B<-d debugflags>
Optional. Specifies the level of debugging (what is written to the
log file). The default is nothing. See L<"EMBPERL_DEBUG"> for exact values.
=back
=head2 As a CGI script
Instead of a file being sent directly by the web server, the document
is processed by the CGI script and the result is sent to the client.
B
B
Use embpcgi.pl on Unix systems and embpcgi.bat on Win32 systems.
You can also run Embperl with B, in this case use embpfastcgi.pl
as cgi script. You must have FCGI.pm installed.
If C is invoked without any parameters and the
environment variable B is set, it runs itself as a CGI
script. This means that form data is taken either from the
environment variable B or from stdin, depending on whether
or not B is set. (This will be set by the web server
depending on whether the request method is GET or POST). Input is
taken from the file pointed to by B and the output is
send to stdout. The logfile is generated at its default location,
which is configurable via the environment variable B.
To use this mode you must copy B to your cgi-bin
directory. You can invoke it with the URL
http://www.domain.xyz/cgi-bin/embpcgi.pl/url/of/your/document.
The /url/of/your/document will be passed to Embperl by the web server.
Normal processing (aliasing, etc.) takes place before the URI makes it
to PATH_TRANSLATED.
If you are running the Apache httpd, you can also define
B as a handler for a specific file extension or
directory.
Example of Apache C:
Action text/html /cgi-bin/embperl/embpcgi.pl
B: For security reasons, embpexec.pl must not be used as a
CGI script anymore!
B: CGI Scripts are not so secure. You should consider using L
to restrict access.
=head2 From mod_perl (Apache httpd)
This works like the CGI-Script, but with the advantage that the script
is compiled only once at server startup, where other one-time actions
(such as opening files and databases) can take place. This will
drastically reduce response times for the request. To use this you
must compile C with C and add C
as the C.
Example of Apache C or C:
SetEnv EMBPERL_DEBUG 2285
Alias /embperl /path/to/embperl/eg
SetHandler perl-script
PerlHandler HTML::Embperl
Options ExecCGI
Another possible setup is
SetEnv EMBPERL_DEBUG 2285
SetHandler perl-script
PerlHandler HTML::Embperl
Options ExecCGI
AddType text/html .epl
Don't forget the B. In this setup, all files ending with
.epl are processed by Embperl.
See the section L<"EMBPERL_DEBUG"> (dbgLogLink and EMBPERL_VIRTLOG) to find
out how you can configure Embperl so you can view the log file with
your browser!
B: When mod_perl is compiled as loadable module (i.e. with USE_DSO) you
B load Embperl at server startup time!
B: L<"perldoc EmbperlObject"|"EmbperlObject.pod"> to see how to setup I so as to
create your site out of small overwriteable objects.
=head2 By calling HTML::Embperl::Execute (\%param)
Execute can be used to call Embperl from your own modules/scripts (for example
from a Apache::Registry or CGI script) or from within another Embperl page (only 1.2b1
or higher) to nest multiple Embperl pages (for example to store a common header or
footer in a different file).
There are two forms you can use for calling Execute. A short form which only takes a
filename and optional additional parameters or a long form which
takes a hash reference as its argument. This gives it the chance to
vary the parameters according to the job that should be done.
(See B for more detailed examples)
B: L<"perldoc EmbperlObject"|"EmbperlObject.pod"> to see how to setup I so as to
create your site out of small overwriteable objects and L<"perldoc HTML::Embperl::Mail"|"Mail.pod"> on how
to use I to send email.
Execute($filename, $p1, $p2, $pn) ;
This will cause Embperl to interpret the file with the name $filename and, if specified, pass
any additional parameters in the array @Z<>param (just like @_ in a perl subroutine).
The above example could also be written in the long form:
Execute ({inputfile => $filename,
param => [$p1, $p2, $pn]}) ;
The possible items for hash of the long form are:
=over 4
=item B
The file which should be used as source. If B is also specified,
this parameter should be given a unique name to identify the source.
Every time Embperl sees the same text in B, it assumes that
you compiled the same source - that means that Embperl uses the same package
name as in your last call, and only recompiles the code if B has
changed or is undefined.
=item B
Call the Embperl subroutine named by this parameter(see also B<"[$ sub $]">).
Currently the subroutine
must be in the same file or if it's in another file, the other file has to be
imported first.
=item B
Reference to a string which contains the source. B must also
be specified to give a name for the source. The name can be any text.
=item B
Last modification time of member B. If undef the code passed
by input is always recompiled, else the code is only recompiled if
mtime changes.
=item B
File to which the output should be written. If neither outputfile
nor output is specified, ouput is written to stdout.
=item B