CAP::DebugScreenのパッチ

CAP::DebugScreenにパッチが送られてきた。
パッチを当てるとimportメソッドがこんなになる。
add_callbackでerrorを設定するのではなく、
error_modeにメソッドを指定させる方法だった。


sub import {
my $self = shift;
my $caller = scalar caller;
$caller->add_callback( 'init', sub{
my $self = shift;
$self->error_mode('__debugscreen_error');
$SIG{__DIE__} = sub{
push @{$self->{__stacktrace}},[Devel::StackTrace->new(ignore_package=>[qw/CGI::Application::Plugin::DebugScreen Carp CGI::Carp/])->frames];
die @_; # rethrow
};
{
no strict 'refs';
*{"$caller\::report"} = \&debug_report;
*{"$caller\::__debugscreen_error"} = sub{
my $self = shift;
if (
exists $INC{'CGI/Application/Plugin/ViewCode.pm'}
&&
! exists $INC{'CGI/Application/Dispatch.pm'}
)
{
$self->{__viewcode}++;
}
$self->report(@_);
};
}
});
if ( ! exists $INC{'CGI/Application/Dispatch.pm'} &&
! exists $INC{'CGI/Application/Plugin/ViewCode.pm'}
)
{
"CGI::Application::Plugin::ViewCode"->require
or delete $INC{'CGI/Application/Plugin/ViewCode.pm'};
unless ($@) {goto &CGI::Application::Plugin::ViewCode::import}
}
}

私が思った利点は、debug_reportメソッドでprintではなくreturnでデバッグ画面を返せるところですね。
テストサーバを作った場合、returnでデバッグ画面を返せるのはいい感じなのですよね。

ただ、error_modeを他でsetupされてしまうとDebugが動かなくなります。
これってどうなんだろ。。

それはそれでいい気もしてきてるのですが、どうでしょうか?
ご意見いただければうれしいです。