Embedded perl

From SlackWiki
Jump to navigation Jump to search

How to Install Embedded Perl on Slackware 12.0

First, I installed mod_perl: Installing Mod_Perl.

Then, I used cpan to install Embed Perl. I ran "perl -MCPAN -e shell" and at the prompt typed "install Embperl". This prompted me for some dependencies, I had to do "install LWP" and then try "install Embperl" again. Eventually it worked.

I added these lines to the section for my virtual host in /etc/httpd/extra/httpd-vhost.conf (they could also be added in the main httpd.conf to apply to the whole server if desired):

#    PerlModule HTML::Embperl
    PerlModule Embperl
    <Directory /home/rgr/public_html/embperl>
        SetHandler perl-script
        Options ExecCGI
#       PerlHandler HTML::Embperl::handler
        PerlHandler Embperl::handler
    </Directory>

Note the parts that are commented out -- whose were in an online example I found, but they resulted in the "500 internal server error" message. I could see the detailed message in the apache error log, and perl was looking for HTML/Embperl.pm when it should have been looking for Embperl.pm.

After that I set up an example file (see the tutorial below) and successfully tested it.

Tutorial on Use

http://perl.apache.org/embperl/pod/intro/Intro.-page-3-.htm

Here is an example file I created in /home/rgr/public_html/embperl/test.pl (it actually should be in which ever directory you set to be handled via embperl in the httpd.conf file or httpd-vhosts.conf file):

<html>
<body>
First line.<br>
[- $a = 5 -] Some stuff! [- $b = 6 if ($a == 5) -]<br>
Now for some output:<br>
[+ $a +]  [+ $array[$b] +] [+ "A is $a" +]
</body>
<html>

And here is the output of http://localhost/embperl/test.html:

First line.
Some stuff!
Now for some output:
5 A is 5

Note that the code with [- -] is just run. The code with [+ +] is run, and the results are used to replace that part of the html file. You can also use [!  !] which is for code that should only be run once, such as function definitions. The perldoc documentation or the apache page linked above has more complete explanations and tutorials: http://perl.apache.org/embperl/