CGI::AppでのDebugScreen
このエントリーは最初の投稿時と大きく書き換えました。
nekokakさんがつくられた「CGI::AppでのDebugScreen」はかなりハゲシクGJです。
ただ、prerunに引っ掛けるとその他のPluginで動かなくなるのがありそうなので、error_modeを使うinitにHookしてSIG{__DIE__}を差し込むというのはいかがですか?
importとdebug_reportを書き換えた。
sub import {
my $caller = caller;
$caller->add_callback( 'init', sub{
my $self = shift;
$caller::SIG{__DIE__} = sub{
$self->debug_report(@_);
die @_;
};
});
no strict 'refs';
*{"$caller\::debug_report"} = \&debug_report;
}
sub debug_report{
my $self = shift;
my $desc = shift;
my $vars = {
desc => $desc,
title => ref $self || $self,
context => \&print_context,
};
$vars->{stacktrace} = [Devel::StackTrace->new(ignore_package=>[qw/CGI::Application::Plugin::DebugScreen Carp/])->frames];
my $t = Template->new;
my $output;
$t->process(\$TEMPLATE, $vars, \$output);
$self->header_props( -type => 'text/html' );
my $headers = $self->_send_headers();
print $headers.$output;
}
サンプルはこちら。
http://nomadscafe.jp/test/cgiappdebugscreen/app.cgi
ソースはここに。
CGI::Application::Plugin::DebugScreenはこれ。
「そんなRun modeはない」というエラーも補足可能です。
コメント
こんばんは。
pluginの内容を考えても、initにHookすべきでしたね^^
オイラのはdebugメソッドでrunもどきを実行させてるので、美しくないなぁと思ってました。
Good Jobです!!
投稿者: nekokak | 2005年12月15日 19:44