Skip to content

Instantly share code, notes, and snippets.

@nanto
Created March 5, 2013 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanto/5091311 to your computer and use it in GitHub Desktop.
Save nanto/5091311 to your computer and use it in GitHub Desktop.
$SIG{__DIE__} の設定如何で Text::Xslate の投げる例外が変化するかもしれないというメモ
use Our::App;
use Try::Tiny;
use Devel::StackTrace::WithLexicals;
builder {
enable sub {
my $app = shift;
sub {
my $trace;
local $SIG{__DIE__} = sub {
$trace = Devel::StackTrace::WithLexicals->new(...);
die @_;
};
try {
$app->(@_);
} catch {
# do something with $trace
};
};
};
Our::App->to_app;
};
WAF として Amon2 を使い、上記のような app.psgi を書き、
$c->render($unknown_file) (ここで $c は Amon2::Web のインスタンス、
$unknown_file は存在しないファイル名)を呼び出したとき、
https://github.com/tokuhirom/Amon/blob/master/lib/Amon2/Web.pm#L159
で例外が発生する。
ただし、例外の内容 ($@ を文字列化した値) は、$SIG{__DIE__} を設定していないときは
Xslate: LoadError なのに対し、上記のように $SIG{__DIE__} を設定したときは
Not a subroutine reference となる (スタックトレースを見ると、
先頭が Not a subroutine reference で次に Xslate: LoadError が登場している)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment