From: Steve Hancock <perltidy@users.sourceforge.net> Date: Wed, 6 Apr 2022 13:33:37 +0000 (-0700) Subject: fix undef ref for user-defined formatter without output X-Git-Tag: 20220217.03~16 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=fb1dddd53927403d06b49f5a6886d50600e07aff;p=perltidy.git fix undef ref for user-defined formatter without output --- 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 {