From fb1dddd53927403d06b49f5a6886d50600e07aff Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 6 Apr 2022 06:33:37 -0700 Subject: [PATCH] fix undef ref for user-defined formatter without output --- lib/Perl/Tidy.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index cf25acd0..6594d4e2 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1412,7 +1412,7 @@ EOM my $use_destination_buffer; my $encode_destination_buffer; my $ref_destination_stream = ref($destination_stream); - if ($ref_destination_stream) { + if ( $ref_destination_stream && !$user_formatter ) { $use_destination_buffer = 1; $output_file = \$destination_buffer; @@ -1847,13 +1847,13 @@ EOM if ( ref($destination_stream) eq 'SCALAR' ) { ${$destination_stream} = $destination_buffer; } - else { + elsif ($destination_buffer) { my @lines = split /^/, $destination_buffer; if ( ref($destination_stream) eq 'ARRAY' ) { @{$destination_stream} = @lines; } - # destination is object with print method + # destination stream must be an object with print method else { foreach (@lines) { $destination_stream->print($_); @@ -1863,6 +1863,11 @@ EOM } } } + else { + + # Empty destination buffer not going to a string ... could + # happen for example if user deleted all pod or comments + } } else { -- 2.39.5