Over the last few days I've put the Perl::Critic framework to a new use, that of upgrading old perl5 code to shiny new Perl6. The result of this is currently residing on https://github.com/drforr/Perl-Mogrify as it's not quite ready for CPAN yet. There's quite a bit of gruntwork to do replacing the existing Perl::Critic documentation, and I want to add a few more features, but the list of what it converts over is pretty extensive.

(I'm aware of Util's Blue-Tiger project and in fact cribbed some code from it, but I wanted the ability to let others contribute without having to make a pull request.)

From the README:



Basic data types (integers, floats, strings)





Binary, Octal and Hexadecimal integer





Floating-point trailing decimal





Here-docs





Interpolated values ("${x}", "$x-foo" etc.)





Q types





qw(), qr(), qx()





Conditional constructs ('if', 'elsif', 'unless', 'when')



Looping constructs ('for', 'foreach', 'while', 'until')





Transformation of C-style loops





First-order operators





'map {} @foo', 'grep !2 @a'





Core operators ('->', '.', '<>', '!' etc.)



Package declarations ('package My::Package;', 'package My::Package {}')



Package usage ('use Foo::Bar')



Pragmas ('utf8', 'warnings', 'overload' etc.)



Dereferencing ('%{ $foo }', '%$foo' etc.)



Hashes ('$foo{a}', "$foo{'a'}" etc.)



Sigils ('$x', '$a[1]', '@a', '%a{a,b}' etc.)



Special variables ('@ARGV', '@+', '%ENV' etc.)



Special literals ('__END__', '__PACKAGE__', '__FILE__' etc.)



This is of course done through (ab)?using PPI and its willingness to not care what resides within its DOM. This architecture lets people write their own transformers and share them on GitHub, CPAN or elsewhere, and since it uses Perl::Critic's core logging facility you can even trace back to see what made a change, and maybe even learn a little Perl6 in the process. (for example, check out the Perl6 translation of Perl5's @+ variable.)

Translators can accept custom parameters, but with a bit of creativity lots won't need to. For instance, imagine the act of converting everything to use the braceless style. You certainly could go through each converter and add a custom parameter to delete braces, then ship your set of custom modules.

Or you could just add your own de-bracer transform and configure it to go at the very end of the chain.

Following the new dictum of "release early, release often" I'm getting this out the door so that people have a chance to play with it and give me feedback. It won't be going onto CPAN until I have a chance to get the test suites to pass, and add a few more mandatory transformations.

I'm aware that PPI is a pretty steep learning curve, and it's not without its flaws, so as I go through and add the remaining transforms that I can see, I'll try to move the contents into Perl::Mogrify::Utils::PPI. There are already some small routines to test whether we're using a pragma or regular module, but that needs to be amplified.

Feel free to send me GitHub issues or pull requests. Barring major issues the main development will remain on GitHub, but I'll watch RT once it's on CPAN. Which won't be for a while, as there's quite a bit of documentation to rewrite, and I need to decide exactly how to utilize the 'severity' system in this context. Ideas would be appreciated.