This can't be moved to Try::Tiny due to the closures within causing # leaks on any version of Perl prior to 5.18. # https://perl5.git.perl.org/perl.git/commitdiff/a0d2bbd5c my $error = do { #catch local $@; local $\; # protect the print below from surprises eval { # try if (!defined($arg) || !$response->is_success) { $response->{default_add_content} = 1; } elsif (!ref($arg) && length($arg)) { open(my $fh, ">", $arg) or die "Can't write to '$arg': $!"; binmode($fh); push(@{$response->{handlers}{response_data}}, { callback => sub { print $fh $_[3] or die "Can't write to '$arg': $!"; 1;