Perl: 2007年7月アーカイブ
昨日Moxyを使えるようにしてみたので、メモ。
Mac環境だとdbm_class: DB_Fileしないとエラーが出ました。
取得
http://code.mfac.jp/trac/
インスト
perl Makefile.PL
make
make install
設定ファイル
~/.moxy_config.yaml
---
global:
assets_path: /Users/bokutin/compile/mfac/Moxy/assets
server:
module: HTTPProxy
port: 9999
host: localhost
max_clients: 80
storage:
dbm_class: DB_File
plugins:
- module: Pictogram
- module: HTMLWidth
- module: HTTPEnv
- module: StickyUA
- module: ControlPanel
- module: GPS
- module: UserAgentSwitcher
- module: XMLisHTML
- module: RefererCutter
SHELL
% alias moxy_server
moxy_server='perl /opt/local/lib/perl5/site_perl/5.8.8/moxy.pl --config=/Users/bokutin/.moxy_config.yaml'
おしまい。
テーブルがそのままレンダリングされちゃうよー。
いいのかな・・・
Catalyst-Runtime-5.7007。
catalyst.pl project直後のproject::Controller::Rootの
sub default : Private {
my ( $self, $c ) = @_;
# Hello World
$c->response->body( $c->welcome_message );
}
を以下のように変えて
sub default : Private {
my ( $self, $c ) = @_;
system("ls");
if ($? == -1) {
warn "failed to execute: $!\n";
}
elsif ($? & 127) {
warn "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
warn "child exited with value %d\n", $? >> 8;
}
# Hello World
$c->response->body( $c->welcome_message );
}
のようにsystem()を使うと
failed to execute: No child processes
と言われる。
sendmailを呼びだすようなMIME::Lite::TT::HTML::Japaneseなどを
使っても刺さる。
どうやらこの症状は起動しているサーバーによって挙動が違い
付属のテストサーバーでは、上の通り「No child processes」。
付属のテストサーバーに-rオプションを付けると、system()でロックする。
lighttpdだと、問題なし。
臭ったところのCatalyst::Engine以下ですが、
Catalyst::Engine::HTTPにlocal $SIG{CHLD} = 'IGNORE';を発見。
これが原因になってたよう。
なので、テストサーバ、リスタート付きテストサーバ、lighttpdの三種で
互換性のあるコードを書くには
{
$SIG{CHLD} = 'DEFAULT';
system("/bin/ls");
....
}
などとしなくては、ならないのかにゃ。
なんか心地好くない気がするけど、とりあえず解決。
DBICというか DBIx::Class ですが、0.8から新しく入ったDBIx::Class::ResultClass::HashRefInflator でも使うかなと思ってたところ ちょこっと弄ったら、全然不要でした。
# # 0.2 sec
# $result_rs->search({id => \@ids})->update({folder_id=>$folder_id});
# # 6 sec
# for my $id (@ids) {
# my $result = $result_rs->find({id=>$id}) || die;
# $result->set_from_related('folder', $folder);
# $result->update;
# }
# # 6 sec
# for my $id (@ids) {
# my $result = $result_rs->find({id=>$id}) || die;
# $result->set_column( folder_id => $folder_id );
# $result->update;
# }
@idsは200個ぐらい。 resultはfolderに属している(belongs_to)です。
計測はiTunes再生しながら Benchmark::Stopwatch しましたので不正確ですケド・・・
発行されるSQL文の低減とinflate_resultが無くなったのが要因かにゃ。


