LoginSignup
0
0

More than 5 years have passed since last update.

How to plant a Christmas tree ?

Last updated at Posted at 2016-12-23

こんにちは、Perl 6 Advent Calendar 2016の24日目の投稿になります。
今回は、Inline::Perl5でPerl 5のAcme::POE::Treeを呼び出してクリスマスツリーを植えたいと思います。

イントロダクション

  • 下記プログラムを動かしてみましょう
poetree.p6
use Acme::POE::Tree:from<Perl5>;

my $tree = Acme::POE::Tree.new(
    star_delay => 11.5,
    light_delay => 2,
    run_for => 10
);

$tree.run;
  • 実行してみましょう
木が生えない?
$ perl6 poetree.p6
Can't use string ("run_for") as a HASH ref while "strict refs" in use at /home/itoyota/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/Acme/POE/Tree.pm line 19.
  • うまく実行できませんね。ではどうしたらよいでしょうか

クリスマスツリーの植え方

  • ${}でハッシュをitem context(※)にしたものを渡すようにしましょう
  • プログラムを下記のように書き直してみましょう

(※itemについてより詳しく知りたい方はこちらを参照してください:https://docs.perl6.org/type/Any#sub_item)

poetree.p6
use Acme::POE::Tree:from<Perl5>;

my $tree = Acme::POE::Tree.new(
    ${
        star_delay => 11.5,
        light_delay => 2,
        run_for => 10
    }
);

$tree.run;

🎄

  • では、実行してみましょう。

tty.gif

以上、Perl 6 Advent Calendar 2016の24日目の投稿でした。

P.S.
実は、この解決策を教えてくれたのはInline::Perl5の開発者の方です。
https://github.com/niner/Inline-Perl5/issues/85

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0