niner / Inline-Perl5

Use Perl 5 code in a Raku program
Artistic License 2.0
95 stars 30 forks source link

cannot access stringified Tree::DAG_Node #162

Closed stuart-little closed 3 years ago

stuart-little commented 3 years ago

I'm playing with Perl's Tree::DAG_Node. In Perl:

#!/usr/bin/env perl
use warnings;
use v5.12;
use Tree::DAG_Node;
use Data::Dump qw(dump);

my $root=Tree::DAG_Node->new({ name => 'boo' });
say @{$root->tree2string({ no_attributes => 1 })};
dump $root->tree2string({ no_attributes => 1 });

gives

boo
["boo"]

In Raku:

#!/usr/bin/env perl6
use v6;
use Tree::DAG_Node:from<Perl5>;

my $root=Tree::DAG_Node.new({ name => 'boo' });
say $root.tree2string({ no_attributes => 1 }).raku;

gives

Use of uninitialized value in concatenation (.) or string at $PREFIX/lib/perl5/site_perl/5.32.1/Tree/DAG_Node.pm line 1005.
[""]
niner commented 3 years ago

Technically this is not a bug in Inline::Perl5. You'd need to itemize that hash before passing it to Tree::DAG_Node's constructor to avoid it from getting flattened.

However since this is such a common issue and the itemization makes code more complicated and downright ugly than necessary, I dug into this and finally found out how to avoid that. With Inline::Perl5 v0.53 arguments are no longer flattened by default, so the above example works unmodified.

tbrowder commented 3 years ago

Yaaay! Thanks from another of your fans.