| 1 | package HTTP::Engine::Middleware::DebugScreen; | ||||||||||
| 2 | 1 | ▶ | use HTTP::Engine::Middleware; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use HTTP::Engine::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Scope::Upper qw( localize_elem :words ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | has 'powerd_by' => ( | |||||||||
| 9 | is => 'rw', | ||||||||||
| 10 | default => __PACKAGE__, | ||||||||||
| 11 | ); | ||||||||||
| 12 | |||||||||||
| 13 | 1 | has 'renderer' => ( | |||||||||
| 14 | is => 'rw', | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 1 | has 'err_info' => ( | |||||||||
| 18 | is => 'rw', | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 1 | has 'response' => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 1 | has 'stacktrace_required' => ( | |||||||||
| 26 | is => 'rw', | ||||||||||
| 27 | isa => 'Bool', | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | before_handle { | ||||||||||
| 32 | 1 | ▶ | my($c, $self, $req) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 1 | $self->response(undef); | |||||||||
| 35 | 1 | $self->err_info(undef); | |||||||||
| 36 | 1 | $self->stacktrace_required(0); | |||||||||
| 37 | |||||||||||
| 38 | 1 | ▶ | localize_elem '%SIG', '__DIE__' => sub { $c->diecatch(1); died($self, @_) } => SUB UP; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 1 | $req; | |||||||||
| 41 | 1 | }; | |||||||||
| 42 | |||||||||||
| 43 | after_handle { | ||||||||||
| 44 | 1 | ▶ | my($c, $self, $req, $res) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | if ($self->err_info) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | $res = HTTP::Engine::Response->new; | |||||||||
| 48 | 1 | $res->code(500); | |||||||||
| 49 | 1 | ▶ | $res->body( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | $self->err_info->as_html( | ||||||||||
| 51 | powered_by => $self->powerd_by, | ||||||||||
| 52 | ($self->renderer ? (renderer => $self->renderer) : ()) | ||||||||||
| 53 | ) | ||||||||||
| 54 | ); | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | $res; | |||||||||
| 58 | 1 | }; | |||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub detach { die bless [@_], 'CGI::ExceptionManager::Exception' } | ||||||||
|
Subroutine
detach: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 61 | |||||||||||
| 62 | sub died { | ||||||||||
| 63 | 1 | ▶ | my($self, $msg) = @_; | ||||||||
|
Subroutine
died: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | if (ref $msg eq 'CGI::ExceptionManager::Exception') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $self->response($msg->[0]); | |||||||||
| 67 | 0 | $self->err_info(undef); | |||||||||
| 68 | } else { | ||||||||||
| 69 | 1 | ▶ | unless ($self->stacktrace_required) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | require CGI::ExceptionManager::StackTrace; | |||||||||
| 71 | 1 | $self->stacktrace_required(1); | |||||||||
| 72 | } | ||||||||||
| 73 | 1 | $self->err_info( CGI::ExceptionManager::StackTrace->new($msg) ); | |||||||||
| 74 | } | ||||||||||
| 75 | 1 | die $msg; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 1 | __MIDDLEWARE__ | |||||||||
| 79 | |||||||||||
| 80 | __END__ | ||||||||||
| 81 | |||||||||||
| 82 | =head1 NAME | ||||||||||
| 83 | |||||||||||
| 84 | HTTP::Engine::Middleware::DebugScreen - dump stack-trace when die | ||||||||||
| 85 | |||||||||||
| 86 | =head1 SYNOPSIS | ||||||||||
| 87 | |||||||||||
| 88 | my $mw = HTTP::Engine::Middleware->new; | ||||||||||
| 89 | $mw->install(qw/ HTTP::Engine::Middleware::DebugScreen /); | ||||||||||
| 90 | HTTP::Engine->new( | ||||||||||
| 91 | interface => { | ||||||||||
| 92 | module => 'YourFavoriteInterfaceHere', | ||||||||||
| 93 | request_handler => $mw->handler( \&handler ), | ||||||||||
| 94 | } | ||||||||||
| 95 | )->run(); | ||||||||||
| 96 | |||||||||||
| 97 | =head1 AUTHORS | ||||||||||
| 98 | |||||||||||
| 99 | yappo | ||||||||||
| 100 | |||||||||||
| 101 | kan | ||||||||||
| 102 | |||||||||||
| 103 | and more? | ||||||||||
| 104 | |||||||||||
| 105 | =head1 SEE ALSO | ||||||||||
| 106 | |||||||||||
| 107 | L<Scope::Upper>, L<CGI::ExceptionManager::StackTrace> | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||