<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>platform agnostic &#187; perl</title>
	<atom:link href="http://www.deepakg.com/prog/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deepakg.com/prog</link>
	<description></description>
	<lastBuildDate>Tue, 29 Jun 2010 19:08:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Hacking Chrome Developer Tools Protocol for fun and profit</title>
		<link>http://www.deepakg.com/prog/2010/06/hacking-chrome-developer-tools-protocol-for-fun-and-profit/</link>
		<comments>http://www.deepakg.com/prog/2010/06/hacking-chrome-developer-tools-protocol-for-fun-and-profit/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 17:49:40 +0000</pubDate>
		<dc:creator>deepakg</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.deepakg.com/prog/?p=116</guid>
		<description><![CDATA[I recently came across a tip on Hacker News which along with Firefox, MozRepl plugin and this snippet: autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_firefox() function! Refresh_firefox() if &#38;modified write silent !echo 'vimYo = content.window.pageYOffset; \ vimXo = content.window.pageXOffset; \ BrowserReload(); \ content.window.scrollTo(vimXo,vimYo); \ repl.quit();' &#124; \ nc localhost 4242 2&#62;&#38;1 &#62; /dev/null endif endfunction allows you [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across a tip on <a href="http://news.ycombinator.com/">Hacker News</a> which along with Firefox, <a href="http://wiki.github.com/bard/mozrepl/">MozRepl plugin</a> and <a href="http://vim.wikia.com/wiki/Refresh_Firefox_%28preserving_scroll%29_on_Vim_save,_using_MozRepl">this snippet</a>:</p>
<pre>autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_firefox()
function! Refresh_firefox()
  if &amp;modified
    write
    silent !echo  'vimYo = content.window.pageYOffset;
                 \ vimXo = content.window.pageXOffset;
                 \ BrowserReload();
                 \ content.window.scrollTo(vimXo,vimYo);
                 \ repl.quit();'  |
                 \ nc localhost 4242 2&gt;&amp;1 &gt; /dev/null
  endif
endfunction
</pre>
<p>allows you to refresh a tab in Firefox the moment you save your edits in Vim. No longer do you need to switch to Firefox, hit refresh to see the edits and then come back to your work. This is especially useful when you are on a multi-monitor setup.</p>
<p>My primary browser these days is Google Chrome. I was wondering if such a thing would be possible with Chrome too. It so happens it is. If you start Chrome with &#8211;remote-shell-port=9222 switch (on my Mac I do it like this: ~/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome &#8211;remote-shell-port=9222), you can connect to it using a TCP socket over port 9222 and then issue it commands using <a href="http://code.google.com/p/chromedevtools/wiki/ChromeDevToolsProtocol">Chrome Dev Tools Protocol</a>.</p>
<p>I wrote a small <a href="/prog/code/ChromeTool.pm">Perl wrapper</a> around the protocol and then wrote another simple script that simply refreshes the last open tab in your browser:</p>
<pre>
#refresh.pl

use strict;
use ChromeTool;

my $chrome = ChromeTool->new;
if($chrome) {
    my $tabs = $chrome->tabs;
    if(scalar(@$tabs) > 0) {
        $chrome->eval($tabs->[-1]->[0],
                                 "javascript:window.location.reload()");
    }
}
</pre>
<p>I modified the original Vim snippet mentioned above so that each time I save my code, both the browsers get auto-refreshed:</p>
<pre>
autocmd BufWriteCmd *.html,*.htm,*.css,*.gtpl,*.tt2 :call Refresh_firefox()
function! Refresh_firefox()
  if &#038;modified
    write
    silent !echo  'vimYo = content.window.pageYOffset;
                 \ vimXo = content.window.pageXOffset;
                 \ BrowserReload();
                 \ content.window.scrollTo(vimXo,vimYo);
                 \ repl.quit();'  |
                 \ nc localhost 4242 2>&#038;1 > /dev/null

    <b>silent !perl -I/Users/deepakg/Projects /Users/deepakg/Projects/refresh.pl</b>
  endif
endfunction
</pre>
<p>Of course, you&#8217;ll need to change /Users/deepakg/Projects to where you save the ChromeTool.pm file and refresh.pl. Here is a quick screencast showing this in action:</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/AizqXBAiQy4&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/AizqXBAiQy4&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p><b>Credits:</b> I learned about existence of Chrome Developer Tools Protocol from <a href="http://blog.8-p.info/2009/11/chrome-repl">this post</a>. You can also find link to a Ruby REPL client for talking to Chrome on the same page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deepakg.com/prog/2010/06/hacking-chrome-developer-tools-protocol-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		</item>
		<item>
		<title>Number-only Captcha</title>
		<link>http://www.deepakg.com/prog/2009/11/number-only-captcha/</link>
		<comments>http://www.deepakg.com/prog/2009/11/number-only-captcha/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 13:27:41 +0000</pubDate>
		<dc:creator>deepakg</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://www.deepakg.com/prog/?p=84</guid>
		<description><![CDATA[I was recently looking for a Perl Captcha implementation that&#8217;d generate number-only Captchas. I looked inside Authen::Captcha and figured I could subclass it do just numeric captchas. It turned out to be a lot simpler than I thought it would be. Here is the code: package Authen::NumCaptcha; use strict; use base qw(Authen::Captcha); sub new { [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently looking for a Perl Captcha implementation that&#8217;d generate number-only Captchas. I looked inside Authen::Captcha and figured I could subclass it do just numeric captchas. It turned out to be a lot simpler than I thought it would be. Here is the code:</p>
<pre>
package Authen::NumCaptcha;

use strict;
use base qw(Authen::Captcha);

sub new {
    my $class = shift;
    my $captcha = $class->SUPER::new( @_ );
    return bless $captcha, $class;
}

sub generate_random_string {
    my $self = shift;
    my $length = shift;

    my $code = "";
    my $char;

    for (my $i=0; $i < $length; $i++) {
        $char = int(rand 7)+50;
        $char = chr($char);
        $code .= $char;
    }

    return $code;
}

1;
</pre>
<p>We basically override Authen::Captcha's generate_random_string and only use ASCII characters 50 to 57 (digits 2 to 9). Authen::Captcha doesn't include the digits 0 and 1 because they could be confused with oh (O) and lower case elle (l) or upper case ai (I). </p>
<p>To use Authen::NumCaptcha, place it under /usr/share/perl5/Authen/ (or wherever you have Authen::Captcha installed) alongside Captcha.pm. Then use it as you'd use Auhten::Captcha. For example:</p>
<pre>
use Authen::NumCaptcha;

my $num_chars = 6;
my $num_captcha = Authen::NumCaptcha->new (
                                          data_folder => '/tmp',
                                          output_folder => '/tmp'
                                          );

my $num_md5sum = $num_captcha->generate_code($num_chars);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.deepakg.com/prog/2009/11/number-only-captcha/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		</item>
		<item>
		<title>PerlAuthenHandler</title>
		<link>http://www.deepakg.com/prog/2009/02/perlauthenhandler/</link>
		<comments>http://www.deepakg.com/prog/2009/02/perlauthenhandler/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 17:44:12 +0000</pubDate>
		<dc:creator>deepakg</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[mod_perl]]></category>
		<category><![CDATA[PerlAuthenHandler]]></category>

		<guid isPermaLink="false">http://www.deepakg.com/prog/?p=61</guid>
		<description><![CDATA[Among other things, mod_perl allows you to write authentication handlers that fit nicely into Apache&#8217;s authentication scheme. A Perl authentication handler is a Perl module that decides whether a given user gets access to a resource or not. How you determine whether the user is allowed or denied access is up to you. The mod_perl [...]]]></description>
			<content:encoded><![CDATA[<p>Among other things, mod_perl allows you to write authentication handlers that fit nicely into Apache&#8217;s authentication scheme. A Perl authentication handler is a Perl module that decides whether a given user gets access to a resource or not. How you determine whether the user is allowed or denied access is up to you. </p>
<p>The mod_perl documentation comes with a sample that checks the length of the username+space+password supplied by a user and allows the user access only if the length is 14 characters long. Here is what the code looks like:</p>
<pre>
  package MyApache2::SecretLengthAuth;

  use strict;
  use warnings;

  use Apache2::Access ();
  use Apache2::RequestUtil ();

  use Apache2::Const -compile => qw(OK DECLINED HTTP_UNAUTHORIZED);

  use constant SECRET_LENGTH => 14;

  sub handler {
      my $r = shift;

      my ($status, $password) = $r->get_basic_auth_pw;
      return $status unless $status == Apache2::Const::OK;

      return Apache2::Const::OK
          if SECRET_LENGTH == length join " ", $r->user, $password;

      $r->note_basic_auth_failure;
      return Apache2::Const::HTTP_UNAUTHORIZED;
  }

  1;
</pre>
<p>And you hook this handler up in your apache2.conf as:</p>
<pre>
  &lt;Location / &gt;
      PerlAuthenHandler MyApache2::SecretLengthAuth
      AuthType Basic
      AuthName "The Gate"
      Require valid-user
  &lt;/Location&gt;
</pre>
<p>As the documentation points out, the authentication handler can be configured for any sub section of the site, it doesn&#8217;t matter if it is served by a mod_perl response handler or not.</p>
<p>Now obviously in real life, you&#8217;d want an authentication handler that does a little more &#8211; like verify the password supplied by the user against a database or LDAP . Here is a version that I wrote that uses Perl&#8217;s Net::POP3 package to verify user&#8217;s credential against a POP 3 server.</p>
<pre>
package Apache::PopAuth;

use strict;
use warnings;
use Net::POP3;

use Apache2::Access ();
use Apache2::RequestUtil ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK DECLINED HTTP_UNAUTHORIZED);

sub handler {
    my $r = shift;
    my ($status, $password) = $r->get_basic_auth_pw;
    my $user = $r->user;

    return $status unless $status == Apache2::Const::OK;

    return Apache2::Const::OK
	   if valid_user($user, $password);

    $r->note_basic_auth_failure;
    return Apache2::Const::HTTP_UNAUTHORIZED;
}

sub valid_user {
    my($user, $password) = @_;
    my $pop = Net::POP3->new('pop.yourdomain.com');
    my $status = $pop->login($user, $password);
    $pop->quit();
    return defined($status);
}
1;
</pre>
<p>This saves you from having to maintain a separate set of users on your web server and passes on the baton of user management to the POP server. One word of caution &#8211; this just proof of concept code and I am not sure on well it will scale outside a small intranet. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.deepakg.com/prog/2009/02/perlauthenhandler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Install and enable Apache2::Request on Ubuntu Server 8.10</title>
		<link>http://www.deepakg.com/prog/2009/01/install-and-enable-apache2request-on-ubuntu-server-810/</link>
		<comments>http://www.deepakg.com/prog/2009/01/install-and-enable-apache2request-on-ubuntu-server-810/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 16:40:17 +0000</pubDate>
		<dc:creator>deepakg</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Apache2::Request]]></category>
		<category><![CDATA[libapreq2]]></category>
		<category><![CDATA[mod_apreq2]]></category>
		<category><![CDATA[mod_perl]]></category>

		<guid isPermaLink="false">http://www.deepakg.com/prog/?p=39</guid>
		<description><![CDATA[A mod_perl handler can parse the incoming client request (querystring, form post data etc) using Apache2::Request. It is *not* installed when you install mod_perl. Getting it working is a 3 step process. First issue the following command: sudo apt-get install libapreq2 This installs 2 things &#8211; the libapreq2 shared library, and an Apache module &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>A mod_perl handler can parse the incoming client request (querystring, form post data etc) using Apache2::Request. It is *not* installed when you install mod_perl. Getting it working is a 3 step process. </p>
<p>First issue the following command:</p>
<p><code>sudo apt-get install libapreq2</code></p>
<p>This installs 2 things &#8211; the libapreq2 shared library, and an Apache module &#8211; mod_apreq2.</p>
<p>Next we install the Perl bindings &#8211; Apache2::Request &#8211; which we use in our handler code. </p>
<p><code>sudo apt-get install libapache2-request-perl</code></p>
<p>At this stage if you restart Apache, it will load your Perl handler without any complaints. However if you visit a handler that uses Apache2::Request, it&#8217;ll error out with the following entry in error.log:</p>
<p><code><br />
/usr/sbin/apache2: symbol lookup error: /usr/lib/perl5/auto/APR/Request/Apache2/Apache2.so: undefined symbol: apreq_handle_apache2<br />
</code></p>
<p>This is because unlike <a href="/prog/2009/01/installing-mod_perl-on-ubuntu-server/">our mod_perl installation</a>, apt-get doesn&#8217;t enable mod_apreq2 after installing it. We enable it manually by creating a symbolic link to /etc/apache2/mods-available/apreq.load under /etc/apache2/mods-enabled/:</p>
<p><code><br />
sudo bash<br />
cd /etc/apache2/mods-enabled<br />
ln -s ../mods-available/apreq.load<br />
apache2ctl restart<br />
</code></p>
<p>Updated: You can also run a2enmod to enable an Apache module and use a2dismod to disable it.</p>
<p>Visit your handler url again and this time it should work withour errors. Here is the modified handler from the <a href="/prog/2009/01/installing-mod_perl-on-ubuntu-server/">mod_perl installation post</a> that now uses Apache2::Request to enable you to test if your installation is working correctly:</p>
<pre>
package Hello;
use strict;

use Apache2::RequestRec ();
use Apache2::RequestIO ();

use Apache2::Const -compile => qw(OK);

use Apache2::Request;

sub handler {
    my $r = shift;

    $r->content_type('text/plain');

    my $req = Apache2::Request->new($r);
    my $name = $req->param("name");
    $name = $name ? $name : "World";

    print "Hello $name, the time here is " . localtime() . "\n";

    return Apache2::Const::OK;
}

1;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.deepakg.com/prog/2009/01/install-and-enable-apache2request-on-ubuntu-server-810/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CPAN modules on Ubuntu: apt-get vs. perl -MCPAN</title>
		<link>http://www.deepakg.com/prog/2009/01/cpan-modules-on-ubuntu-apt-get-vs-perl-mcpan/</link>
		<comments>http://www.deepakg.com/prog/2009/01/cpan-modules-on-ubuntu-apt-get-vs-perl-mcpan/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 19:07:01 +0000</pubDate>
		<dc:creator>deepakg</dc:creator>
				<category><![CDATA[installation]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[apt]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[CPAN]]></category>

		<guid isPermaLink="false">http://www.deepakg.com/prog/?p=29</guid>
		<description><![CDATA[Ubuntu allows you to add and remove components from your system using apt-get. Perl allows similar functionality for maintaing Perl modules through the CPAN module&#8217;s shell (invoked by perl -MCPAN -eshell). Now if you are just going to add a Perl module to your system, should you be using apt-get or CPAN? I prefer to [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu allows you to add and remove components from your system using apt-get. Perl allows similar functionality for maintaing Perl modules through the CPAN module&#8217;s shell (invoked by <code>perl -MCPAN -eshell</code>). Now if you are just going to add a Perl module to your system, should you be using apt-get or CPAN?</p>
<p>I prefer to use apt-get because this allows me to keep track of everything I&#8217;ve added to my system in one place. It also keeps things neat in case a given Perl module has binary dependencies. For 99% of the cases, I&#8217;ve found an apt package equivalent of a given CPAN module. The naming convention of the modules varies between CPAN and apt. For example, the package Algorithm::Diff  at CPAN, is known as libalgortihm-diff-perl in the apt world.</p>
<p>So sometimes the trick is knowing the correct apt name for a CPAN module. Now in most cases, if you know the Perl name of a module &#8211; say XML::Simple then you can arrive at the apt name by converting the package name to lowercase, replacing the &#8220;::&#8221; with a &#8220;-&#8221;, prefixing &#8220;lib&#8221; and suffixing -perl to it. i.e.</p>
<p><code><br />
echo "XML::Simple" | perl -e '$x=&lt;&gt;; chomp($x); $x=~s/::/-/; $x=lc($x); print &quot;lib$x-perl&quot;'<br />
</code></p>
<p>And if you want to automate things further:<br />
<code><br />
sudo bash<br />
echo "XML::Simple" | perl -e '$x=&lt;&gt;; chomp($x); $x=~s/::/-/; $x=lc($x); print "lib$x-perl"' | <strong>xargs apt-get install</strong><br />
</code></p>
<p>Just bear in mind that there are exceptions to this naming convention. The one I ran into recently involved Sablotron; which is known as XML::Sablotron in the CPAN world, but as libxml-sablot-perl in the apt world.</p>
<p>Also, apt might not always have the most recent version of a given module. So you have to depend on CPAN if you need the latest, greatest version of a module.</p>
<p>Lastly, some modules might not have an apt version &#8211; for example at the moment Devel::PerlySense exists on CPAN alone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deepakg.com/prog/2009/01/cpan-modules-on-ubuntu-apt-get-vs-perl-mcpan/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installing mod_perl on Ubuntu Server 8.10</title>
		<link>http://www.deepakg.com/prog/2009/01/installing-mod_perl-on-ubuntu-server/</link>
		<comments>http://www.deepakg.com/prog/2009/01/installing-mod_perl-on-ubuntu-server/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 18:59:41 +0000</pubDate>
		<dc:creator>deepakg</dc:creator>
				<category><![CDATA[configuration]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mod_perl]]></category>

		<guid isPermaLink="false">http://www.deepakg.com/prog/?p=8</guid>
		<description><![CDATA[I am at a stage in life where I am going to be writing a lot of Perl code again. My preferred OS is Mac OS since it already comes with Perl 5.8.8 and Apache 2.2.9 (as of Mac OS 10.5.6). Unfortunately, mod_perl that ships with Mac OS, is broken (segfaults!). You can use fink [...]]]></description>
			<content:encoded><![CDATA[<p>I am at a stage in life where I am going to be writing a lot of Perl code again. My preferred OS is Mac OS since it already comes with Perl 5.8.8 and Apache 2.2.9 (as of Mac OS 10.5.6). Unfortunately, mod_perl that ships with Mac OS, is broken (segfaults!). You can use fink or macports to pull Apache/Perl/mod_perl that work but I figured that if I use Ubuntu, I also get to be close to my Debian production environment. Here is how I got a fresh Ubuntu 8.10 Server VM ready with mod_perl:</p>
<h5>Getting started</h5>
<p>At one stage during the installation of Ubuntu server, you&#8217;ll be asked what components you want installed. Pick LAMP at the very least. After booting up for the first time (and logging in), fire up the following commands:<br />
<code><br />
sudo bash #fire up a root shell so that we don't have to sudo every command<br />
apt-get update<br />
apt-get dist-update<br />
reboot</code></p>
<p><code> </code></p>
<p><code>#install things that could come in handy later<br />
sudo bash<br />
apt-get emacs #skip this if you prefer vi - it's already there<br />
apt-get install linux-headers-server build-essential<br />
</code></p>
<p>At this stage you&#8217;ll have the latest kernel running. I find the default 80&#215;24 display a little too restrictive. We&#8217;ll fix that by editing <code>/boot/grub/menu.lst</code>. Open the file in emacs or whatever editor you like, and scroll down to the end to a bunch of options that look like title, uuid, kernel, initrd. Append vga=0x31A to the end of the first kernel statement. e.g. in my case<br />
<code><br />
kernel		/boot/vmlinuz-2.6.27-9-server root=UUID=d9f9cc35-d880-494d-8cd3-92da418a438b ro quiet splash<br />
</code></p>
<p>became<br />
<code><br />
kernel		/boot/vmlinuz-2.6.27-9-server root=UUID=d9f9cc35-d880-494d-8cd3-92da418a438b ro quiet splash <strong>vga=0x31A</strong><br />
</code></p>
<p>Reboot.</p>
<p>vga=0x31A gives me a resolution of 1280&#215;1024 and 64k colors. Here are other options that you can play with:</p>
<pre>#  FRAMEBUFFER RESOLUTION SETTINGS
#     +-------------------------------------------------+
#          | 640x480    800x600    1024x768   1280x1024
#      ----+--------------------------------------------
#      256 | 0x301=769  0x303=771  0x305=773   0x307=775
#      32K | 0x310=784  0x313=787  0x316=790   0x319=793
#      64K | 0x311=785  0x314=788  0x317=791   0x31A=794
#      16M | 0x312=786  0x315=789  0x318=792   0x31B=795
#     +-------------------------------------------------+</pre>
<h5>Installing mod_perl</h5>
<p>At this stage we already have Apache and Perl installed. If you do:<br />
<code>tail /var/log/apache2/error.log</code>, you&#8217;ll see that out of the box, you only get support for PHP.<br />
<code><br />
[Sun Dec 14 12:04:05 2008] [notice] Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch configured -- resuming normal operations<br />
</code></p>
<p>Here is how you add mod_perl support:</p>
<p><code><br />
sudo bash<br />
apt-get install libapache2-mod-perl2</code></p>
<p><code>#restart apache so that it loads mod_perl<br />
apache2ctl restart</p>
<p>#make sure that it did indeed load<br />
tail /var/log/apache2/error.log</p>
<p></code></p>
<p><code>#if all went well, you'll see something to the effect of (emphasis mine):<br />
[Sun Dec 14 12:19:17 2008] [notice] Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch <strong>mod_perl/2.0.4 Perl/v5.10.0</strong> configured -- resuming normal operations<br />
</code></p>
<h5>Testing our mod_perl installation</h5>
<p>Let&#8217;s write a simple mod_perl response handler to make sure our installation was successful. Create Hello.pm in your home directory &#8211; which is <code>/home/deepakg/</code> on my machine:</p>
<pre>package Hello;
use strict;

use Apache2::RequestRec ();
use Apache2::RequestIO ();

use Apache2::Const -compile =&gt; qw(OK);

sub handler {
    my $r = shift;

    $r-&gt;content_type('text/plain');
    print "Hello World, the time here is " . localtime() . "\n";

    return Apache2::Const::OK;
}

1;</pre>
<p>Then to make sure that we didn&#8217;t make any typos:<br />
<code><br />
perl -c Hello.pm<br />
Hello.pm syntax OK<br />
</code></p>
<p>Next, open <code>/etc/apache2/apache2.conf</code> and type the following right at the end:</p>
<pre>PerlRequire /home/deepakg/Hello.pm
&lt;Location /time&gt;
   SetHandler perl-script
   PerlResponseHandler Hello
&lt;/Location&gt;</pre>
<p>Restart apache and check the Apache error log to make sure that it started without any issues:<br />
<code><br />
sudo apache2ctl restart<br />
tail /var/log/apache2/error.log<br />
</code></p>
<p>Install lynx, so that you can check your handy work:<br />
<code><br />
sudo apt-get install lynx</code></p>
<p><code> </code></p>
<p><code># and once it is installed<br />
lynx http://localhost/time<br />
</code></p>
<p>If everything is working then you&#8217;ll be greeted with something like this:<br />
<code><br />
Hello World, the time here is Sat Jan 10 15:25:51 2009<br />
</code><br />
Of course, the actual date and time will vary on your system <img src='http://www.deepakg.com/prog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h5>Miscellaneous</h5>
<p>If the time shown by the script above looks awkward, your time zone might not have been configured correctly. Configure the time zone to where you are:<br />
<code><br />
sudo dpkg-reconfigure tzdata<br />
</code></p>
<p>And then may be tweak the clock by hand if needed:<br />
<code><br />
sudo date MMDDhhmm #MM - month, DD - date, hh - hour (24 format), mm - minute<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.deepakg.com/prog/2009/01/installing-mod_perl-on-ubuntu-server/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.669 seconds -->
