diff --git a/lib/Plack/Middleware/StackTrace.pm b/lib/Plack/Middleware/StackTrace.pm index 9c02c109..d0821e53 100644 --- a/lib/Plack/Middleware/StackTrace.pm +++ b/lib/Plack/Middleware/StackTrace.pm @@ -55,7 +55,8 @@ sub call { $trace = $caught_trace if $caught_trace; } - if ($trace && ($caught || ($self->force && ref $res eq 'ARRAY' && $res->[0] == 500)) ) { + # Use ref $trace to avoid calling as_string twice when it's not necessary + if (ref $trace && ($caught || ($self->force && ref $res eq 'ARRAY' && $res->[0] == 500)) ) { my $text = $trace->as_string; my $html = $trace->as_html; $env->{'plack.stacktrace.text'} = $text;