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.
Inline::Perl5
Get it from http://modules.perl6.org/
panda install Inline::Perl5
Following example shows how to import and call Perl 5 module Text::Unidecode
, "the Unicode transliteration of last resort" from Perl 6.
Install the module if you don't have it
perl -MCPAN -e "install Text::Unidecode"
Now the code
use Inline::Perl5;
use Text::Unidecode:from<Perl5>;
my $result = Text::Unidecode::unidecode('Solidarność');
say($result);
Alternatively, the more flexible way is to import the Inline::Perl5 yourself, create a new context and evaluate the function call in that context
use Inline::Perl5;
my $p5 = Inline::Perl5.new;
$p5.use('Text::Unidecode');
my $result = $p5.call('Text::Unidecode::unidecode', 'Solidarność');
say($result);
Either way, this prints
./perl6-m ~/perl/usefrom5.pl
Solidarnosc
Longer overview is available in the Readme on Github
Historic perspective
Previously, there have been two other interoperability projects. Use v5 and project blizkost. V5 still works, somewhat. Blizkost is completely irrelevant now.
Use v5
panda install v5
As of late 2014, v5 does not compile under Rakudo JVM. It does compile under Rakudo on MoarVM (It also does not compile under Rakudo on ParrotVM).
blizkost
Several years old effort to bring Perl 5 on ParotVM and use the VM to provide interoperability. Since this is a VM specific solution, it has been abandoned in favour of Inline::Perl5.
There is blizkost project that aims to use of perl5 code from Rakudo/Parrot. However it is AFAIK in quite early stage of development and probably not usable for real code.
来源:https://stackoverflow.com/questions/9173043/how-can-i-use-perl-5-modules-from-perl-6