Skip to content
Browse files

Merge branch 'master' into middleware-api2

Conflicts:
	scripts/plackup
	t/Plack-Middleware/order.t
  • Loading branch information...
2 parents 4a1e2a1 + 850bc4f commit cb2c24a9d446091e727504605742700ecf0d5698 @miyagawa miyagawa committed
View
7 Makefile.PL
@@ -30,7 +30,12 @@ feature 'Serve static files with sendfile(2)',
'Sys::Sendfile' => 0.09,
'IO::AIO' => 3.3;
-requires 'CGI::ExceptionManager'; # Middleware::StackTrace
+requires 'Devel::StackTrace'; # Middleware::StackTrace
+requires 'Devel::StackTrace::AsHTML'; # Middleware::StackTrace
+
+feature 'Stacktrace with lexical variables',
+ 'Devel::StackTrace::WithLexicals';
+
requires 'Path::Class'; # Middleware::Static
requires 'MIME::Types'; # Middleware::Static
View
5 eg/dot-psgi/error.psgi
@@ -1 +1,4 @@
-sub { die "Oops" };
+sub {
+ my $x = "bar"; my $y = [1,2,3]; my $z = { x => 1 }; my @y = qw(foo bar); my %z = (x => 1, y => 2);
+ die "Oops";
+};
View
33 lib/Plack/Middleware/StackTrace.pm
@@ -3,19 +3,25 @@ use strict;
use warnings;
use base qw/Plack::Middleware/;
use Plack;
-use CGI::ExceptionManager::StackTrace;
-use Encode;
+use Plack::Util;
+use Data::Dump;
+use Devel::StackTrace;
+use Devel::StackTrace::AsHTML;
-__PACKAGE__->mk_accessors(qw/renderer/);
+our $StackTraceClass = "Devel::StackTrace";
+
+# Optional since it needs PadWalker
+if (eval { require Devel::StackTrace::WithLexicals; 1 }) {
+ $StackTraceClass = "Devel::StackTrace::WithLexicals";
+}
sub call {
my($self, $env) = @_;
- my $err_info;
+ my $trace;
local $SIG{__DIE__} = sub {
- my($msg) = @_;
- $err_info = CGI::ExceptionManager::StackTrace->new($msg);
- die $msg;
+ $trace = $StackTraceClass->new;
+ die @_;
};
my $res = do {
@@ -23,12 +29,9 @@ sub call {
eval { $self->app->($env) };
};
- if ($err_info) {
- my $body = $err_info->as_html(
- powered_by => "Plack/$Plack::VERSION",
- renderer => $self->renderer,
- );
- $res = [500, ['Content-Type' => 'text/html; charset=utf-8'], [ encode_utf8($body) ]];
+ if (!$res && $trace) {
+ my $body = $trace->as_html;
+ $res = [500, ['Content-Type' => 'text/html; charset=utf-8'], [ $body ]];
}
return $res;
@@ -62,9 +65,11 @@ No configuration option is available.
Tokuhiro Matsuno
+Tatsuhiko Miyagawa
+
=head1 SEE ALSO
-L<CGI::ExceptionManager> L<Plack::Middleware>
+L<Devel::StackTrace::AsHTML> L<Plack::Middleware>
=cut
View
10 lib/Plack/Util.pm
@@ -196,6 +196,16 @@ sub status_with_no_entity_body {
return $status < 200 || $status == 204 || $status == 304;
}
+sub encode_html {
+ my $str = shift;
+ $str =~ s/&/&amp;/g;
+ $str =~ s/>/&gt;/g;
+ $str =~ s/</&lt;/g;
+ $str =~ s/"/&quot;/g;
+ $str =~ s/'/&#39;/g;
+ return $str;
+}
+
sub inline_object {
my %args = @_;
bless {%args}, 'Plack::Util::Prototype';
View
5 scripts/plackup
@@ -31,10 +31,9 @@ lib->import(@includes) if @includes;
my $handler = Plack::Util::load_psgi $app;
if ($env eq 'development') {
- if (eval "require Plack::Middleware::StackTrace; 1") {
- $handler = Plack::Middleware::StackTrace->wrap($handler);
- }
+ require Plack::Middleware::StackTrace;
require Plack::Middleware::AccessLog;
+ $handler = Plack::Middleware::StackTrace->wrap($handler);
$handler = Plack::Middleware::AccessLog->wrap($handler, logger => sub { print STDERR @_ });
}
View
1 t/Plack-Middleware/order.t
@@ -1,5 +1,4 @@
use strict;
-use Test::Requires qw( CGI::ExceptionManager );
use Plack::Builder;
use Test::More;
View
1 t/Plack-Middleware/stacktrace.t
@@ -1,7 +1,6 @@
use strict;
use warnings;
use Test::More;
-use Test::Requires qw( CGI::ExceptionManager );
use Plack::Middleware::StackTrace;
my $handler = Plack::Middleware::StackTrace->wrap(sub { die "orz" });

0 comments on commit cb2c24a

Please sign in to comment.
Something went wrong with that request. Please try again.