Is the a way to use Perl 5 modules from CPAN from Rakudo Perl 6?
For example, how can I use the venerable Perl 5 module, CGI, which hasn't been ported yet, in Perl 6.
Update:
And what this funky code from some early Perl 6 module:
use CGI:from<perl5>;
Is the :from<perl5>
directive used to evoke some kind of a Perl 5 compatibility layer? Can't seem to find any documentation about it.
Since backward compatibility is a common goal when enhancing software, the breaking changes in Perl 6 had to be stated explicitly. The distinction between Perl 5 and Perl 6 became so large that eventually Perl 6 was renamed Raku.
The perl1 compiler (yes, there is a compiler although it's interpreted language) loads files, compiles them, then switches to run time to run the compiled code. When it encounters a new file to load, it switches back to compile time, compiles the new code, and so on. To load a module at compile time, you use it.
The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors.
Use Inline::Perl5.
The following example shows how to use the CPAN hosted Perl 5 module Text::Unidecode
("the Unicode transliteration of last resort") in Raku.
First, install Inline::Perl5 if you don't already have it installed:
zef install Inline::Perl5
Now install the CPAN module if you don't already have it installed:
perl -MCPAN -e "install Text::Unidecode"
You can now use the installed Perl module by writing a use
statement with an appended :from<Perl5>
(with an uppercase P
, not :from<perl5>
) :
use Text::Unidecode:from<Perl5>;
say Text::Unidecode::unidecode 'Solidarność';
displays:
Solidarnosc
See also other SO posts about Inline::Perl5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With