How can I use Perl 5 modules from Perl 6?

两盒软妹~` 提交于 2019-12-03 10:39:12
user7610

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!