fREWdiculous!
21 Apr
So I am working on a new way to use perlcritic, and one of the things I’d like perlcritic to check for is a correctly formatted file. Unfortunately the integration between perlcritic and perltidy goes something like this:
Tidy the file with perltidy
Give vague error if tidy file != original file
That’s fine until you discover that = signs get aligned and apparently you cannot turn that feature off. That means that my code gets marked sketch if I don’t align my = signs. That is terrible. So I figured I’d make it easy to tidy up source files.
First off you have to install perltidy (I think it’s Acme::Tidy.) This also assumes Win32. On Mac and Linux the commandline isn’t so painful so this isn’t necessary. Next run this code:
1 2 3 4 5 6 7 | use Win32::TieRegistry; $Registry-> Delimiter("/"); $perlKey = $Registry-> {"HKEY_CLASSES_ROOT/Perl/"}; $perlKey-> {"shellex/"} = { "DropHandler/" => { "/"=> "{86C86720-42A0-1069-A2E8-08002B30309D}" }}; |
That will allow for you to drag files onto .pl files and put the file list into @ARGV.
Then you just make a script with this in it:
1 2 | use Perl::Tidy; Perl::Tidy::perltidy(); |
And drag perl files into it. It will create new files with the .tdy extension in the same dir as the original files. If you create a .perltidyrc and put it in your home it will use those settings. Here’s our .perltidyrc:
1 | -i=3 -ce -bar -nsbl -sot -sct |
Enjoy!
2 Responses for "More Tools Monday"
The RequireTidyCode policy takes a “perltidyrc” option that allows you to specify how you want Perl Tidy to work. You can turn off the alignment in there.
Perl::Tidy is in Perl-Tidy distribution, but you don’t need this information if you install using CPAN/CPANPLUS shell – it will find it for you.
Leave a reply