-->

Cannot import Perl5 module using Inline::Perl5 int

2019-02-22 02:25发布

问题:

I'm trying to import a Perl5 module I really like https://metacpan.org/pod/Data::Printer using advice from the manual page https://modules.perl6.org/dist/Inline::Perl5:cpan:NINE

using a very simple script

use Inline::Perl5;
my $p5 = Inline::Perl5.new;
$p5.use('Data::Printer');

but then I get this error:

Unsupported type NativeCall::Types::Pointer<94774650480224> in p5_to_p6
  in method p5_to_p6_type at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 298
  in method unpack_return_values at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 375
  in method invoke at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 446
  in method import at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 776
  in method use at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 898
  in block <unit> at inline_perl5.p6 line 4

what is going wrong here? How can I import this perl5 module into perl6? I would also be happy if there is a similar way to get the colored/tabbed output in Perl6 like I would get from Data::Printer because I can't find it.

EDIT: This is solved here: how to load Perl5's Data::Printer in Perl6?

回答1:

I think you stumbled on a bug in Inline::Perl5 that seems to happen for the Data::Printer Perl 5 module, so I would suggest you open an issue for it at https://github.com/niner/Inline-Perl5/issues .

Meanwhile, the syntax has become much simpler. Once you have Inline::Perl5 installed, you only need to add the :from<Perl5> adverb to load a module from Perl 5:

use Data::Printer:from<Perl5>;

Unfortunately, at this moment that creates the same error that you already described:

===SORRY!===
Unsupported type NativeCall::Types::Pointer<140393737675456> in p5_to_p6

So I don't think there is a solution this that wouldn't require an upgrade of either Inline::Perl5 or Rakudo Perl 6.



回答2:

From the github page, https://github.com/niner/Inline-Perl5/issues/128

> perl6 -Ilib -e 'use Data::Printer:from<Perl5>; my @a = 1, 2, [3, 4, ${a => 1}]; p @a'
[
    [0] 1,
    [1] 2,
    [2] [
        [0] 3,
        [1] 4,
        [2] {
            a   1
        } (tied to Perl6::Hash)
    ]
]

I'm not particularly happy with this though. This is much more complicated than perl5 would have been. One of the main points of using Perl6 over Perl5 is simpler use and syntax. This isn't it. The 'Inline::Perl5' module should be able to be loaded within the script like every other module, not as an option at the command line.



标签: perl6