Perl::ToPerl6 released to CPAN

$ perlmogrify
$ more

Perl::ToPerl6 is now available on CPAN. This is the final name for the previously-mentioned Perl::Mogrify tool, with the goal of being able to transliterate (not translate, subtle distinction there) working Perl5 code into compilable Perl6.

Please ignore most of the documentation aside from the README file, as this application is heavily cribbed (read: mostly copied) from L (Thanks Jeffrey.) This tool is meant mostly for module authors, so please don't expect (yet!) a production-quality idiomatic Perl6 translation - We're still not sure what "idiomatic" Perl6 will look like.

Most of my effort has gone into changing operators because that's not easily done in search-and-replace (Keep in mind '.' -> '~', '=~' -> '~~', '->' -> '.') and whitespace is now significant in more places than you'd suspect based on a casual overview. Basically I'm trying to fix most of the simple stuff that would trip people up if they're porting modules by hand.

Feel free to submit pull requests or issues to Perl-Mogrify on GitHub (haven't changed the module name). I'll keep an eye on the RT trackers, but likely GitHub will be resolved quicker.

I should point out again that it's completely pluggable and extensible, so feel free to add your own modules to the L namespace, if you're familiar with PPI. Even if you're not, I'm in the process of building a library of transform operations.

It's meant to make just enough changes to ensure your Perl5 code compiles under Perl6. Future modules may help make your Perl6 code more idiomatic, but for the moment focus is on getting existing Perl5 code up and running. I haven't tested the CPAN-released version on a large codebase yet, but the last time I tested it against Parse::RecDescent only 1% of the code required human intervention to get it to compile, and that was mostly refactoring away C type constructs. A future conversion module may help with that.

From the README:

As of the initial release, it contains transformers for:

Basic data types (integers, floats, strings)
Binary, Octal and Hexadecimal integer
Floating-point trailing decimal
Interpolated values ("${x}", "$x-foo" etc.)
Interpolated case modifiers ("\lFoo", "\Ufoo\E" etc.)
'print $fh "text hee"'
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.)

Leave a comment

About DrForr

user-pic I blog about Perl.