2010-01-06

LazyWeb? Solutions for using MX::Declare and PerlTidy?

Dear Lazyweb.

I've been fighting for a while with this minor headache.

Using PerlTidy and MooseX::Declare in conjunction results in pain.

Here is a sample of the sort of indentation that results:

Input:


use MooseX::Declare;

class Foo {

method Simple {
my $foo = 1;
$foo = $foo + 1;
if( $foo ) {
$foo++;
}
}

method SimpleArgs ( $arg, $arg ) {
my $foo = 1;
$foo = $foo + 1;
if( $foo ) {
$foo++;
}
}

method NamedArgs ( :$argname , :$otherarg ) {
my $foo = 1;
$foo = $foo + 1;
if( $foo ) {
$foo++;
}
}
}


And the indentation after going through PerlTidy:

use MooseX::Declare;

class Foo {

method Simple {

my $foo = 1;
$foo = $foo + 1;
if ($foo) {
$foo++;
}
}

method SimpleArgs( $arg, $arg ) {
my $foo = 1;
$foo = $foo + 1;
if ($foo) {
$foo++;
}
}

method NamedArgs( : $argname, : $otherarg ) {
my $foo = 1;
$foo = $foo + 1;
if ($foo) {
$foo++;
}
};
}


You might notice the second example is both ugly, and refuses to function.

I gripe about it every now and then to various peoples, and the results tend towards 2 options:

  • Don't use PerlTidy
  • Don't use MooseX::Declare

Neither of those are much of an option to me. I really like keeping formatting and indentation consistent right across a project, but hand adjusting everything is just too much pain.

Some people tell me that I should just tweak my editor to do this for me, but that hardly works, I am yet to see an editor that handles Perl indentation intelligently enough for my liking. Additionally, some editors don't even really have features that tidy indentation and clean up end-of-line whitespace yet, while supporting heaps of other features I want.

Lately, I've been swayed towards using Padre, and its a handy interface for Perl coding, but there's still a massive void in the domain of keeping code tidy. The very best I can find is the Padre PerlTidy plugin, but that has all the same caveats PerlTidy has, so in this case, "just using my editors features" results in PerlTidy being the weak point yet again.

As far as I can make out, there's nothing even slightly comparable to PerlTidy, I cannot seem to see anything else that does anything remotely like it, not even on a more simplistic scale.

So, Dear Lazyweb, please scratch my itch.