Created
March 5, 2013 15:56
-
-
Save nanto/5091311 to your computer and use it in GitHub Desktop.
$SIG{__DIE__} の設定如何で Text::Xslate の投げる例外が変化するかもしれないというメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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