The trickiest part was to prevent Perl::Tidy from choking on a verbatim, indented piece of code containing a here-document:
print << 'EOT';
The text string passed to Perl::Tidy has to be
munged so that line 4 is '
This was achieved by writing
=begin tidy EOT and having the view remove all blanks at the begining of the lines matching the heredoc boundary, stacking them in an array (in case several heredocs in the code snippet used the same string) and putting them back after. A rather clumsy solution.
Luckily, while writing this entry I thought to myself: "Mmm, maybe another option would have been too simply unindent the whole code based on the first line and reindent it after Perl::Tidy's finished working on it." It really sounds much better and general this way.