« blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Message.pm
↑ Summary
blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/App/Controller/ApiBase.pm »
| 1 | package App::Controller::WebBase; | ||
| 2 | use Dwarf::Pragma; | ||
| 3 | use parent 'Dwarf::Module::HTMLBase'; | ||
| 4 | use Dwarf::DSL; | ||
| 5 | use App::Constant; | ||
| 6 | |||
| 7 | # バリデーションエラー時に直ちにエラーを送出するかどうか | ||
| 8 | sub _build_autoflush_validation_error { 0 } | ||
| 9 | |||
| 10 | sub init_plugins { | ||
| 11 | load_plugins( | ||
| 12 | 'Error' => { | ||
| 13 | LACK_OF_PARAM => sub { shift->throw(1001, @_) }, | ||
| 14 | INVALID_PARAM => sub { shift->throw(1002, @_) }, | ||
| 15 | ERROR => sub { shift->throw( 400, @_)->flush }, | ||
| 16 | }, | ||
| 17 | 'CGI::SpeedyCGI' => {}, | ||
| 18 | 'Text::Xslate' => {}, | ||
| 19 | 'HTTP::Session' => { | ||
| 20 | session_key => conf('/session/state/name'), | ||
| 21 | session_table => conf('/session/store/table'), | ||
| 22 | session_expires => 60 * 60 * 24 * 21, | ||
| 23 | session_clean_thres => 0.001, | ||
| 24 | param_name => 'session_id', | ||
| 25 | cookie_path => '/', | ||
| 26 | cookie_domain => undef, | ||
| 27 | cookie_expires => 60 * 60 * 24 * 21, | ||
| 28 | cookie_secure => conf('ssl') ? true : false, | ||
| 29 | cookie_httponly => 1, | ||
| 30 | }, | ||
| 31 | ); | ||
| 32 | } | ||
| 33 | |||
| 34 | sub will_dispatch { | ||
| 35 | |||
| 36 | } | ||
| 37 | |||
| 38 | # テンプレートに渡す共通の値を定義することなどに使う | ||
| 39 | # 例)ヘッダなど | ||
| 40 | # sub will_render { | ||
| 41 | # my ($self, $c, $data) = @_; | ||
| 42 | # } | ||
| 43 | |||
| 44 | # 500 系のエラー | ||
| 45 | sub receive_server_error { | ||
| 46 | my ($self, $c, $error) = @_; | ||
| 47 | print STDERR sprintf "[Server Error] %s\n", $error; | ||
| 48 | load_plugins('Devel::StackTrace' => {}); | ||
| 49 | $self->{server_error_template} ||= '500.html'; | ||
| 50 | $self->{server_error_vars} ||= { error => $c->stacktrace($error) }; | ||
| 51 | return $c->render($self->server_error_template, $self->server_error_vars); | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 |