From 5a52015232f6c9611c5519400afd5cd58fd9021a Mon Sep 17 00:00:00 2001 From: Tatsuhiko Miyagawa Date: Thu, 14 Sep 2023 14:41:20 -0700 Subject: [PATCH] use ref to avoid calling overloaded methods. Fix #697 --- lib/Plack/Middleware/StackTrace.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Plack/Middleware/StackTrace.pm b/lib/Plack/Middleware/StackTrace.pm index 9c02c109c..d0821e53c 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;