7

I've been trying to load in the Perl5 module Data::Printer into Perl6, but am having a hard time.

I asked this earlier, Cannot import Perl5 module using Inline::Perl5 into Perl6 and did get useful advice from @raiph and Elizabeth, but was advised to do another question

con@con-VirtualBox:~$ perldoc -lm Data::Printer
/usr/local/share/perl/5.26.0/Data/Printer.pm
con@con-VirtualBox:~$ perl6
To exit type 'exit' or '^D'
> use Inline::Perl5;
Nil
> use lib:from<Perl5> '/usr/local/share/perl/5.26.0/Data/';
Nil
> my @a = 1,2,3,4
[1 2 3 4]
> p @a
===SORRY!=== Error while compiling:
Undeclared routine:
    p used at line 1

The p routine should be loaded, and yet it isn't.

alternatively, I try to load, but this produces a bug as well

> use Data::Printer:from<Perl5>
Unsupported type NativeCall::Types::Pointer<94859011731840> 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 sub EXPORT at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 805
  in any statement_control at /usr/lib/nqp/lib/Perl6/Grammar.moarvm line 1

I have no idea how I can usefully load this library into a Perl6 script.

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
con
  • 5,767
  • 8
  • 33
  • 62
  • 1
    Shouldn't you just use `use Data::Printer:from`? You should not have to set the include path with `use lib:from '/usr/local/share/perl/5.26.0/Data/'`, and you are missing the `use Data::Printer:from` statement, see [the GitHub page for Inline::Perl5](https://github.com/niner/Inline-Perl5) for examples. – Håkon Hægland Feb 05 '19 at 21:36
  • @HåkonHægland I've edited the question to show the error that that gives – con Feb 05 '19 at 21:38
  • This seem like the same problem as in you previous question, [see the answer by Elizabeth](https://stackoverflow.com/a/54487421/2173773) – Håkon Hægland Feb 05 '19 at 21:43
  • @HåkonHægland the solution on there isn't acceptable. Elizabeth may be correct that this a bug deep within either the language or the module, but another user suggested that there may be a better fix – con Feb 05 '19 at 21:51
  • 2
    Hi again @con. Håkon has now added a very simple 4 line recipe to refresh your IP5. If you already have `git` installed you will likely find that you can just type those 4 lines and when they've done their thing you'll be all set. If you *don't* have `git` installed then you'd need to do that first. Please let us know if you decide to try. If you do, then in principle (modulo bugs like the one you found) you should be able install P5 modules and then write the `use ... :from` line and then write P6 code to use the P5 functions. So this could be a big improvement in P6's utility for you. – raiph Feb 06 '19 at 10:26

1 Answers1

7

Unsupported type NativeCall::Types::Pointer<94859011731840> in p5_to_p6

This was a bug in Inline::Perl that was fixed 4 days ago.

You will not get this lastest version if you simply do zef install Inline::Perl5. Here is what I did:

# Install a position independent version of perl, 
#   see  https://github.com/niner/Inline-Perl5/
$ perlbrew install perl-5.29.7 --as perl-5.29.7-PIC -Duseshrplib -Dusemultiplicity
$ perlbrew install-cpanm
$ perlbrew use perl-5.29.7-PIC
$ cpanm Data::Printer
$ git clone https://github.com/niner/Inline-Perl5.git
$ cd Inline-Perl5/
# Run: 'zef uninstall Inline::Perl5' first if you already have it installed
$ perl6 configure.pl6
$ make
$ make install # this installs the latest version of Inline::Perl5
$ cd ..

Then I tested this with this script (p.p6):

use Data::Printer:from<Perl5>;
my @a = 1,2,3,4;
p @a;

Running perl6 p.p6 gives now:

[
    [0] 1,
    [1] 2,
    [2] 3,
    [3] 4
]

Edit: If you already have installed a position independent perl binary, the above installation procedure can be simplified:

$ git clone https://github.com/niner/Inline-Perl5.git
$ cd Inline-Perl5/
$ zef uninstall Inline::Perl5
$ zef install . # or alternatively create the `Makefile` as above 
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • 1
    Thanks for the comments @raiph! I think you are right there are simpler ways to do this. I thought it might be helpful to include instructions on using `perlbrew` to install a position independent `perl`, but maybe that is confusing. I included the simpler approach if you already have the position independent `perl` in my answer. – Håkon Hægland Feb 06 '19 at 05:48
  • 2
    this is amazing work @HåkonHægland the only minus is that the color doesn't come through, but that is very minor. Much appreciation and thanks! – con Feb 06 '19 at 16:32
  • 1
    Hi @raiph. Yes you are right, color does not work in P6. I have [posted an SO question](https://stackoverflow.com/q/54601397/2173773). Thanks for looking into this! – Håkon Hægland Feb 08 '19 at 23:02