Embperl のインストールメモ

CGIプログラミングの p.163 で紹介されてるモジュール。
なんかこのモジュール、日本語の情報が少ない気がする…。あまり使われてないのかな?


cpan で楽々インストール。

% cpan HTML::Embperl


インストールされたか確認するために use してみる。

% perl -MEmbperl -e ''


mod_perl が入ってない環境だと、embpcgi.pl という Embperl と一緒に配布される CGIスクリプトが必要みたいなので、検索してみる。

% sudo find / -name 'embpcgi.pl'
Password:
find: WARNING: Hard link count is wrong for /proc/1: this may be a bug in your filesystem driver.  Automatically turning on find's -noleaf option.  Earlier results may have failed to include directories that should have been searched.
/home/BigFatCat/.cpan/build/Embperl-2.3.0-hXEEBd/embpcgi.pl

警告が出てるけど、ここでは無視しとく。


embpcgi.pl を CGI の実行を許可しているディレクトリにコピーする。

% sudo cp /home/BigFatCat/.cpan/build/Embperl-2.3.0-hXEEBd/embpcgi.pl /var/www/cgi-bin/


テンプレートを書く(simple.epl)

<html>
  <head>
    <title>Embperl</title>
  </head>
  <body>

    <div align="center">
      <h1>Ebbperl を使って%ENVの内容一覧を表示</h1>

      [- $time = localtime -]

      <p>[+ $time +]のあなたからのリクエストに関する詳細を以下に示します:</p>

      <table border="1" cellpadding="4" width="400">
          <tr>
            <th>変数名</th>
            <th>値</th>
          </tr>

          [$ foreach (sort keys %ENV) $]
          <tr>
            <td><b>[+ $_ +]</b></td>
            <td>[+ $ENV{$_} +]</td>
          </tr>
          [$ endforeach $]
      </table>
    </div>

  </body>
</html>


最後に、ブラウザから「http://localhost/cgi-bin/embpcgi.pl/templates/simple.epl」にアクセスして実行する。

ひとりごと

CGI.pm は CGIプログラム から HTML を出力するけど、Embperl は HTML に CGIプログラムを埋め込むということだな。
なんか、Java でも同じような構図を見たことがある気がする…
JSPServlet っていうやつだっけ?