6

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?

con
  • 5,767
  • 8
  • 33
  • 62

2 Answers2

7

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.

Elizabeth Mattijsen
  • 25,654
  • 3
  • 75
  • 105
  • 3
    I've added the issue onto GitHub, thanks for letting me know. If anyone ever solves it there, I'll re-post a solution if it is given – con Feb 01 '19 at 21:41
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.

con
  • 5,767
  • 8
  • 33
  • 62
  • 3
    That line was just niner's way to quickly demonstrate the fix. He won't have realized you're a P6 newbie. You can just write it in script form instead: `use lib 'lib'; use Data::Printer:from; ...` where `lib` is the directory in which your P5 libs are installed. – raiph Feb 02 '19 at 17:11
  • 2
    And thank you for trying this out, asking your SO questions, and posting an issue on the IP5 repo. By patiently participating at this level you just made a significant contribution to P6. :) Also, now you know you can use many P5 modules as is in P6 and if they don't work you can contribute to P6's improvement by posting an issue and in some cases there'll be a fix a few days or weeks later and sometimes within a day. :) – raiph Feb 02 '19 at 17:18
  • 1
    And the icing on the cake is that there are [other similar language adaptors](https://modules.perl6.org/search/?q=inline) (though they're currently less polished than the IP5 adaptor) for other languages. So if you can't get what you want in the form of a P6 module you can look for a P5 module and if that doesn't do the trick you can use many Python modules, Ruby gems, C libraries, ... P6 is a superglue. :) – raiph Feb 02 '19 at 17:22
  • 1
    Er, `use lib 'lib';` is for P6 modules. That should have been `use lib:from 'lib';` if you want to load P5 modules from the 'lib' directory instead of (or as well as? I can't test this atm) the directory IP5 loads P5 modules from by default. – raiph Feb 02 '19 at 18:06
  • @raiph `use lib:from '/usr/local/share/perl/5.26.0/Data/'` says `Nil` but it fails to get the necessary `p` routine from Data::Printer :( it says `Undeclared routine` – con Feb 05 '19 at 16:23
  • @raiph It may be easier to just translate the `Printer.pm` module than to load it with `Inline::Perl5` I'm really disappointed with it :( – con Feb 05 '19 at 16:30
  • I'm sorry to hear it's being a pain. I can't diagnose the problem you are having from your comment "`use lib:from '/usr/local/share/perl/5.26.0/Data/'` says `Nil` but it fails to get the necessary `p` routine from Data::Printer" because the comment is either lacking detail or, if it includes all the detail, then you're not using these features correctly. I realize this is a drag but please consider posting yet another SO that shows exactly what code you have in a script that's giving you the `Undeclared routine` error. It will be appreciated. If you prefer to give up, I will understand. – raiph Feb 05 '19 at 16:42
  • 1
    @raiph https://stackoverflow.com/questions/54543088/how-to-load-perl5s-dataprinter-in-perl6 – con Feb 05 '19 at 21:11