The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

web-iPerl - bring Web-documents alive with bits of embedded Perl

DESCRIPTION

This is the webserver frontend of an inverse Perl interpreter, where HTML, XML, SGML, PostScript or plain text gets passed to the browser as is, while specially marked Perl statements are executed on the server-side. Loop or conditional blocks can surround normal text. The MIME-type is recognized by the file suffix according to the following table:

text/html

html, phtml, htmlp and pht, htp

text/css

css, pcss, cssp and pcs, csp

text/plain

All not found elsewhere, including txt, ptxt, txtp and ptx, txp

text/plain; charset=UTF-8

utxt, putxt, utxtp and put, utp

text/sgml

sgml, psgml, sgmlp and psg, sgp

text/vnd.wap.wml

wml, pwml, wmlp and pwm, wmp

text/xml

xml, pxml, xmlp and pxm, xmp

application/postscript

ps, pps, psp, eps, peps, epsp and pep, epp

image/x-xbitmap

xbm, pxbm, xbmp and pxb, xbp

image/x-xpixmap

xpm, pxpm, xpmp and pxp, xpp (not understood by most browsers)

The first plain text flushed out by web-iPerl is preceded by the value $header, which has been set for you. This means that if your document starts with a bit of Perl, the variable contains the HTTP-header and may be modified. Or you can unset it and write the header right after the Perl section - no newline in between though! Inversely you should not print any output before the header has been printed. Processing occurs in the directory where the file was found.

If you call any system-commands (beware of passing uncontrolled arguments from the query!) you should first turn on autoflushing ($| = 1) to ensure that output order is preserved.

VARIABLES

$header

Normally the empty string. Is output and reset every time iPerl wants to output a bit of plain text.

@type

Holds the list of arguments to CGI function header. This can help you change the header more easily, by adding you own options.

$header = header @type, ...;

INSTALLATION

The file-suffixes are freely electable as listed above. For Apache these are attributed to an internal MIME-type, which is then correlated to the web-iPerl interpreter by the action module, which must be installed in Apache. On these lines, which are the same for the three following alternatives, put all the suffixes you expect to use among those found above, under DESCRIPTION:

AddType application/x-web-iPerl pcss phtml pps ptxt putxt pps
DirectoryIndex index.html index.htm index.phtml index.pht

The installation depends on what you have, and what you want:

mod_perl

If you have mod_perl installed (which you should for remarkable performance gains!), this is the necessary configuration. The first part is possibly already done for you.

<Location /perl/>
  SetHandler perl-script
  PerlHandler Apache::Registry
  Options ExecCGI
  PerlSendHeader On
</Location>

You must copy web-iperl to the perl-directory in your web-server tree. Then you add the following line to your configuration:

Action application/x-web-iPerl /perl/web-iPerl
CGI

This is the classical mode of operation. You must copy web-iperl to the cgi-bin-directory in your web-server tree, which we assume to have been set up. Then you add the following line to your configuration:

Action application/x-web-iPerl /cgi-bin/web-iPerl

Warning: Due to the way the CGI mechanism works, this method can cause failure when running under full load. If the server already has as many processes running as one user is allowed by the system to spawn, starting this script will fail, making some page temporarily inservable. This means that the MAXUP kernel parameter should be somewhat higher than the maximum number of connections served.

NPH

This is another classical mode of operation. Unlike the preceding one, the server doesn't look at your output. The header funtion takes this into account by adding a HTTP-response line. On the downside, you yourself are responsible for everything else you want, like keep-alive negotiation.

You must copy web-iperl to the cgi-bin-directory in your web-server tree, which we assume to have been set up, and rename (as hard-wired in Apache) it to nph-iperl. Then you add the following line to your configuration:

Action application/x-web-iPerl /cgi-bin/nph-iPerl

Warning: Same as for CGI, just above.

SEE ALSO

Text::iPerl, iperl, iPerl.el, perl, apache, mod_perl, http://beam.to/iPerl/