Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output not flushed on end() #7

Open
XSven opened this issue Feb 28, 2024 · 0 comments
Open

output not flushed on end() #7

XSven opened this issue Feb 28, 2024 · 0 comments

Comments

@XSven
Copy link

XSven commented Feb 28, 2024

I have created a lexical output filehandle with the three-argument open() function. I haven't altered $|. I have passed this handle to an XML::Writer instance and after I am done with the XML creation I am calling the object method end(). I have not closed the filehandle explicitly because I am leaving a surrounding subroutine scope that should flush and close the filehandle. Unfortuntely the flush did not happen and the XML output was incomplete. Whatever is the real root cause of this phenomenon I am asking myself why end() does not call flush() on the output filehandle?!

I have added a flush() call to the $end code reference

my $end = sub {
  $output->print("\n");
  $output->flush();

  return $selfcontained_output
      if $use_selfcontained_output and defined wantarray;
};

and I have added an empty flush() implementation to the private XML::Writer::_String package

package XML::Writer::_String;
...
sub flush {}

This has solved my issue and the change has no negative impact on the XML::Writer unit tests.

PS: I have removed two $outputFile->flush(); statements from the t/01_main.t test script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant