ivo Welch
ivo Welch

Reputation: 2876

perl5 code with (ignored) perl6 data types

I want to start prepping some perl5 code for perl6. in particular, I like the idea of declaring what types my variables are supposed to be. perl6 defines Bool, Int, Array, Hash, Num, Complex, Pair, and Str. So I would in essence like to do the equivalent of a C preprocessor #define Int /**/ for now. It would be even better if it would check the data type, but I can live without it.

Easy? Hard? Impossible?

Upvotes: 4

Views: 67

Answers (2)

BarneySchmale
BarneySchmale

Reputation: 780

There are several Perl 5 modules that go into that direction. For object orientation you can use Moose and MooseX::Method::Signatures.

For declaring subs and methods there is Method::Signatures, Sub::Signatures and Kavorka.

Also look in the Perl6namespace on CPAN.

Upvotes: 5

user5854207
user5854207

Reputation:

You would have to write a parser that can parse Perl 5. Unless your code is fairly simple, that's pretty high on the hardness scale.

Also, I found that I structure Perl 6 programs very much different from Perl 5 code. You can technically stay very close to 1:1 one a line by line basis when porting Perl 5 to Perl 6 but the result wont be idiomatic, slow and hard to maintain when you fully switch to Perl 6. Just adding empty macros will not help you much because every mistake you make is just ignored. That may actually increase the burden when you want to port the program for good.

The idea has appeal but you may just increase your workload for no real gain.

Upvotes: 7

Related Questions