2006-01-19

Configure Catalyst 5.61 with Apache2 on Windows

I reconfigured my Catalyst app using mod_perl today. It was configured using CGI before as I was making a lot of changes and would like to page to always reflect the last change. The original configuration is:
<VirtualHost *:80>
ServerAdmin my@server.com
DocumentRoot c:/site/myapp/root
ServerName myserver2
ErrorLog c:/site/myapp/myapp-error.log
CustomLog c:/site/myapp/myapp-access.log common
ScriptAliasMatch ^/(.+) c:/site/myapp/script/myapp_cgi.pl/$1
Alias /static c:/site/myapp/root/static
<Location "/static">
SetHandler none
</Location>
</VirtualHost>

It works but the performance is horrorable. The new configuration is:
<VirtualHost *:80>
ServerAdmin my@server.com
DocumentRoot c:/site/myapp/root
ServerName myserver2
ErrorLog c:/site/myapp/myapp-error.log
CustomLog c:/site/myapp/myapp-access.log common
PerlOptions +Parent
PerlSwitches -IC:/site/myapp/lib
<Location />
SetHandler modperl
PerlHandler myapp
</Location>
<LocationMatch "/static">
SetHandler none
</LocationMatch>
</VirtualHost>

2006-01-18

Use DBD: :Oracle 1.16 to access Oracle 9.2 database

I try to connect to an Oracle 9.2 database using following code:
 my $dbh = DBI->connect($config->{dburl}, $config->{dbuser}, $config->{dbpass});

It failed with error:
DBI connect('host=host;sid=dbsid','user',...) failed: ORA-12705: invalid or unknown NLS parameter value specified (DBD ERROR: OCISessionBegin) at ..

I have to explicitly set the ENV variable NLS_LANG to make it work. The new code looks like:
$ENV{NLS_LANG}="AMERICAN_AMERICA.UTF8";
my $dbh = DBI->connect($config->{dburl}, $config->{dbuser}, $config->{dbpass});

and it works.

The initial thought is that the default NLS_LANG from DBD::Oracle has to match the server configuration which is "AMERICAN_AMERICA.UTF8". But the follwoing code works as well:
$ENV{NLS_LANG}="AMERICAN_AMERICA.US7ASCII";
my $dbh = DBI->connect($config->{dburl}, $config->{dbuser}, $config->{dbpass});

So maybe the DBD:Oracle is sending some invalid NLS_LANG string though I havn't figured out what it is.

The SimpleDateFormat class is NOT threadsafe

In researching a defect in my project, I find SimpleDateFormat class is not thread safe. The "bug" is reported back in JDK 1.2 and JavaDoc is added in JDK 1.5. I just don't see it. :(

2006-01-14

Perl object is just a blessed hash

To work on a small testing utility, I have to pick up perl again. Fortunately my memory still served me well until I got into this problem. How to trun a hash into object. After a little reading of my Learning Perl book. I figured out how it works. Once you understand perl object is just a blessed hash, then the solution is clear.

============================
package MyTest;

use strict;

my %hash = (color=>"red", shape=>"round");
my $hashref = \%hash;

sub not_typical_new {
my ($proto, $arg) = @_;
my $class = ref($proto) || $proto;
my $self = $arg;
bless ($self, $class);
return $self;
}

my $obj = mytest->not_typical_new($hashref);
print $obj->{color}, "\n";

Added a nice JSCalendar to the blogger

I added a nice JSCalendar to my blog. The instructions from ecmanaut helped. The first part is relatively easy. But the seconf part is difficult to follow. I ended up have to dig into the source code to find out how it works. After a hour or so, I finally figured out the basic functions. The challenge is because I used a customized template so that many CSS tags used by the scripts are not included. I have to change the template to include al l those CSS tags just to make the calendar work. I still cannot get the title hint to work as it requires more template change which I am not willing to spend more time. So I stopped here. But it is good enough for me now.

The del.icio.us tag script does not get along with Google's tools bar

I added the del.icio.us greasemonkey script so that I can create the bookmark after the post. However, it stopped working today. After a search on google, I learned that the script, for some reason, does not work with Google's toolbar extension. After remove the Google's toolbar, it works just fine. :(

2006-01-13

Added the freshtag to the blog

I added the freshtag to my blog today. It allows me to use del.icio.us tag to categorize my blog.