Pod::POM and Perl::Tidy

BooK on 2004-07-24T00:41:20

Thanks to Pod::POM and Perl::Tidy, all the Perl articles written by Les Mongueurs de Perl and published by GNU/Linux Magazine France now contain colored code examples.

The trickiest part was to prevent Perl::Tidy from choking on a verbatim, indented piece of code containing a here-document:

=begin tidy

    print << 'EOT';
    foo bar
    baz
    EOT
    $A++;

=end tidy

The text string passed to Perl::Tidy has to be munged so that line 4 is 'EOT' and not '<SP><SP><SP><SP>EOT'.

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.

Anyway, just have a look all these colorful Perl articles!


Another option

Aristotle on 2004-12-15T11:09:45

Personally I like Text::VimColor, if only for the simple reason that it can highlight a huge variety of input formats besides Perl.