23 April 2005
This post may be outdated due to it was written on 2005. The links may be broken. The code may be not working anymore. Leave comments if needed.

早上去上考研数学微积分,下午闲着无事改代码。

先改改了留言本 FayGuestBook,因为 $q->param('name1') 不能变量内插,所以就用了 $q->Vars

my %input = $q->Vars;

变量少的时候可以用 my $name1 = $q->param('name1');,可变量一多写起来就麻烦了。不过可以试试下面的代码

my ($name1, $name2, $name3, $name4, $name5, $name6);
foreach (qw/name1 name2 name3 name4 name5 name6/) {
    no strict 'refs';
    ${$_} = $q->param($_);
}

这样也不是非常好。不过暂时也想不出什么好办法来。
留言本实在不想大改,没啥意思。将它移植到 fayland.org GuestBook 就不想管了。

接着去看 Eplanet 的代码。
Eplanet 有个功能(build_alltopics)是将数据库里的数据转为 HTML 文档。

my @cms = Eplanet::M::CDBI::Cms->retrieve_all;
	
foreach (0 .. $#cms) {
    $c->stash->{topic} = $cms[$_];
    $c->stash->{prev_topic} = $cms[$_-1] unless ($_ == 0);
    $c->stash->{next_topic} = $cms[$_+1] unless ($_ == $#cms);
    $c->stash->{build_filename} = $cms[$_]->get('cms_file');

    $c->req->action(undef);$c->res->output(undef);

    $c->req->path('view/'. $cms[$_]->{'cms_id'} .'/build');
    $c->prepare_action();
    $c->dispatch();
}

用 path, prepare_action, dispatch 来执行多次 view,这功能改自 Catalyst::Plugin::SubRequest
多次执行 view 的速度实在让人不太能忍受。于是想着在 mod_perl 下运行。
运行不成功,倒是找到了个 bug,给 Catalyst Maillist 组发了 mail:
$req->base 's trailing slash in Catalyst::Engine::CGI

运行不成功的提示是

Caught exception "DBD::mysql::db FETCH failed: handle 2 is owned by thread 138b014 not current thread 2d1b40c (handles can't be shared between threads and your driver may need a CLONE method added) at C:/usr/site/lib/Ima/DBI.pm line 316."

可能需要重新启动机子或者其他的吧。这个容后再考虑。

晚上再看会代码,然后去喝点酒。

22:00

搞不定那个多线程错误,只好转向运行 catalyst 生成的一个 http 服务器(用 catalyst Eplanet 命令后,在script目录下有一个eplanet_server.pl)。发现速度很让人惊讶。将它转为 bat 文件(改下use lib)后放到 path 目录下。OK.


blog comments powered by Disqus