Perl tidy

Flavio Poletti edited this page Aug 18, 2016 · 9 revisions

Perl::Tidy to the rescue

Keeping code well formatted is not vital, however, it reduces the cost of maintenance and it raises acceptance among co-workers. Whenever someone looks into code snippets which vary all over the place the results are unpredictable. There are reasonable tools on the market which test your code and format it.

A common one is the Perl module Perl::Tidy. It lets you specify the way your code is being formatted by using a configuration file named ~/.perltidyrc. The Mojolicious GitHub repository has a nice perltidyrc included. Why not use the way the Mojolicious project formats the code?

  • Install Perl::Tidy (easiest way: cpan Perl::Tidy)

  • Download the perltidyrc file from the Mojolicious repo and install it inside your home directory.

    perl -Mojo -e 'print g("")->body' \
    > ~/.perltidyrc
  • perltidy will use the default configuration file named ~/.perltidyrc if no further options are given. You can use a different perltidyrc file using the command option -pro=<perltidyrc>.

  • Format your sources (perltidy <sourcefile>)